def test_convert_rename_str(tmpdir): source_dir = DATA_DIR / 'example1' target_dir = Path(tmpdir) convert_files(source_dir, tmpdir, shutil.copy, pattern='**/*.dat', rename=lambda p: p.with_suffix('.foo').name) assert set(iter_files(tmpdir, pattern='**/*.foo')) == { target_dir / 'aa' / 'colors.foo', }
def test_convert_files_directory_error(): source_dir = DATA_DIR / 'example1' target_dir = source_dir / 'aa' function = Mock(return_value=None) with pytest.raises( InvalidDirectoryError, match=r'Source must not be a parent of Target \(and vice versa\)'): convert_files(source_dir, target_dir, function) with pytest.raises( InvalidDirectoryError, match=r'Source must not be a parent of Target \(and vice versa\)'): convert_files(target_dir, source_dir, function)
def test_convert_files_txt_only(tmpdir): source_dir = DATA_DIR / 'example1' target_dir = Path(tmpdir) convert_files(source_dir, tmpdir, shutil.copy, pattern='**/*.txt') assert set(iter_files(tmpdir)) == { target_dir / 'shapes.txt', target_dir / 'aa' / 'numbers.txt', target_dir / 'aa' / 'pets.txt', target_dir / 'bb' / 'names.txt', target_dir / 'bb' / 'cc' / 'cars.txt', } assert not (target_dir / 'aa' / 'colors.dat').exists() assert set(iter_texts(tmpdir)) == { 'Square Circle\nHexagon\n', 'One Two\nThree\n', 'Cat Dog\nParrot\n', 'Alice Bob\nCarol\n', 'Toyota Honda\nFord\n', }
def test_convert_files(tmpdir): source_dir = DATA_DIR / 'example1' target_dir = Path(tmpdir) convert_files(source_dir, tmpdir, shutil.copy) assert set(iter_files(tmpdir)) == { target_dir / 'shapes.txt', target_dir / 'aa' / 'colors.dat', # including this target_dir / 'aa' / 'numbers.txt', target_dir / 'aa' / 'pets.txt', target_dir / 'bb' / 'names.txt', target_dir / 'bb' / 'cc' / 'cars.txt', } assert set(iter_texts(tmpdir)) == { 'Square Circle\nHexagon\n', 'Red Green\nBlue\n', # including this 'One Two\nThree\n', 'Cat Dog\nParrot\n', 'Alice Bob\nCarol\n', 'Toyota Honda\nFord\n', }