def test_create_from_pathname_with_file(): prefix = file.relative_to(__file__, 'test-resources/files/') collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/first')) assert len(collection.get_files()) == 1 assert prefix == collection.get_prefix() collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/first.xcf')) assert len(collection.get_files()) == 1 assert prefix == collection.get_prefix() collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/first.png')) assert len(collection.get_files()) == 0 assert '' == collection.get_prefix()
def test_replace_path_components_without_replacements(): collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/**')) files_before = collection.get_files() collection = collection.replace_path_components() files_after = collection.get_files() assert files_before == files_after
def test_ordering(): prefix = file.relative_to(__file__, 'test-resources/files/') collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/**')) collection = collection.replace_prefix(prefix) assert [ 'first.xcf', 'second.xcf', 'a/third.xcf', 'a/b/fourth.xcf', ] == collection.get_files()
def test_replace_path_components(): prefix = file.relative_to(__file__, 'test-resources/files/') suffix = '.xcf' collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/**')) collection = collection.replace_path_components(prefix, '#', suffix, '%') assert [ '#first%.xcf', '#second%.xcf', '#a/third%.xcf', '#a/b/fourth%.xcf', ] == collection.get_files()
def test_create_from_pathname_with_recursive_match(): prefix = file.relative_to(__file__, 'test-resources/files/') collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/**')) assert len(collection.get_files()) == 4 assert prefix == collection.get_prefix() collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/**/')) assert len(collection.get_files()) == 4 assert prefix == collection.get_prefix() collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/**/*')) assert len(collection.get_files()) == 4 assert prefix == collection.get_prefix() collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/**/*.xcf')) assert len(collection.get_files()) == 4 assert prefix == collection.get_prefix() collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/**/*.png')) assert len(collection.get_files()) == 0 assert '' == collection.get_prefix()
def test_replace_path_components_with_non_existing_component(): collection = GimpFileCollection.create_from_pathname(file.relative_to(__file__, 'test-resources/files/**')) with pytest.raises(NonExistingPathComponentException): collection.replace_path_components('wrong_prefix', '#')