def test_path_get_last_element ():

    path_1 = Path.parse('./path/to/file.txt')
    path_2 = Path.parse('/path/to/dir_1')

    assert path_1.get_last_element() == 'file.txt'
    assert path_2.get_last_element() == 'dir_1'
def test_file_exists ():

    current_file = File.path(Path.parse('./__init__.py'))
    false_file = File.path(Path.parse('./false_file.py'))

    assert current_file.exists() is True
    assert false_file.exists() is False
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def test_directory_get_parent_directory():

    directory = Directory.path(Path.parse('/path/to/false_dir_1'))
    parent_dir = directory.get_parent_directory()

    assert isinstance(parent_dir, Directory)
    assert parent_dir.get_name() == 'to'
    assert parent_dir.get_path() == Path.parse('/path/to')
    assert parent_dir.exists() is False
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
Exemplo n.º 7
0
def test_directory_getter_functions():

    directory = Directory.path(Path.parse('/path/to/dir_1'))
    dir_name = directory.get_name()
    dir_path = directory.get_path()

    assert dir_name == 'dir_1'
    assert isinstance(dir_name, String)
    assert dir_path == Path.parse('/path/to/dir_1')
    assert isinstance(dir_path, Path)
def test_path_parse ():

    # create path from String parsing
    path_1 = Path.parse("/path/to/file.txt")
    path_2 = Path.parse('/path/to/file.txt')
    path_3 = Path.parse(String('/path/to/file.txt'))

    assert isinstance(path_1, Path)
    assert isinstance(path_2, Path)
    assert isinstance(path_3, Path)
def test_path_to_string ():

    path_1 = Path.undefined()
    with pytest.raises(RuntimeError):

        path_1.to_string()

    path_2 = Path.parse('/path/to/file.txt')
    path_2_string = path_2.to_string()
    assert isinstance(path_2_string, String)
    assert path_2_string == String('/path/to/file.txt')
    assert path_2_string == '/path/to/file.txt'
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_path_operators ():

    path_1 = Path.parse("/path/to/dir_1")
    path_2 = Path.parse("/dir_1/to/file.txt")
    path_3 = path_1 + path_2

    assert path_1 == path_1
    assert path_2 != path_1

    path_1 += path_2

    assert isinstance(path_1, Path)
    assert isinstance(path_2, Path)
    assert isinstance(path_3, Path)
Exemplo n.º 12
0
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_operators ():

    undefined_file = File.undefined()
    current_file = File.path(Path.parse('./test_file.py'))

    assert current_file == current_file
    assert current_file != undefined_file
def test_file_is_defined ():

    undefined_file = File.undefined()
    current_file = File.path(Path.parse('./test_file.py'))

    assert undefined_file.is_defined() is False
    assert current_file.is_defined() is True
def test_file_constructors ():

    undefined_file = File.undefined()
    current_file = File.path(Path.parse('./test_file.py'))

    assert isinstance(undefined_file, File)
    assert isinstance(current_file, File)
Exemplo n.º 16
0
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
Exemplo n.º 17
0
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
Exemplo n.º 18
0
def test_directory_to_string():

    directory = Directory.path(Path.parse('/path/to/dir_1'))
    dir_string = directory.to_string()

    assert dir_string == String('/path/to/dir_1')
    assert dir_string == '/path/to/dir_1'
    assert isinstance(dir_string, String)
Exemplo n.º 19
0
def test_directory_is_empty():

    root_directory = Directory.root()
    assert root_directory.is_empty() is False

    false_directory = Directory.path(Path.parse('/path/to/false_dir_1'))
    assert false_directory.exists() is False

    with pytest.raises(RuntimeError):
        false_directory.is_empty()
Exemplo n.º 20
0
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_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_path_undefined ():

    # create undefined path
    undefined_path = Path.undefined()
    assert isinstance(undefined_path, Path)
def test_path_current ():

    # create current path
    current_path = Path.current()
    assert isinstance(current_path, Path)
def test_path_root ():

    # create root path
    root_path = Path.root()
    assert isinstance(root_path, Path)
def test_path_get_parent_path ():

    path = Path.parse('./path/to/file.txt')
    parent_path = path.get_parent_path()

    assert parent_path.to_string() == './path/to'