Coverage for tests/test_tutorial/test_arguments/test_help/test_tutorial001.py: 100%

35 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-04-14 00:18 +0000

1import subprocess 1abcdefghi

2import sys 1abcdefghi

3 

4import typer 1abcdefghi

5import typer.core 1abcdefghi

6from typer.testing import CliRunner 1abcdefghi

7 

8from docs_src.arguments.help import tutorial001 as mod 1abcdefghi

9 

10runner = CliRunner() 1abcdefghi

11 

12app = typer.Typer() 1abcdefghi

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

14 

15 

16def test_help(): 1abcdefghi

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

18 assert result.exit_code == 0 1abcdefghi

19 assert "[OPTIONS] NAME" in result.output 1abcdefghi

20 assert "Arguments" in result.output 1abcdefghi

21 assert "NAME" in result.output 1abcdefghi

22 assert "The name of the user to greet" in result.output 1abcdefghi

23 assert "[required]" in result.output 1abcdefghi

24 

25 

26def test_help_no_rich(): 1abcdefghi

27 rich = typer.core.rich 1abcdefghi

28 typer.core.rich = None 1abcdefghi

29 result = runner.invoke(app, ["--help"]) 1abcdefghi

30 assert result.exit_code == 0 1abcdefghi

31 assert "[OPTIONS] NAME" in result.output 1abcdefghi

32 assert "Arguments" in result.output 1abcdefghi

33 assert "NAME" in result.output 1abcdefghi

34 assert "The name of the user to greet" in result.output 1abcdefghi

35 assert "[required]" in result.output 1abcdefghi

36 typer.core.rich = rich 1abcdefghi

37 

38 

39def test_call_arg(): 1abcdefghi

40 result = runner.invoke(app, ["Camila"]) 1abcdefghi

41 assert result.exit_code == 0 1abcdefghi

42 assert "Hello Camila" in result.output 1abcdefghi

43 

44 

45def test_script(): 1abcdefghi

46 result = subprocess.run( 1abcdefghi

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

48 capture_output=True, 

49 encoding="utf-8", 

50 ) 

51 assert "Usage" in result.stdout 1abcdefghi