test_cli.py
1 """Tests for the CLI.""" 2 3 from __future__ import annotations 4 5 import sys 6 7 import pytest 8 9 from failprint._internal import debug 10 from failprint._internal.cli import main 11 12 13 def test_fail_without_arguments() -> None: 14 """Fails without arguments.""" 15 with pytest.raises(SystemExit): 16 main([]) 17 18 19 def test_show_help(capsys: pytest.CaptureFixture) -> None: 20 """Show help. 21 22 Parameters: 23 capsys: Pytest fixture to capture output. 24 """ 25 with pytest.raises(SystemExit): 26 main(["-h"]) 27 captured = capsys.readouterr() 28 assert "failprint" in captured.out 29 30 31 def test_run_command() -> None: 32 """Run a simple command.""" 33 assert main(["--", sys.executable, "-c", "print('hello')"]) == 0 34 35 36 def test_accept_custom_format(capsys: pytest.CaptureFixture) -> None: 37 """Run a command with a custom output format. 38 39 Arguments: 40 capsys: Pytest fixture to capture output. 41 """ 42 assert main(["--no-progress", "-f", "custom={{output}}", "--", sys.executable, "-c", "print('custom')"]) == 0 43 outerr = capsys.readouterr() 44 assert "custom" in outerr.out 45 46 47 def test_show_version(capsys: pytest.CaptureFixture) -> None: 48 """Show version. 49 50 Parameters: 51 capsys: Pytest fixture to capture output. 52 """ 53 with pytest.raises(SystemExit): 54 main(["-V"]) 55 captured = capsys.readouterr() 56 assert debug._get_version() in captured.out 57 58 59 def test_show_debug_info(capsys: pytest.CaptureFixture) -> None: 60 """Show debug information. 61 62 Parameters: 63 capsys: Pytest fixture to capture output. 64 """ 65 with pytest.raises(SystemExit): 66 main(["--debug-info"]) 67 captured = capsys.readouterr().out.lower() 68 assert "python" in captured 69 assert "system" in captured 70 assert "environment" in captured 71 assert "packages" in captured