diff --git a/.travis.yml b/.travis.yml index 908f5b6..de57439 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/niflow_manager/util/tests/__init__.py b/niflow_manager/util/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/niflow_manager/util/tests/test_git.py b/niflow_manager/util/tests/test_git.py new file mode 100644 index 0000000..58b1c60 --- /dev/null +++ b/niflow_manager/util/tests/test_git.py @@ -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