def test_directory_operators(): directory_1 = Directory.path(Path.parse('/path/to/dir_1')) directory_2 = Directory.path(Path.current()) assert directory_1 == directory_1 assert directory_1 != directory_2
def test_directory_is_defined(): directory = Directory.undefined() assert directory.is_defined() is False directory = Directory.path(Path.current()) assert directory.is_defined() is True
def test_path_is_defined (): path_1 = Path.undefined() path_2 = Path.current() assert path_1.is_defined() is False assert path_2.is_defined() is True
def test_path_is_relative (): path_1 = Path.current() path_2 = Path.parse('../path/to/file.txt') path_3 = Path.parse('./path/to/file.txt') assert path_1.is_relative() is False assert path_2.is_relative() is True assert path_3.is_relative() is True
def test_path_get_absolute_path (): current_path = Path.current() path_1 = Path.parse('/path/to/file.txt') path_2 = Path.parse('./path/to/file.txt') abs_path_1 = path_1.get_absolute_path() abs_path_2 = path_2.get_absolute_path() assert path_1.is_absolute() is True assert path_1 == abs_path_1 assert path_2.is_relative() is True assert abs_path_2 == current_path + path_2 assert abs_path_2.get_normalized_path() == current_path + path_1
def test_directory_exists(): directory = Directory.undefined() with pytest.raises(RuntimeError): directory.exists() is False directory = Directory.root() assert directory.exists() is True directory = Directory.path(Path.current()) assert directory.exists() is True directory = Directory.path(Path.parse('/path/to/false_dir_1')) assert directory.exists() is False
def test_directory_constructors(): directory = Directory.undefined() assert isinstance(directory, Directory) directory = Directory.path(Path.current()) assert isinstance(directory, Directory) assert os.getcwd() == directory.to_string() directory = Directory.path(Path.parse('/path/to/dir_1')) assert isinstance(directory, Directory) directory = Directory.root() assert isinstance(directory, Directory) assert directory.to_string() == '/' assert directory.to_string() == String('/')
def test_file_getter_functions (): current_file = File.path(Path.parse('./__init__.py')) shared_lib_file = File.path(Path.parse('./shared_library.so.3.3')) test_file = File.path(Path.current() + Path.parse('../assets/pythontestfile.txt')) # name file_name = current_file.get_name() so_file_name = shared_lib_file.get_name() assert isinstance(file_name, String) assert file_name == '__init__.py' assert so_file_name == 'shared_library.so.3.3' # extension file_extension = current_file.get_extension() so_file_extension = shared_lib_file.get_extension() assert isinstance(file_extension, String) assert isinstance(so_file_extension, String) assert file_extension == 'py' assert so_file_extension == '3' # [TBR] # path file_path = current_file.get_path() so_file_path = shared_lib_file.get_path() assert isinstance(file_path, Path) assert file_path == Path.parse('./__init__.py') assert so_file_path == Path.parse('./shared_library.so.3.3') # permissions file_permissions = current_file.get_permissions() assert isinstance(file_permissions, PermissionSet) with pytest.raises(RuntimeError): so_file_permissions = shared_lib_file.get_permissions() # directory file_directory = current_file.get_parent_directory() assert isinstance(file_directory, Directory) assert file_directory.to_string() == '/usr/local/lib/python3.8/site-packages/ostk/core'
def test_directory_get_directories(): true_directory = Directory.path(Path.current()) assert true_directory.exists() is True directories = true_directory.get_directories() assert isinstance(directories, list) if len(directories) > 0: assert isinstance(directories[0], Directory) false_directory = Directory.path(Path.parse('/path/to/false_dir_1')) assert false_directory.exists() is False with pytest.raises(RuntimeError): directories = false_directory.get_directories() root_directory = Directory.root() assert root_directory.exists() is True directories = root_directory.get_directories() assert len(directories) > 0 assert isinstance(directories[0], Directory)
def test_path_get_normalized_path (): current_path = Path.current() path_1 = Path.parse('/path/to/file.txt') path_2 = Path.parse('./path/to/file.txt') path_3 = Path.parse('/path/to/../to/./file.txt') path_4 = Path.parse('/path/../to/./file.txt') norm_path_1 = path_1.get_normalized_path() norm_path_2 = path_2.get_normalized_path() norm_path_3 = path_3.get_normalized_path() norm_path_4 = path_4.get_normalized_path() assert path_1.is_absolute() is True assert path_1 == norm_path_1 assert path_2.is_relative() is True assert norm_path_2 == current_path + path_1 assert norm_path_3 == Path.parse('/path/to/file.txt') assert norm_path_3.to_string() == '/path/to/file.txt' assert norm_path_4 == Path.parse('/to/file.txt') assert norm_path_4.to_string() == '/to/file.txt'
def test_path_current (): # create current path current_path = Path.current() assert isinstance(current_path, Path)