def test_pathmanager_bad_dir(): pm = paths.PathManager(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.construct('sub1', 'sub2') == 'C:\\directory\\test\\sub1\\sub2'
def test_pathmanager_good_dir(): dir_path = os.path.dirname(__file__) dir_name = os.path.basename(dir_path) pm = paths.PathManager(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.construct('sub1', 'sub2') == os.path.join(dir_path, 'sub1', 'sub2')
def test_pathmanager_good_file(): file_name = os.path.basename(__file__) dir_path = os.path.dirname(__file__) pm = paths.PathManager(__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.construct('sub1', 'sub2') == os.path.join(dir_path, 'sub1', 'sub2', file_name)
def test_pathmanager_bad_init(): with pytest.raises(TypeError): paths.PathManager(None) paths.PathManager('') with pytest.raises(ValueError): paths.PathManager(r'C:\directory\file.ext', r'C:\directory')