Coverage for tests/test_tutorial/test_options/test_callback/test_tutorial004_an.py: 100%

24 statements  

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

1import os 1abcdefgh

2import subprocess 1abcdefgh

3import sys 1abcdefgh

4 

5import typer 1abcdefgh

6from typer.testing import CliRunner 1abcdefgh

7 

8from docs_src.options.callback import tutorial004_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, ["--name", "Camila"]) 1abcdefgh

18 assert result.exit_code == 0 1abcdefgh

19 assert "Validating param: name" in result.output 1abcdefgh

20 assert "Hello Camila" in result.output 1abcdefgh

21 

22 

23def test_2(): 1abcdefgh

24 result = runner.invoke(app, ["--name", "rick"]) 1abcdefgh

25 assert result.exit_code != 0 1abcdefgh

26 assert "Invalid value for '--name': Only Camila is allowed" in result.output 1abcdefgh

27 

28 

29def test_script(): 1abcdefgh

30 result = subprocess.run( 1abcdefgh

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

32 capture_output=True, 

33 encoding="utf-8", 

34 ) 

35 assert "Usage" in result.stdout 1abcdefgh

36 

37 

38def test_completion(): 1abcdefgh

39 result = subprocess.run( 1abcdefgh

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

41 capture_output=True, 

42 encoding="utf-8", 

43 env={ 

44 **os.environ, 

45 "_TUTORIAL004_AN.PY_COMPLETE": "complete_bash", 

46 "COMP_WORDS": "tutorial004_an.py --", 

47 "COMP_CWORD": "1", 

48 }, 

49 ) 

50 assert "--name" in result.stdout 1abcdefgh