Coverage for tests/test_cli.py: 94.12%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-15 16:47 +0200

1"""Tests for the `cli` module.""" 

2 

3from __future__ import annotations 

4 

5import sys 

6 

7import pytest 

8 

9from _griffe import cli, debug 

10 

11 

12def test_main() -> None: 

13 """Basic CLI test.""" 

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

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

16 else: 

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

18 

19 

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

21 """Show help. 

22 

23 Parameters: 

24 capsys: Pytest fixture to capture output. 

25 """ 

26 with pytest.raises(SystemExit): 

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

28 captured = capsys.readouterr() 

29 assert "griffe" in captured.out 

30 

31 

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

33 """Show version. 

34 

35 Parameters: 

36 capsys: Pytest fixture to capture output. 

37 """ 

38 with pytest.raises(SystemExit): 

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

40 captured = capsys.readouterr() 

41 assert debug._get_version() in captured.out 

42 

43 

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

45 """Show debug information. 

46 

47 Parameters: 

48 capsys: Pytest fixture to capture output. 

49 """ 

50 with pytest.raises(SystemExit): 

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

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

53 assert "python" in captured 

54 assert "system" in captured 

55 assert "environment" in captured 

56 assert "packages" in captured