Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
author = Actor("An author", "author@example.com")
committer = Actor("A committer", "committer@example.com")
# First commit
with open(tmppath / ".gitignore", "w") as ignore:
ignore.write(".wily/")
index.add([".gitignore"])
commit1 = index.commit("commit1", author=author, committer=committer)
# Second commit
with open(tmppath / "test.py", "w") as file1:
file1.write("print(1)")
index.add(["test.py"])
commit2 = index.commit("commit2", author=author, committer=committer)
config = DEFAULT_CONFIG
config.path = tmpdir
archiver = GitArchiver(config)
assert archiver.config == config
revisions = archiver.revisions(tmpdir, 3)
assert len(revisions) == 2
assert revisions[0].message == "commit2"
assert revisions[0].author_email == "author@example.com"
assert revisions[0].author_name == "An author"
assert (
revisions[0].key in commit2.name_rev
and revisions[0].key not in commit1.name_rev
)
assert revisions[1].message == "commit1"
repo = Repo.init(path=tmpdir)
tmppath = pathlib.Path(tmpdir)
# Write a test file to the repo
with open(tmppath / ".gitignore", "w") as ignore:
ignore.write("*.py[co]\n")
index = repo.index
index.add([".gitignore"])
author = Actor("An author", "author@example.com")
committer = Actor("A committer", "committer@example.com")
index.commit("ignore python cache", author=author, committer=committer)
config = DEFAULT_CONFIG
config.path = tmpdir
with pytest.raises(WilyIgnoreGitRepositoryError):
archiver = GitArchiver(config)
def test_exists(tmpdir):
"""
Test that exists() returns true if path does exist
"""
config = DEFAULT_CONFIG
config.cache_path = tmpdir
assert cache.exists(config)
def config():
cfg = DEFAULT_CONFIG
return cfg
def test_git_revisions(repo, tmpdir):
with patch("wily.archivers.git.Repo", return_value=repo):
test_config = wily.config.DEFAULT_CONFIG
test_config.path = repo.path
archiver = git.GitArchiver(test_config)
revisions = archiver.revisions(tmpdir, 99)
assert archiver.repo is not None
assert archiver.config == test_config
assert revisions[0].key == "1234"
assert revisions[1].key == "1234"
assert revisions[0].author_name == "Mr Test"
def test_cyclomatic_error_case(harvester):
MockCC.results = {"test.py": {"error": "bad data"}}
op = wily.operators.cyclomatic.CyclomaticComplexityOperator(DEFAULT_CONFIG)
results = op.run("test.py", {})
assert results == {"test.py": {"detailed": {}, "total": {"complexity": 0}}}
def test_get_default_metrics_empty(tmpdir):
"""
Test that get_metrics goes ok with an empty index
"""
config = DEFAULT_CONFIG
tmppath = pathlib.Path(tmpdir) / ".wily"
config.cache_path = str(tmppath)
tmppath.mkdir()
(tmppath / "git").mkdir()
with open(tmppath / "git" / "index.json", "w+") as f:
f.write("[]")
metrics = cache.get_default_metrics(config)
assert metrics == []
def test_cyclomatic_bad_entry_data(harvester):
MockCC.results = {"test.py": [{"complexity": 5}]}
op = wily.operators.cyclomatic.CyclomaticComplexityOperator(DEFAULT_CONFIG)
results = op.run("test.py", {})
assert results == {"test.py": {"detailed": {}, "total": {"complexity": 0}}}
def config(builddir):
_cfg = wily.config.DEFAULT_CONFIG
_cfg.path = builddir
return _cfg