@@ -807,9 +807,9 @@ def test_dataclasses(self, pytester: Pytester) -> None:
807807 "E ['field_b']" ,
808808 "E " ,
809809 "E Drill down into differing attribute field_b:" ,
810- "E field_b: 'b' != 'c'... " ,
811- "E " ,
812- "E ...Full output truncated (3 lines hidden), use '-vv' to show " ,
810+ "E field_b: 'b' != 'c'" ,
811+ "E - c " ,
812+ "E + b " ,
813813 ],
814814 consecutive = True ,
815815 )
@@ -827,7 +827,7 @@ def test_recursive_dataclasses(self, pytester: Pytester) -> None:
827827 "E Drill down into differing attribute g:" ,
828828 "E g: S(a=10, b='ten') != S(a=20, b='xxx')..." ,
829829 "E " ,
830- "E ...Full output truncated (52 lines hidden), use '-vv' to show" ,
830+ "E ...Full output truncated (51 lines hidden), use '-vv' to show" ,
831831 ],
832832 consecutive = True ,
833833 )
@@ -1188,30 +1188,55 @@ def test_doesnt_truncate_at_when_input_is_5_lines_and_LT_max_chars(self) -> None
11881188 def test_truncates_at_8_lines_when_given_list_of_empty_strings (self ) -> None :
11891189 expl = ["" for x in range (50 )]
11901190 result = truncate ._truncate_explanation (expl , max_lines = 8 , max_chars = 100 )
1191+ assert len (result ) != len (expl )
11911192 assert result != expl
11921193 assert len (result ) == 8 + self .LINES_IN_TRUNCATION_MSG
11931194 assert "Full output truncated" in result [- 1 ]
1194- assert "43 lines hidden" in result [- 1 ]
1195+ assert "42 lines hidden" in result [- 1 ]
11951196 last_line_before_trunc_msg = result [- self .LINES_IN_TRUNCATION_MSG - 1 ]
11961197 assert last_line_before_trunc_msg .endswith ("..." )
11971198
11981199 def test_truncates_at_8_lines_when_first_8_lines_are_LT_max_chars (self ) -> None :
1199- expl = ["a" for x in range (100 )]
1200+ total_lines = 100
1201+ expl = ["a" for x in range (total_lines )]
12001202 result = truncate ._truncate_explanation (expl , max_lines = 8 , max_chars = 8 * 80 )
12011203 assert result != expl
12021204 assert len (result ) == 8 + self .LINES_IN_TRUNCATION_MSG
12031205 assert "Full output truncated" in result [- 1 ]
1204- assert "93 lines hidden" in result [- 1 ]
1206+ assert f" { total_lines - 8 } lines hidden" in result [- 1 ]
12051207 last_line_before_trunc_msg = result [- self .LINES_IN_TRUNCATION_MSG - 1 ]
12061208 assert last_line_before_trunc_msg .endswith ("..." )
12071209
1210+ def test_truncates_at_8_lines_when_there_is_one_line_to_remove (self ) -> None :
1211+ """The number of line in the result is 9, the same number as if we truncated."""
1212+ expl = ["a" for x in range (9 )]
1213+ result = truncate ._truncate_explanation (expl , max_lines = 8 , max_chars = 8 * 80 )
1214+ assert result == expl
1215+ assert "truncated" not in result [- 1 ]
1216+
1217+ def test_truncates_edgecase_when_truncation_message_makes_the_result_longer_for_chars (
1218+ self ,
1219+ ) -> None :
1220+ line = "a" * 10
1221+ expl = [line , line ]
1222+ result = truncate ._truncate_explanation (expl , max_lines = 10 , max_chars = 10 )
1223+ assert result == [line , line ]
1224+
1225+ def test_truncates_edgecase_when_truncation_message_makes_the_result_longer_for_lines (
1226+ self ,
1227+ ) -> None :
1228+ line = "a" * 10
1229+ expl = [line , line ]
1230+ result = truncate ._truncate_explanation (expl , max_lines = 1 , max_chars = 100 )
1231+ assert result == [line , line ]
1232+
12081233 def test_truncates_at_8_lines_when_first_8_lines_are_EQ_max_chars (self ) -> None :
1209- expl = ["a" * 80 for x in range (16 )]
1234+ expl = [chr ( 97 + x ) * 80 for x in range (16 )]
12101235 result = truncate ._truncate_explanation (expl , max_lines = 8 , max_chars = 8 * 80 )
12111236 assert result != expl
1212- assert len (result ) == 8 + self .LINES_IN_TRUNCATION_MSG
1237+ assert len (result ) == 16 - 8 + self .LINES_IN_TRUNCATION_MSG
12131238 assert "Full output truncated" in result [- 1 ]
1214- assert "9 lines hidden" in result [- 1 ]
1239+ assert "8 lines hidden" in result [- 1 ]
12151240 last_line_before_trunc_msg = result [- self .LINES_IN_TRUNCATION_MSG - 1 ]
12161241 assert last_line_before_trunc_msg .endswith ("..." )
12171242
@@ -1240,7 +1265,7 @@ def test_full_output_truncated(self, monkeypatch, pytester: Pytester) -> None:
12401265
12411266 line_count = 7
12421267 line_len = 100
1243- expected_truncated_lines = 2
1268+ expected_truncated_lines = 1
12441269 pytester .makepyfile (
12451270 r"""
12461271 def test_many_lines():
@@ -1261,7 +1286,7 @@ def test_many_lines():
12611286 "*+ 1*" ,
12621287 "*+ 3*" ,
12631288 "*+ 5*" ,
1264- "*truncated (%d lines hidden)*use*-vv*" % expected_truncated_lines ,
1289+ "*truncated (%d line hidden)*use*-vv*" % expected_truncated_lines ,
12651290 ]
12661291 )
12671292
0 commit comments