with inter-line and intra-line change highlights. The table can be generated in
either full or contextual difference mode.
+ .. warning::
+
+ The trailing newlines get stripped before the diff, so the result can be
+ incomplete. See :gh:`71896` for details.
+
The constructor for this class is:
# change tabs to spaces before it gets more difficult after we insert
# markup
+ # it also removes trailing newlines, causing some diffs to be missed
+ # see: gh-71896
fromlines,tolines = self._tab_newline_replace(fromlines,tolines)
# create diffs iterator which generates side by side from/to data
self.assertIn('content="text/html; charset=us-ascii"', output)
self.assertIn('ımplıcıt', output)
+ def test_strip_trailing_newlines_before_diff(self):
+ # characterization test for the current buggy behavior
+ # see: gh-71896
+ html_diff = difflib.HtmlDiff()
+ from_lines = [
+ "Line 1: no newline after",
+ "Line 2: one newline after\n",
+ "Line 3: several newlines after\n\n\n\n\n",
+ ]
+ to_lines = [
+ "Line 1: no newline after",
+ "Line 2: one newline after", # actually no \n
+ "Line 3: several newlines after", # actually no \n
+ ]
+ output = html_diff.make_table(from_lines, to_lines)
+ # we (currently) expect no line change, so all equal
+ self.assertNotIn('class="diff_add"', output)
+ self.assertNotIn('class="diff_chg"', output)
+ self.assertNotIn('class="diff_sub"', output)
+ self.assertEqual(output.count('>Line 1: no newline after<'), 2)
+ self.assertEqual(output.count('>Line 2: one newline after<'), 2)
+ self.assertEqual(output.count('>Line 3: several newlines after<'), 2)
def test_one_insert(self):
m = difflib.Differ().compare('b' * 2, 'a' + 'b' * 2)