@@ -62,3 +62,46 @@ def test_unmodified_traceback():
6262 assert "typer.main.get_command(broken_app)()" in result .stderr
6363 assert "print(name + 3)" in result .stderr
6464 assert 'TypeError: can only concatenate str (not "int") to str' in result .stderr
65+
66+
67+ def test_rich_exceptions_dont_truncate_code_on_wide_terminal ():
68+ file_path = Path (__file__ ).parent / "assets/type_error_rich.py"
69+ result = subprocess .run (
70+ [sys .executable , "-m" , "coverage" , "run" , str (file_path )],
71+ capture_output = True ,
72+ encoding = "utf-8" ,
73+ env = {
74+ ** os .environ ,
75+ "TERMINAL_WIDTH" : "120" ,
76+ "TYPER_STANDARD_TRACEBACK" : "" ,
77+ "_TYPER_STANDARD_TRACEBACK" : "" ,
78+ },
79+ )
80+
81+ assert (
82+ "# The line below will cause TypeError because you cannot concatenate string and integer."
83+ in result .stderr
84+ )
85+
86+
87+ def test_rich_exceptions_wrap_words_on_small_width_terminal ():
88+ file_path = Path (__file__ ).parent / "assets/type_error_rich.py"
89+ result = subprocess .run (
90+ [sys .executable , "-m" , "coverage" , "run" , str (file_path )],
91+ capture_output = True ,
92+ encoding = "utf-8" ,
93+ env = {
94+ ** os .environ ,
95+ "TERMINAL_WIDTH" : "80" ,
96+ "TYPER_STANDARD_TRACEBACK" : "" ,
97+ "_TYPER_STANDARD_TRACEBACK" : "" ,
98+ },
99+ )
100+
101+ # Long line is wrapped, so the full line is not in the output, but parts of it are.
102+ assert "# The line below will cause TypeError because you cannot" in result .stderr
103+ assert "concatenate string and integer." in result .stderr
104+ assert (
105+ "# The line below will cause TypeError because you cannot concatenate string and integer."
106+ not in result .stderr
107+ )
0 commit comments