def test_set_permission(filesystem: FileSystemImpl, lpaths: Dict[str, AbstractPath]) -> None: if filesystem._supports('permissions'): for permission in Permission: filesystem._set_permission(lpaths['root'], permission, False) for permission in Permission: assert not filesystem._has_permission(lpaths['root'], permission) for permission in Permission: filesystem._set_permission(lpaths['root'], permission, True) for p2 in Permission: is_same = (permission == p2) assert filesystem._has_permission(lpaths['root'], p2) == is_same filesystem._set_permission(lpaths['root'], permission, False) filesystem._chmod(lpaths['root'], 0o0755)
def test_chmod(filesystem: FileSystemImpl, lpaths: Dict[str, AbstractPath]) -> None: if filesystem._supports('permissions'): filesystem._chmod(lpaths['root'], 0o0000) for permission in Permission: assert not filesystem._has_permission(lpaths['root'], permission) filesystem._chmod(lpaths['root'], 0o0755) granted_permissions = [ Permission.OWNER_READ, Permission.OWNER_WRITE, Permission.OWNER_EXECUTE, Permission.GROUP_READ, Permission.GROUP_EXECUTE, Permission.OTHERS_READ, Permission.OTHERS_EXECUTE ] for permission in Permission: if permission in granted_permissions: assert filesystem._has_permission(lpaths['root'], permission) else: assert not filesystem._has_permission(lpaths['root'], permission)
def test_has_permission(filesystem: FileSystemImpl, lpaths: Dict[str, AbstractPath]) -> None: if filesystem._supports('permissions'): assert filesystem._has_permission(lpaths['root'], Permission.OWNER_READ) assert filesystem._has_permission(lpaths['root'], Permission.OWNER_WRITE) assert filesystem._has_permission(lpaths['root'], Permission.OWNER_EXECUTE) assert filesystem._has_permission(lpaths['root'], Permission.GROUP_READ) assert not filesystem._has_permission(lpaths['root'], Permission.GROUP_WRITE) assert filesystem._has_permission(lpaths['root'], Permission.GROUP_EXECUTE) assert filesystem._has_permission(lpaths['root'], Permission.OTHERS_READ) assert not filesystem._has_permission(lpaths['root'], Permission.OTHERS_WRITE) assert filesystem._has_permission(lpaths['root'], Permission.OTHERS_EXECUTE) assert not filesystem._has_permission(lpaths['file'], Permission.OTHERS_WRITE)
def test_mkdir(filesystem: FileSystemImpl, lpaths: Dict[str, AbstractPath]) -> None: filesystem._mkdir(lpaths['new_dir']) assert filesystem._is_dir(lpaths['new_dir']) filesystem._rmdir(lpaths['new_dir']) filesystem._mkdir(lpaths['deep_new_dir'], parents=True) assert filesystem._is_dir(lpaths['deep_new_dir'].parent) assert filesystem._is_dir(lpaths['deep_new_dir']) filesystem._rmdir(lpaths['deep_new_dir']) filesystem._rmdir(lpaths['deep_new_dir'].parent) try: old_umask = os.umask(0o022) filesystem._mkdir(lpaths['deep_new_dir'], mode=0o660, parents=True) assert filesystem._is_dir(lpaths['deep_new_dir'].parent) assert filesystem._has_permission(lpaths['deep_new_dir'].parent, Permission.OTHERS_READ) assert not filesystem._has_permission(lpaths['deep_new_dir'].parent, Permission.GROUP_WRITE) assert not filesystem._has_permission(lpaths['deep_new_dir'].parent, Permission.OTHERS_WRITE) assert filesystem._is_dir(lpaths['deep_new_dir']) assert not filesystem._has_permission(lpaths['deep_new_dir'], Permission.OTHERS_READ) assert not filesystem._has_permission(lpaths['deep_new_dir'], Permission.GROUP_EXECUTE) assert not filesystem._has_permission(lpaths['deep_new_dir'], Permission.OWNER_EXECUTE) assert filesystem._has_permission(lpaths['deep_new_dir'], Permission.OWNER_WRITE) filesystem._rmdir(lpaths['deep_new_dir']) filesystem._rmdir(lpaths['deep_new_dir'].parent) except UnsupportedOperationError: pass finally: os.umask(old_umask) filesystem._mkdir(lpaths['deep_new_dir'], parents=True) with pytest.raises(FileExistsError): filesystem._mkdir(lpaths['deep_new_dir']) filesystem._mkdir(lpaths['deep_new_dir'], exists_ok=True) filesystem._rmdir(lpaths['deep_new_dir']) filesystem._rmdir(lpaths['deep_new_dir'].parent)