def test_entry_types(filesystem: FileSystemImpl, lpaths: Dict[str, AbstractPath]) -> None: assert filesystem._is_dir(lpaths['root']) assert not filesystem._is_dir(lpaths['file']) assert not filesystem._is_dir(lpaths['new_dir']) assert filesystem._is_file(lpaths['file']) assert not filesystem._is_file(lpaths['root']) assert not filesystem._is_file(lpaths['new_file']) assert (filesystem._is_symlink(lpaths['link']) or not filesystem._supports('symlinks')) assert filesystem._is_file(lpaths['link']) assert not filesystem._is_dir(lpaths['link']) assert not filesystem._is_symlink(lpaths['new_file']) assert (filesystem._is_symlink(lpaths['broken_link']) or not filesystem._supports('symlinks')) assert not filesystem._is_file(lpaths['broken_link']) assert filesystem._entry_type(lpaths['root']) == EntryType.DIRECTORY assert filesystem._entry_type(lpaths['file']) == EntryType.FILE if filesystem._supports('symlinks'): assert filesystem._entry_type( lpaths['link']) == EntryType.SYMBOLIC_LINK # disable for now, doesn't work in a docker #assert filesystem._entry_type(lpaths['chardev']) == EntryType.CHARACTER_DEVICE assert filesystem._entry_type( lpaths['blockdev']) == EntryType.BLOCK_DEVICE assert filesystem._entry_type(lpaths['fifo']) == EntryType.FIFO # TODO: socket? with pytest.raises(FileNotFoundError): filesystem._entry_type(lpaths['new_file'])
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)