Files
models/tests/test_main.py
T

34 lines
1.2 KiB
Python

"""What this module covers: the command line in `models/__main__.py`.
Fixtures: none; the commands declared so far touch no data.
"""
import subprocess
import sys
import pytest
from models.__main__ import main
def test_help_lists_the_subcommands():
"""`python -m models --help` runs as a module and lists `cohorts`. Fails if the entry point breaks or the
subcommand stops being registered."""
result = subprocess.run([sys.executable, "-m", "models", "--help"], capture_output=True, text=True)
assert result.returncode == 0
assert "cohorts" in result.stdout
def test_a_command_is_required():
"""Without a command the parser exits with an error. Fails if `required=True` is dropped, which would make
a bare call look successful."""
with pytest.raises(SystemExit) as exit_info:
main([])
assert exit_info.value.code == 2
def test_a_command_without_actions_does_not_report_success(capsys):
"""`cohorts` has no actions yet, so it shows its help and returns an error code. Fails if it returns 0, which
would let a script believe it had run."""
assert main(["cohorts"]) == 2
assert "cohorts" in capsys.readouterr().out