一个脚本用于在团队之间交换文件信息.它用作:
$ share.py -p /path/to/file.txt
Run Code Online (Sandbox Code Playgroud)
参数检查确保/path/to/file.txt存在并具有正确的权限:
#[...]
# ensure that file exists and is readable
if not os.access(options.path, os.F_OK):
raise MyError('the file does not exist')
# ensure that path is absolute
if not os.path.isabs(options.path):
raise MyError('I need absolute path')
# ensure that file has read permissions for others
info = os.stat(options.path)
last_bit = oct(info.st_mode)[-1]
if not last_bit in ['4', '5', '6', '7']:
raise MyError('others cannot read the file: change permission')
Run Code Online (Sandbox Code Playgroud)
问题是一个用户发送了:
$ share.py -p/path/to /
并且程序没有像它应该的那样失败.在回顾展中我应该看到这一点,但我没有.
如何添加测试以确保路径是常规文件,可能有也可能没有扩展名(我不能简单地处理名称字符串)?
| 归档时间: |
|
| 查看次数: |
345 次 |
| 最近记录: |