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

18 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 tutorial004 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 "_TUTORIAL004.PY_COMPLETE": "complete_zsh", 

20 "_TYPER_COMPLETE_ARGS": "tutorial004_aux.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 

27 

28def test_1(): 1abcdefgh

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

30 assert result.exit_code == 0 1abcdefgh

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

32 

33 

34def test_script(): 1abcdefgh

35 result = subprocess.run( 1abcdefgh

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

37 capture_output=True, 

38 encoding="utf-8", 

39 ) 

40 assert "Usage" in result.stdout 1abcdefgh