annotate Lib/test/test_difflib.py @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents f554dfff7450
children 713f1f6bf339
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 19817
diff changeset
1 import difflib
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
2 from test.test_support import run_unittest, findfile
29719
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
3 import unittest
29892
79ec7e302d53 Exercise Jim Fulton's new doctest extension for running doctests in a
Raymond Hettinger <python@rcn.com>
parents: 29719
diff changeset
4 import doctest
36429
16bfe9386068 Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 33326
diff changeset
5 import sys
29719
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
6
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
7 class TestSFbugs(unittest.TestCase):
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
8
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
9 def test_ratio_for_null_seqn(self):
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
10 # Check clearing of SF bug 763023
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
11 s = difflib.SequenceMatcher(None, [], [])
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
12 self.assertEqual(s.ratio(), 1)
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
13 self.assertEqual(s.quick_ratio(), 1)
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
14 self.assertEqual(s.real_quick_ratio(), 1)
fa4cf878c538 Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents: 24364
diff changeset
15
32612
5546c7ae24f7 SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents: 31389
diff changeset
16 def test_comparing_empty_lists(self):
5546c7ae24f7 SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents: 31389
diff changeset
17 # Check fix for bug #979794
5546c7ae24f7 SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents: 31389
diff changeset
18 group_gen = difflib.SequenceMatcher(None, [], []).get_grouped_opcodes()
5546c7ae24f7 SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents: 31389
diff changeset
19 self.assertRaises(StopIteration, group_gen.next)
5546c7ae24f7 SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents: 31389
diff changeset
20 diff_gen = difflib.unified_diff([], [])
5546c7ae24f7 SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents: 31389
diff changeset
21 self.assertRaises(StopIteration, diff_gen.next)
5546c7ae24f7 SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents: 31389
diff changeset
22
57411
f554dfff7450 Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
Senthil Kumaran <orsenthil@gmail.com>
parents: 54389
diff changeset
23 def test_added_tab_hint(self):
f554dfff7450 Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
Senthil Kumaran <orsenthil@gmail.com>
parents: 54389
diff changeset
24 # Check fix for bug #1488943
f554dfff7450 Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
Senthil Kumaran <orsenthil@gmail.com>
parents: 54389
diff changeset
25 diff = list(difflib.Differ().compare(["\tI am a buggy"],["\t\tI am a bug"]))
f554dfff7450 Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
Senthil Kumaran <orsenthil@gmail.com>
parents: 54389
diff changeset
26 self.assertEqual("- \tI am a buggy", diff[0])
f554dfff7450 Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
Senthil Kumaran <orsenthil@gmail.com>
parents: 54389
diff changeset
27 self.assertEqual("? --\n", diff[1])
f554dfff7450 Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
Senthil Kumaran <orsenthil@gmail.com>
parents: 54389
diff changeset
28 self.assertEqual("+ \t\tI am a bug", diff[2])
f554dfff7450 Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
Senthil Kumaran <orsenthil@gmail.com>
parents: 54389
diff changeset
29 self.assertEqual("? +\n", diff[3])
f554dfff7450 Fix for issue1488943 - difflib.Differ() doesn't always add hints for tab
Senthil Kumaran <orsenthil@gmail.com>
parents: 54389
diff changeset
30
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
31 patch914575_from1 = """
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
32 1. Beautiful is beTTer than ugly.
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
33 2. Explicit is better than implicit.
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
34 3. Simple is better than complex.
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
35 4. Complex is better than complicated.
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
36 """
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
37
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
38 patch914575_to1 = """
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
39 1. Beautiful is better than ugly.
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
40 3. Simple is better than complex.
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
41 4. Complicated is better than complex.
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
42 5. Flat is better than nested.
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
43 """
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
44
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
45 patch914575_from2 = """
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
46 \t\tLine 1: preceeded by from:[tt] to:[ssss]
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
47 \t\tLine 2: preceeded by from:[sstt] to:[sssst]
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
48 \t \tLine 3: preceeded by from:[sstst] to:[ssssss]
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
49 Line 4: \thas from:[sst] to:[sss] after :
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
50 Line 5: has from:[t] to:[ss] at end\t
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
51 """
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
52
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
53 patch914575_to2 = """
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
54 Line 1: preceeded by from:[tt] to:[ssss]
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
55 \tLine 2: preceeded by from:[sstt] to:[sssst]
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
56 Line 3: preceeded by from:[sstst] to:[ssssss]
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
57 Line 4: has from:[sst] to:[sss] after :
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
58 Line 5: has from:[t] to:[ss] at end
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
59 """
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
60
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
61 patch914575_from3 = """line 0
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
62 1234567890123456789012345689012345
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
63 line 1
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
64 line 2
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
65 line 3
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
66 line 4 changed
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
67 line 5 changed
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
68 line 6 changed
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
69 line 7
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
70 line 8 subtracted
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
71 line 9
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
72 1234567890123456789012345689012345
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
73 short line
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
74 just fits in!!
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
75 just fits in two lines yup!!
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
76 the end"""
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
77
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
78 patch914575_to3 = """line 0
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
79 1234567890123456789012345689012345
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
80 line 1
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
81 line 2 added
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
82 line 3
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
83 line 4 chanGEd
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
84 line 5a chanGed
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
85 line 6a changEd
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
86 line 7
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
87 line 8
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
88 line 9
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
89 1234567890
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
90 another long line that needs to be wrapped
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
91 just fitS in!!
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
92 just fits in two lineS yup!!
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
93 the end"""
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
94
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
95 class TestSFpatches(unittest.TestCase):
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
96
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
97 def test_html_diff(self):
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
98 # Check SF patch 914575 for generating HTML differences
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
99 f1a = ((patch914575_from1 + '123\n'*10)*3)
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
100 t1a = (patch914575_to1 + '123\n'*10)*3
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
101 f1b = '456\n'*10 + f1a
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
102 t1b = '456\n'*10 + t1a
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
103 f1a = f1a.splitlines()
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
104 t1a = t1a.splitlines()
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
105 f1b = f1b.splitlines()
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
106 t1b = t1b.splitlines()
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
107 f2 = patch914575_from2.splitlines()
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
108 t2 = patch914575_to2.splitlines()
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
109 f3 = patch914575_from3
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
110 t3 = patch914575_to3
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
111 i = difflib.HtmlDiff()
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
112 j = difflib.HtmlDiff(tabsize=2)
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
113 k = difflib.HtmlDiff(wrapcolumn=14)
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
114
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
115 full = i.make_file(f1a,t1a,'from','to',context=False,numlines=5)
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
116 tables = '\n'.join(
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
117 [
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
118 '<h2>Context (first diff within numlines=5(default))</h2>',
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
119 i.make_table(f1a,t1a,'from','to',context=True),
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
120 '<h2>Context (first diff after numlines=5(default))</h2>',
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
121 i.make_table(f1b,t1b,'from','to',context=True),
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
122 '<h2>Context (numlines=6)</h2>',
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
123 i.make_table(f1a,t1a,'from','to',context=True,numlines=6),
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
124 '<h2>Context (numlines=0)</h2>',
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
125 i.make_table(f1a,t1a,'from','to',context=True,numlines=0),
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
126 '<h2>Same Context</h2>',
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
127 i.make_table(f1a,f1a,'from','to',context=True),
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
128 '<h2>Same Full</h2>',
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
129 i.make_table(f1a,f1a,'from','to',context=False),
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
130 '<h2>Empty Context</h2>',
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
131 i.make_table([],[],'from','to',context=True),
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
132 '<h2>Empty Full</h2>',
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
133 i.make_table([],[],'from','to',context=False),
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
134 '<h2>tabsize=2</h2>',
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
135 j.make_table(f2,t2),
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
136 '<h2>tabsize=default</h2>',
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
137 i.make_table(f2,t2),
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
138 '<h2>Context (wrapcolumn=14,numlines=0)</h2>',
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
139 k.make_table(f3.splitlines(),t3.splitlines(),context=True,numlines=0),
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
140 '<h2>wrapcolumn=14,splitlines()</h2>',
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
141 k.make_table(f3.splitlines(),t3.splitlines()),
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
142 '<h2>wrapcolumn=14,splitlines(True)</h2>',
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
143 k.make_table(f3.splitlines(True),t3.splitlines(True)),
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
144 ])
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
145 actual = full.replace('</body>','\n%s\n</body>' % tables)
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
146
54389
70fb848870ac explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents: 37550
diff changeset
147 # temporarily uncomment next two lines to baseline this test
70fb848870ac explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents: 37550
diff changeset
148 #with open('test_difflib_expect.html','w') as fp:
70fb848870ac explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents: 37550
diff changeset
149 # fp.write(actual)
33326
787fff51bf2a Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents: 33324
diff changeset
150
54389
70fb848870ac explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents: 37550
diff changeset
151 with open(findfile('test_difflib_expect.html')) as fp:
70fb848870ac explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents: 37550
diff changeset
152 self.assertEqual(actual, fp.read())
33319
6d3bdd19beeb Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Martin v. Löwis <martin@v.loewis.de>
parents: 32612
diff changeset
153
36429
16bfe9386068 Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 33326
diff changeset
154 def test_recursion_limit(self):
16bfe9386068 Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 33326
diff changeset
155 # Check if the problem described in patch #1413711 exists.
16bfe9386068 Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 33326
diff changeset
156 limit = sys.getrecursionlimit()
16bfe9386068 Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 33326
diff changeset
157 old = [(i%2 and "K:%d" or "V:A:%d") % i for i in range(limit*2)]
16bfe9386068 Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 33326
diff changeset
158 new = [(i%2 and "K:%d" or "V:B:%d") % i for i in range(limit*2)]
16bfe9386068 Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 33326
diff changeset
159 difflib.SequenceMatcher(None, old, new).get_opcodes()
16bfe9386068 Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 33326
diff changeset
160
16bfe9386068 Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 33326
diff changeset
161
37550
0342c5f0f4ff Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents: 36429
diff changeset
162 def test_main():
0342c5f0f4ff Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents: 36429
diff changeset
163 difflib.HtmlDiff._default_prefix = 0
0342c5f0f4ff Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents: 36429
diff changeset
164 Doctests = doctest.DocTestSuite(difflib)
0342c5f0f4ff Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents: 36429
diff changeset
165 run_unittest(TestSFpatches, TestSFbugs, Doctests)
29892
79ec7e302d53 Exercise Jim Fulton's new doctest extension for running doctests in a
Raymond Hettinger <python@rcn.com>
parents: 29719
diff changeset
166
37550
0342c5f0f4ff Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents: 36429
diff changeset
167 if __name__ == '__main__':
0342c5f0f4ff Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents: 36429
diff changeset
168 test_main()