Coverage for tests / test_cli.py: 93.10%

27 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-02-11 11:48 +0100

1"""Tests for the CLI.""" 

2 

3from __future__ import annotations 

4 

5import sys 

6 

7import pytest 

8 

9from griffe._internal import debug 

10from griffecli._internal import cli 

11 

12 

13def test_main() -> None: 

14 """Basic CLI test.""" 

15 if sys.platform == "win32": 15 ↛ 16line 15 didn't jump to line 16 because the condition on line 15 was never true

16 assert cli.main(["dump", "griffe", "-s", "src", "-oNUL"]) == 0 

17 else: 

18 assert cli.main(["dump", "griffe", "-s", "src", "-o/dev/null"]) == 0 

19 

20 

21def test_show_help(capsys: pytest.CaptureFixture) -> None: 

22 """Show help. 

23 

24 Parameters: 

25 capsys: Pytest fixture to capture output. 

26 """ 

27 with pytest.raises(SystemExit): 

28 cli.main(["-h"]) 

29 captured = capsys.readouterr() 

30 assert "griffe" in captured.out 

31 

32 

33def test_show_version(capsys: pytest.CaptureFixture) -> None: 

34 """Show version. 

35 

36 Parameters: 

37 capsys: Pytest fixture to capture output. 

38 """ 

39 with pytest.raises(SystemExit): 

40 cli.main(["-V"]) 

41 captured = capsys.readouterr() 

42 assert debug._get_version() in captured.out 

43 

44 

45def test_show_debug_info(capsys: pytest.CaptureFixture) -> None: 

46 """Show debug information. 

47 

48 Parameters: 

49 capsys: Pytest fixture to capture output. 

50 """ 

51 with pytest.raises(SystemExit): 

52 cli.main(["--debug-info"]) 

53 captured = capsys.readouterr().out.lower() 

54 assert "python" in captured 

55 assert "system" in captured 

56 assert "environment" in captured 

57 assert "packages" in captured