Coverage for tests/test_tracebacks.py: 100%

26 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

4from pathlib import Path 1abcdefgh

5 

6 

7def test_traceback_no_rich(): 1abcdefgh

8 file_path = Path(__file__).parent / "assets/type_error_no_rich.py" 1abcdefgh

9 result = subprocess.run( 1abcdefgh

10 [sys.executable, "-m", "coverage", "run", str(file_path)], 

11 capture_output=True, 

12 encoding="utf-8", 

13 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""}, 

14 ) 

15 assert "return get_command(self)(*args, **kwargs)" not in result.stderr 1abcdefgh

16 

17 assert "typer.run(main)" in result.stderr 1abcdefgh

18 assert "print(name + 3)" in result.stderr 1abcdefgh

19 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefgh

20 

21 

22def test_traceback_no_rich_short_disable(): 1abcdefgh

23 file_path = Path(__file__).parent / "assets/type_error_no_rich_short_disable.py" 1abcdefgh

24 result = subprocess.run( 1abcdefgh

25 [sys.executable, "-m", "coverage", "run", str(file_path)], 

26 capture_output=True, 

27 encoding="utf-8", 

28 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""}, 

29 ) 

30 assert "return get_command(self)(*args, **kwargs)" not in result.stderr 1abcdefgh

31 

32 assert "app()" in result.stderr 1abcdefgh

33 assert "print(name + 3)" in result.stderr 1abcdefgh

34 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefgh

35 

36 

37def test_unmodified_traceback(): 1abcdefgh

38 file_path = Path(__file__).parent / "assets/type_error_normal_traceback.py" 1abcdefgh

39 result = subprocess.run( 1abcdefgh

40 [sys.executable, "-m", "coverage", "run", str(file_path)], 

41 capture_output=True, 

42 encoding="utf-8", 

43 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""}, 

44 ) 

45 assert "morty" in result.stdout, "the call to the first app should work normally" 1abcdefgh

46 assert "return callback(**use_params)" in result.stderr, ( 1abcdefgh

47 "calling outside of Typer should show the normal traceback, " 

48 "even after the hook is installed" 

49 ) 

50 assert "typer.main.get_command(broken_app)()" in result.stderr 1abcdefgh

51 assert "print(name + 3)" in result.stderr 1abcdefgh

52 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefgh