Coverage for tests/test_tutorial/test_exceptions/test_tutorial001.py: 100%
26 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
« 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
4from pathlib import Path 1abcdefgh
6from typer.testing import CliRunner 1abcdefgh
8from docs_src.exceptions import tutorial001 as mod 1abcdefgh
10runner = CliRunner() 1abcdefgh
13def test_traceback_rich(): 1abcdefgh
14 file_path = Path(mod.__file__) 1abcdefgh
15 result = subprocess.run( 1abcdefgh
16 [sys.executable, "-m", "coverage", "run", str(file_path)],
17 capture_output=True,
18 encoding="utf-8",
19 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
20 )
21 assert "return get_command(self)(*args, **kwargs)" not in result.stderr 1abcdefgh
23 assert "typer.run(main)" not in result.stderr 1abcdefgh
24 assert "print(name + 3)" in result.stderr 1abcdefgh
25 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefgh
26 assert "name = 'morty'" in result.stderr 1abcdefgh
29def test_standard_traceback_env_var(): 1abcdefgh
30 file_path = Path(mod.__file__) 1abcdefgh
31 result = subprocess.run( 1abcdefgh
32 [sys.executable, "-m", "coverage", "run", str(file_path)],
33 capture_output=True,
34 encoding="utf-8",
35 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": "1"},
36 )
37 assert "return get_command(self)(*args, **kwargs)" in result.stderr 1abcdefgh
39 assert "typer.run(main)" in result.stderr 1abcdefgh
40 assert "print(name + 3)" in result.stderr 1abcdefgh
41 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefgh
42 assert "name = 'morty'" not in result.stderr 1abcdefgh
45def test_script(): 1abcdefgh
46 result = subprocess.run( 1abcdefgh
47 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
48 capture_output=True,
49 encoding="utf-8",
50 )
51 assert "Usage" in result.stdout 1abcdefgh