Coverage for tests/test_tutorial/test_multiple_values/test_arguments_with_multiple_values/test_tutorial002.py: 100%

33 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

5from typer.testing import CliRunner 1abcdefgh

6 

7from docs_src.multiple_values.arguments_with_multiple_values import tutorial002 as mod 1abcdefgh

8 

9runner = CliRunner() 1abcdefgh

10app = typer.Typer() 1abcdefgh

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

12 

13 

14def test_help(): 1abcdefgh

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

16 assert result.exit_code == 0 1abcdefgh

17 assert "[OPTIONS] [NAMES]..." in result.output 1abcdefgh

18 assert "Arguments" in result.output 1abcdefgh

19 assert "[default: Harry, Hermione, Ron]" in result.output 1abcdefgh

20 

21 

22def test_defaults(): 1abcdefgh

23 result = runner.invoke(app) 1abcdefgh

24 assert result.exit_code == 0 1abcdefgh

25 assert "Hello Harry" in result.output 1abcdefgh

26 assert "Hello Hermione" in result.output 1abcdefgh

27 assert "Hello Ron" in result.output 1abcdefgh

28 

29 

30def test_invalid_args(): 1abcdefgh

31 result = runner.invoke(app, ["Draco", "Hagrid"]) 1abcdefgh

32 assert result.exit_code != 0 1abcdefgh

33 assert "Argument 'names' takes 3 values" in result.stdout 1abcdefgh

34 

35 

36def test_valid_args(): 1abcdefgh

37 result = runner.invoke(app, ["Draco", "Hagrid", "Dobby"]) 1abcdefgh

38 assert result.exit_code == 0 1abcdefgh

39 assert "Hello Draco" in result.stdout 1abcdefgh

40 assert "Hello Hagrid" in result.stdout 1abcdefgh

41 assert "Hello Dobby" in result.stdout 1abcdefgh

42 

43 

44def test_script(): 1abcdefgh

45 result = subprocess.run( 1abcdefgh

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

47 capture_output=True, 

48 encoding="utf-8", 

49 ) 

50 assert "Usage" in result.stdout 1abcdefgh