Skip to content

Commit

Permalink
Merge pull request #21 from effigies/test/coverage
Browse files Browse the repository at this point in the history
TEST: Test util/git.py
  • Loading branch information
effigies authored Jul 2, 2019
2 parents c6d59ce + 6ffe441 commit 8ef5b7c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ before_script:
- travis_retry python -m pip install pytest-cov coverage codecov

script:
- py.test -vs --cov niflow_manager --cov-report xml:cov.xml --doctest-modules niflow_manager
- py.test -v -s --cov niflow_manager --cov-report xml:cov.xml --doctest-modules niflow_manager

after_script:
- codecov --file cov.xml --flags unittests -e TRAVIS_JOB_NUMBER
Empty file.
32 changes: 32 additions & 0 deletions niflow_manager/util/tests/test_git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest
import subprocess as sp
from configparser import ConfigParser
from ..git import git_variables

GIT_AUTHOR = "Test Author"
GIT_EMAIL = "unreal3214@fake2182.tld"


# Test one, two, and missing queries
@pytest.mark.parametrize("variables, expected, exception",
[([("user", "name", GIT_AUTHOR)], {'user.name': GIT_AUTHOR}, None),
([("user", "name", GIT_AUTHOR), ("user", "email", GIT_EMAIL)],
{'user.name': GIT_AUTHOR, "user.email": GIT_EMAIL}, None),
([("user", "name", GIT_AUTHOR), ("user", "email", GIT_EMAIL)],
{'user.name': GIT_AUTHOR, "user.fake": "EXCEPTION"}, KeyError),
])
def test_git_variables(tmpdir, variables, expected, exception):
sp.run(["git", "-C", str(tmpdir), "init"], check=True)
config = ConfigParser()
for section, name, value in variables:
config.setdefault(section, {})
config[section][name] = value
with open(tmpdir / '.git' / 'config', 'at') as fobj:
config.write(fobj)

args = (tmpdir, *expected.keys())
if exception is not None:
pytest.raises(exception, git_variables, *args)
else:
test_vars = git_variables(*args)
assert test_vars == expected

0 comments on commit 8ef5b7c

Please sign in to comment.