Coverage for tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py: 100%

39 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-19 20:29 +0000

1import subprocess 1abcdefghi

2import sys 1abcdefghi

3 

4from typer.testing import CliRunner 1abcdefghi

5 

6from docs_src.parameter_types.enum import tutorial001 as mod 1abcdefghi

7 

8runner = CliRunner() 1abcdefghi

9app = mod.app 1abcdefghi

10 

11 

12def test_help(): 1abcdefghi

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

14 assert result.exit_code == 0 1abcdefghi

15 assert "--network" in result.output 1abcdefghi

16 assert "[simple|conv|lstm]" in result.output 1abcdefghi

17 assert "default: simple" in result.output 1abcdefghi

18 

19 

20def test_main(): 1abcdefghi

21 result = runner.invoke(app, ["--network", "conv"]) 1abcdefghi

22 assert result.exit_code == 0 1abcdefghi

23 assert "Training neural network of type: conv" in result.output 1abcdefghi

24 

25 

26def test_main_default(): 1abcdefghi

27 result = runner.invoke(app) 1abcdefghi

28 assert result.exit_code == 0 1abcdefghi

29 assert "Training neural network of type: simple" in result.output 1abcdefghi

30 

31 

32def test_invalid_case(): 1abcdefghi

33 result = runner.invoke(app, ["--network", "CONV"]) 1abcdefghi

34 assert result.exit_code != 0 1abcdefghi

35 assert "Invalid value for '--network'" in result.output 1abcdefghi

36 assert "'CONV' is not one of" in result.output 1abcdefghi

37 assert "simple" in result.output 1abcdefghi

38 assert "conv" in result.output 1abcdefghi

39 assert "lstm" in result.output 1abcdefghi

40 

41 

42def test_invalid_other(): 1abcdefghi

43 result = runner.invoke(app, ["--network", "capsule"]) 1abcdefghi

44 assert result.exit_code != 0 1abcdefghi

45 assert "Invalid value for '--network'" in result.output 1abcdefghi

46 assert "'capsule' is not one of" in result.output 1abcdefghi

47 assert "simple" in result.output 1abcdefghi

48 assert "conv" in result.output 1abcdefghi

49 assert "lstm" in result.output 1abcdefghi

50 

51 

52def test_script(): 1abcdefghi

53 result = subprocess.run( 1abcdefghi

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

55 capture_output=True, 

56 encoding="utf-8", 

57 ) 

58 assert "Usage" in result.stdout 1abcdefghi