Skip to content

Commit

Permalink
test(cli): ensure version flags bypass config creation
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Mar 21, 2024
1 parent dee007f commit 8e98338
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_littlepay.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
import re
import subprocess

import pytest
Expand Down Expand Up @@ -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
21 changes: 21 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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

0 comments on commit 8e98338

Please sign in to comment.