diff --git a/tests/test_littlepay.py b/tests/test_littlepay.py index 203b83e..39f43ee 100644 --- a/tests/test_littlepay.py +++ b/tests/test_littlepay.py @@ -1,4 +1,5 @@ from pathlib import Path +import re import subprocess import pytest @@ -50,3 +51,14 @@ def test_config(capfd): assert "Participants:" in capture.out assert "Active:" in capture.out assert res == RESULT_SUCCESS + + +@pytest.mark.parametrize("version_flag", ["-v", "--version"]) +def test_version(capfd, version_flag): + res = subprocess.call(["littlepay", version_flag]) + capture = capfd.readouterr() + + assert "Creating config file:" not in capture.out + assert "Config:" not in capture.out + assert re.match(r"littlepay \d+\.\d+\.", capture.out) + assert res == RESULT_SUCCESS diff --git a/tests/test_main.py b/tests/test_main.py index 2ad1276..7a3851d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,9 +1,12 @@ from argparse import Namespace from pathlib import Path +import re + import pytest from littlepay.commands import RESULT_FAILURE, RESULT_SUCCESS from littlepay.config import CONFIG_TYPES, Config +import littlepay.main from littlepay.main import main, __name__ as MODULE @@ -268,3 +271,21 @@ def test_main_unrecognized(capfd): capture = capfd.readouterr() assert err.value.code != RESULT_SUCCESS assert "usage: littlepay" in capture.err + + +@pytest.mark.parametrize("version_flag", ["-v", "--version"]) +def test_main_version_flag(version_flag, mocker, capfd, mock_commands_config): + # littlepay.main.Config (the class) + config_cls = mocker.patch.object(littlepay.main, "Config") + # littlepay.main.Config() (an instance) + config = config_cls.return_value + + with pytest.raises(SystemExit) as err: + main(argv=[version_flag]) + capture = capfd.readouterr() + + assert err.value.code == RESULT_SUCCESS + assert re.match(r"littlepay \d+\.\d+\.", capture.out) + mock_commands_config.assert_not_called() + # there should have been no calls to any method on littlepay.main.Config() + assert len(config.mock_calls) == 0