Beispiel #1
0
def test_path_bad_dir():
    pm = paths.Path(r'C:\directory\test')
    assert not pm.is_file
    assert not pm.is_dir
    assert not pm.exists
    assert pm.extension() == ''
    assert pm.extension(False) == ''
    assert pm.basename() == 'test'
    assert pm.basename(False) == 'test'
    assert pm.make_path('sub1', 'sub2') == 'C:\\directory\\test\\sub1\\sub2'
Beispiel #2
0
def test_path_good_dir():
    dir_path = os.path.dirname(__file__)
    dir_name = os.path.basename(dir_path)
    pm = paths.Path(dir_path)
    assert not pm.is_file
    assert pm.is_dir
    assert pm.exists
    assert pm.extension() == ''
    assert pm.extension(False) == ''
    assert pm.basename() == dir_name
    assert pm.basename(False) == dir_name
    assert pm.make_path('sub1',
                        'sub2') == os.path.join(dir_path, 'sub1', 'sub2')
Beispiel #3
0
def test_path_good_file():
    file_name = os.path.basename(__file__)
    dir_path = os.path.dirname(__file__)
    pm = paths.Path(__file__)
    assert pm.is_file
    assert not pm.is_dir
    assert pm.exists
    assert pm.extension() == '.py'
    assert pm.extension(False) == 'py'
    assert pm.basename() == file_name
    assert pm.basename(False) == file_name.split('.')[0]
    assert pm.make_path('sub1',
                        'sub2') == os.path.join(dir_path, 'sub1', 'sub2',
                                                file_name)
Beispiel #4
0
def test_path_bad_init():
    with pytest.raises(TypeError):
        paths.Path(None)
        paths.Path('')
    with pytest.raises(ValueError):
        paths.Path(r'C:\directory\file.ext', r'C:\directory')