adding FilePerms tests

This commit is contained in:
Mahmoud Hashemi 2015-05-17 20:07:59 -07:00
parent 7c0b237741
commit d3a6c9743f
2 changed files with 22 additions and 15 deletions

View File

@ -408,22 +408,8 @@ copytree = copy_tree # alias for drop-in replacement of shutil
if __name__ == '__main__': if __name__ == '__main__':
pass
#with atomic_save('/tmp/final.txt') as f: #with atomic_save('/tmp/final.txt') as f:
# f.write('rofl') # f.write('rofl')
# raise ValueError('nope') # raise ValueError('nope')
# f.write('\n') # f.write('\n')
def _main():
up = FilePerms()
up.other = ''
up.user = 'xrw'
up.group = 'rrrwx'
try:
up.other = 'nope'
except ValueError:
pass
print(up)
print('user:', up.user)
print(oct(int(up)))
print(oct(int(FilePerms())))
_main()

21
tests/test_fileutils.py Normal file
View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from boltons.fileutils import FilePerms
def test_fileperms():
up = FilePerms()
up.other = ''
up.user = 'xrw'
up.group = 'rrrwx'
try:
up.other = 'nope'
except ValueError:
# correctly raised ValueError on invalid chars
pass
assert repr(up) == "FilePerms(user='rwx', group='rwx', other='')"
assert up.user == 'rwx'
assert oct(int(up)).endswith('770') # 0770 on py2 and 0o770 on py3
assert int(FilePerms()) == 0