def test_changed_module(self, fs): # pylint: disable=invalid-name fs.create_file("old/module.py") fs.create_file("new/module.py") pathlib.Path("new/module.py").write_text("class Klass:\n pass") change = pd.pyff_directory(pathlib.Path("old"), pathlib.Path("new")) assert change assert pathlib.Path("module.py") in change.modules.changed
def test_changed_package(self, fs): # pylint: disable=invalid-name fs.create_dir("old/pkg/__init__.py") fs.create_file("new/pkg/__init__.py") fs.create_file("new/pkg/module.py") change = pd.pyff_directory(pathlib.Path("old"), pathlib.Path("new")) assert change assert pathlib.Path("pkg") in change.packages.changed
def test_invalid(self, fs): # pylint: disable=invalid-name fs.create_file("old") fs.create_file("dir/pkg/__init__.py") with pytest.raises(ValueError): pd.pyff_directory(pathlib.Path("old"), pathlib.Path("dir")) with pytest.raises(ValueError): pd.pyff_directory(pathlib.Path("dir"), pathlib.Path("old")) with pytest.raises(ValueError): pd.pyff_directory(pathlib.Path("dir"), pathlib.Path("nonexistent"))
def pyff_git_revision(repository: str, old: str, new: str) -> Optional[RevisionsPyfference]: """Compare two revisions in a Git repository""" with tempfile.TemporaryDirectory() as temporary_wd: working_directory = pathlib.Path(temporary_wd) source_dir = working_directory / "source" old_dir = working_directory / "old" new_dir = working_directory / "new" repo = git.Repo.clone_from(repository, source_dir) repo.git.checkout(old) shutil.copytree(source_dir, old_dir) repo.git.checkout(new) shutil.copytree(source_dir, new_dir) change = pd.pyff_directory(old_dir, new_dir) if change: return RevisionsPyfference(change) return None
def compare(old, new, _): """Compare two directories""" return pyff_directory(old, new)
def test_identical(self, fs): # pylint: disable=invalid-name fs.create_file("old/package/__init__.py") fs.create_file("new/package/__init__.py") assert pd.pyff_directory(pathlib.Path("old"), pathlib.Path("new")) is None
def test_new_module(self, fs): # pylint: disable=invalid-name fs.create_dir("old") fs.create_file("new/module.py") change = pd.pyff_directory(pathlib.Path("old"), pathlib.Path("new")) assert change assert pathlib.Path("module.py") in change.modules.new