Coverage for tests/test_tutorial/test_options/test_required/test_tutorial001_an.py: 100%

35 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.options.required import tutorial001_an as mod 1abcdefgh

9 

10runner = CliRunner() 1abcdefgh

11 

12app = typer.Typer() 1abcdefgh

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

14 

15 

16def test_1(): 1abcdefgh

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

18 assert result.exit_code != 0 1abcdefgh

19 assert "Missing option '--lastname'." in result.output 1abcdefgh

20 

21 

22def test_option_lastname(): 1abcdefgh

23 result = runner.invoke(app, ["Camila", "--lastname", "Gutiérrez"]) 1abcdefgh

24 assert result.exit_code == 0 1abcdefgh

25 assert "Hello Camila Gutiérrez" in result.output 1abcdefgh

26 

27 

28def test_help(): 1abcdefgh

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

30 assert result.exit_code == 0 1abcdefgh

31 assert "--lastname" in result.output 1abcdefgh

32 assert "TEXT" in result.output 1abcdefgh

33 assert "[required]" in result.output 1abcdefgh

34 

35 

36def test_help_no_rich(): 1abcdefgh

37 rich = typer.core.rich 1abcdefgh

38 typer.core.rich = None 1abcdefgh

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

40 assert result.exit_code == 0 1abcdefgh

41 assert "--lastname" in result.output 1abcdefgh

42 assert "TEXT" in result.output 1abcdefgh

43 assert "[required]" in result.output 1abcdefgh

44 typer.core.rich = rich 1abcdefgh

45 

46 

47def test_script(): 1abcdefgh

48 result = subprocess.run( 1abcdefgh

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

50 capture_output=True, 

51 encoding="utf-8", 

52 ) 

53 assert "Usage" in result.stdout 1abcdefgh