Coverage for tests/test_tutorial/test_parameter_types/test_bool/test_tutorial002_an.py: 100%

43 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +0000

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3 

4import typer 1abcdefgh

5import typer.core 1abcdefgh

6from typer.testing import CliRunner 1abcdefgh

7 

8from docs_src.parameter_types.bool import tutorial002_an as mod 1abcdefgh

9 

10runner = CliRunner() 1abcdefgh

11 

12app = typer.Typer() 1abcdefgh

13app.command()(mod.main) 1abcdefgh

14 

15 

16def test_help(): 1abcdefgh

17 result = runner.invoke(app, ["--help"]) 1abcdefgh

18 assert result.exit_code == 0 1abcdefgh

19 assert "--accept" in result.output 1abcdefgh

20 assert "--reject" in result.output 1abcdefgh

21 assert "--no-accept" not in result.output 1abcdefgh

22 

23 

24def test_help_no_rich(): 1abcdefgh

25 rich = typer.core.rich 1abcdefgh

26 typer.core.rich = None 1abcdefgh

27 result = runner.invoke(app, ["--help"]) 1abcdefgh

28 assert result.exit_code == 0 1abcdefgh

29 assert "--accept" in result.output 1abcdefgh

30 assert "--reject" in result.output 1abcdefgh

31 assert "--no-accept" not in result.output 1abcdefgh

32 typer.core.rich = rich 1abcdefgh

33 

34 

35def test_main(): 1abcdefgh

36 result = runner.invoke(app) 1abcdefgh

37 assert result.exit_code == 0 1abcdefgh

38 assert "I don't know what you want yet" in result.output 1abcdefgh

39 

40 

41def test_accept(): 1abcdefgh

42 result = runner.invoke(app, ["--accept"]) 1abcdefgh

43 assert result.exit_code == 0 1abcdefgh

44 assert "Accepting!" in result.output 1abcdefgh

45 

46 

47def test_reject(): 1abcdefgh

48 result = runner.invoke(app, ["--reject"]) 1abcdefgh

49 assert result.exit_code == 0 1abcdefgh

50 assert "Rejecting!" in result.output 1abcdefgh

51 

52 

53def test_invalid_no_accept(): 1abcdefgh

54 result = runner.invoke(app, ["--no-accept"]) 1abcdefgh

55 assert result.exit_code != 0 1abcdefgh

56 assert "No such option: --no-accept" in result.output 1abcdefgh

57 

58 

59def test_script(): 1abcdefgh

60 result = subprocess.run( 1abcdefgh

61 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], 

62 capture_output=True, 

63 encoding="utf-8", 

64 ) 

65 assert "Usage" in result.stdout 1abcdefgh