Coverage for tests/test_tutorial/test_options_autocompletion/test_tutorial008_an.py: 100%

20 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 

5from typer.testing import CliRunner 1abcdefgh

6 

7from docs_src.options_autocompletion import tutorial008_an as mod 1abcdefgh

8 

9runner = CliRunner() 1abcdefgh

10 

11 

12def test_completion(): 1abcdefgh

13 result = subprocess.run( 1abcdefgh

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

15 capture_output=True, 

16 encoding="utf-8", 

17 env={ 

18 **os.environ, 

19 "_TUTORIAL008_AN.PY_COMPLETE": "complete_zsh", 

20 "_TYPER_COMPLETE_ARGS": "tutorial008_an.py --name ", 

21 }, 

22 ) 

23 assert '"Camila":"The reader of books."' in result.stdout 1abcdefgh

24 assert '"Carlos":"The writer of scripts."' in result.stdout 1abcdefgh

25 assert '"Sebastian":"The type hints guy."' in result.stdout 1abcdefgh

26 assert "[]" in result.stderr 1abcdefgh

27 

28 

29def test_1(): 1abcdefgh

30 result = runner.invoke(mod.app, ["--name", "Camila", "--name", "Sebastian"]) 1abcdefgh

31 assert result.exit_code == 0 1abcdefgh

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

33 assert "Hello Sebastian" in result.output 1abcdefgh

34 

35 

36def test_script(): 1abcdefgh

37 result = subprocess.run( 1abcdefgh

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

39 capture_output=True, 

40 encoding="utf-8", 

41 ) 

42 assert "Usage" in result.stdout 1abcdefgh