Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_difflib.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 09459397f807 |
| children |
| 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 |
|
66156
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
7 |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
8 class TestWithAscii(unittest.TestCase): |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
9 def test_one_insert(self): |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
10 sm = difflib.SequenceMatcher(None, 'b' * 100, 'a' + 'b' * 100) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
11 self.assertAlmostEqual(sm.ratio(), 0.995, places=3) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
12 self.assertEqual(list(sm.get_opcodes()), |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
13 [ ('insert', 0, 0, 0, 1), |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
14 ('equal', 0, 100, 1, 101)]) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
15 sm = difflib.SequenceMatcher(None, 'b' * 100, 'b' * 50 + 'a' + 'b' * 50) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
16 self.assertAlmostEqual(sm.ratio(), 0.995, places=3) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
17 self.assertEqual(list(sm.get_opcodes()), |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
18 [ ('equal', 0, 50, 0, 50), |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
19 ('insert', 50, 50, 50, 51), |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
20 ('equal', 50, 100, 51, 101)]) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
21 |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
22 def test_one_delete(self): |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
23 sm = difflib.SequenceMatcher(None, 'a' * 40 + 'c' + 'b' * 40, 'a' * 40 + 'b' * 40) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
24 self.assertAlmostEqual(sm.ratio(), 0.994, places=3) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
25 self.assertEqual(list(sm.get_opcodes()), |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
26 [ ('equal', 0, 40, 0, 40), |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
27 ('delete', 40, 41, 40, 40), |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
28 ('equal', 41, 81, 40, 80)]) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
29 |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
30 |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
31 class TestAutojunk(unittest.TestCase): |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
32 """Tests for the autojunk parameter added in 2.7""" |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
33 def test_one_insert_homogenous_sequence(self): |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
34 # By default autojunk=True and the heuristic kicks in for a sequence |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
35 # of length 200+ |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
36 seq1 = 'b' * 200 |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
37 seq2 = 'a' + 'b' * 200 |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
38 |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
39 sm = difflib.SequenceMatcher(None, seq1, seq2) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
40 self.assertAlmostEqual(sm.ratio(), 0, places=3) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
41 |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
42 # Now turn the heuristic off |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
43 sm = difflib.SequenceMatcher(None, seq1, seq2, autojunk=False) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
44 self.assertAlmostEqual(sm.ratio(), 0.9975, places=3) |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
45 |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
46 |
|
29719
fa4cf878c538
Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents:
24364
diff
changeset
|
47 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
|
48 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
|
49 # 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 |
|
32612
5546c7ae24f7
SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
55 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
|
56 # Check fix for bug #979794 |
|
5546c7ae24f7
SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
57 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
|
58 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
|
59 diff_gen = difflib.unified_diff([], []) |
|
5546c7ae24f7
SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
60 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
|
61 |
|
57415
818cd40df865
Merged revisions 76464 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
37550
diff
changeset
|
62 def test_added_tab_hint(self): |
|
818cd40df865
Merged revisions 76464 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
37550
diff
changeset
|
63 # Check fix for bug #1488943 |
|
818cd40df865
Merged revisions 76464 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
37550
diff
changeset
|
64 diff = list(difflib.Differ().compare(["\tI am a buggy"],["\t\tI am a bug"])) |
|
818cd40df865
Merged revisions 76464 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
37550
diff
changeset
|
65 self.assertEqual("- \tI am a buggy", diff[0]) |
|
818cd40df865
Merged revisions 76464 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
37550
diff
changeset
|
66 self.assertEqual("? --\n", diff[1]) |
|
818cd40df865
Merged revisions 76464 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
37550
diff
changeset
|
67 self.assertEqual("+ \t\tI am a bug", diff[2]) |
|
818cd40df865
Merged revisions 76464 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
37550
diff
changeset
|
68 self.assertEqual("? +\n", diff[3]) |
|
818cd40df865
Merged revisions 76464 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
37550
diff
changeset
|
69 |
|
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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 """ |
|
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 |
|
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 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 """ |
|
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
|
83 |
|
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
|
84 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
|
85 \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
|
86 \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
|
87 \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
|
88 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
|
89 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
|
90 """ |
|
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 |
|
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 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
|
93 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
|
94 \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
|
95 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
|
96 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
|
97 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
|
98 """ |
|
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 |
|
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 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
|
101 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
|
102 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
|
103 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
|
104 line 3 |
|
33326
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
105 line 4 changed |
|
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
106 line 5 changed |
|
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 |
|
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 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
|
118 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
|
119 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
|
120 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
|
121 line 3 |
|
33326
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
122 line 4 chanGEd |
|
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
123 line 5a chanGed |
|
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 |
|
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 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
|
135 |
|
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 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
|
137 # 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 k = difflib.HtmlDiff(wrapcolumn=14) |
|
33326
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
153 |
|
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
|
154 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
|
155 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
|
156 [ |
|
33326
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
157 '<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
|
158 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
|
159 '<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
|
160 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
|
161 '<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
|
162 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
|
163 '<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
|
164 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
|
165 '<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
|
166 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
|
167 '<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
|
168 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
|
169 '<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
|
170 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
|
171 '<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
|
172 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
|
173 '<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
|
174 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
|
175 '<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
|
176 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
|
177 '<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
|
178 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
|
179 '<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
|
180 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
|
181 '<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
|
182 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
|
183 ]) |
|
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
|
184 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
|
185 |
|
54389
70fb848870ac
explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents:
37550
diff
changeset
|
186 # temporarily uncomment next two lines to baseline this test |
|
70fb848870ac
explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents:
37550
diff
changeset
|
187 #with open('test_difflib_expect.html','w') as fp: |
|
70fb848870ac
explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents:
37550
diff
changeset
|
188 # fp.write(actual) |
|
33326
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
189 |
|
54389
70fb848870ac
explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents:
37550
diff
changeset
|
190 with open(findfile('test_difflib_expect.html')) as fp: |
|
70fb848870ac
explicitly close files
Philip Jenvey <pjenvey@underboss.org>
parents:
37550
diff
changeset
|
191 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
|
192 |
|
36429
16bfe9386068
Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
33326
diff
changeset
|
193 def test_recursion_limit(self): |
|
16bfe9386068
Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
33326
diff
changeset
|
194 # 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
|
195 limit = sys.getrecursionlimit() |
|
16bfe9386068
Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
33326
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 |
|
16bfe9386068
Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
33326
diff
changeset
|
200 |
|
60552
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
201 class TestOutputFormat(unittest.TestCase): |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
202 def test_tab_delimiter(self): |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
203 args = ['one', 'two', 'Original', 'Current', |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
204 '2005-01-26 23:30:50', '2010-04-02 10:20:52'] |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
205 ud = difflib.unified_diff(*args, lineterm='') |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
206 self.assertEqual(list(ud)[0:2], [ |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
207 "--- Original\t2005-01-26 23:30:50", |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
208 "+++ Current\t2010-04-02 10:20:52"]) |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
209 cd = difflib.context_diff(*args, lineterm='') |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
210 self.assertEqual(list(cd)[0:2], [ |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
211 "*** Original\t2005-01-26 23:30:50", |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
212 "--- Current\t2010-04-02 10:20:52"]) |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
213 |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
214 def test_no_trailing_tab_on_empty_filedate(self): |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
215 args = ['one', 'two', 'Original', 'Current'] |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
216 ud = difflib.unified_diff(*args, lineterm='') |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
217 self.assertEqual(list(ud)[0:2], ["--- Original", "+++ Current"]) |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
218 |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
219 cd = difflib.context_diff(*args, lineterm='') |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
220 self.assertEqual(list(cd)[0:2], ["*** Original", "--- Current"]) |
|
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
221 |
|
69282
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
222 def test_range_format_unified(self): |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
223 # Per the diff spec at http://www.unix.org/single_unix_specification/ |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
224 spec = '''\ |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
225 Each <range> field shall be of the form: |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
226 %1d", <beginning line number> if the range contains exactly one line, |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
227 and: |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
228 "%1d,%1d", <beginning line number>, <number of lines> otherwise. |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
229 If a range is empty, its beginning line number shall be the number of |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
230 the line just before the range, or 0 if the empty range starts the file. |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
231 ''' |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
232 fmt = difflib._format_range_unified |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
233 self.assertEqual(fmt(3,3), '3,0') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
234 self.assertEqual(fmt(3,4), '4') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
235 self.assertEqual(fmt(3,5), '4,2') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
236 self.assertEqual(fmt(3,6), '4,3') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
237 self.assertEqual(fmt(0,0), '0,0') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
238 |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
239 def test_range_format_context(self): |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
240 # Per the diff spec at http://www.unix.org/single_unix_specification/ |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
241 spec = '''\ |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
242 The range of lines in file1 shall be written in the following format |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
243 if the range contains two or more lines: |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
244 "*** %d,%d ****\n", <beginning line number>, <ending line number> |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
245 and the following format otherwise: |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
246 "*** %d ****\n", <ending line number> |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
247 The ending line number of an empty range shall be the number of the preceding line, |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
248 or 0 if the range is at the start of the file. |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
249 |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
250 Next, the range of lines in file2 shall be written in the following format |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
251 if the range contains two or more lines: |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
252 "--- %d,%d ----\n", <beginning line number>, <ending line number> |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
253 and the following format otherwise: |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
254 "--- %d ----\n", <ending line number> |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
255 ''' |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
256 fmt = difflib._format_range_context |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
257 self.assertEqual(fmt(3,3), '3') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
258 self.assertEqual(fmt(3,4), '4') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
259 self.assertEqual(fmt(3,5), '4,5') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
260 self.assertEqual(fmt(3,6), '4,6') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
261 self.assertEqual(fmt(0,0), '0') |
|
09459397f807
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
68256
diff
changeset
|
262 |
|
60552
713f1f6bf339
Issue #7585: use tab between components in unified and context diff headers.
R. David Murray <rdmurray@bitdance.com>
parents:
57411
diff
changeset
|
263 |
|
37550
0342c5f0f4ff
Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents:
36429
diff
changeset
|
264 def test_main(): |
|
0342c5f0f4ff
Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents:
36429
diff
changeset
|
265 difflib.HtmlDiff._default_prefix = 0 |
|
0342c5f0f4ff
Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents:
36429
diff
changeset
|
266 Doctests = doctest.DocTestSuite(difflib) |
|
66156
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
267 run_unittest( |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
268 TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs, |
|
1a65290e6d03
#2986 Add autojunk parameter to SequenceMatcher to optionally disable 'popular == junk' heuristic.
Terry Reedy <tjreedy@udel.edu>
parents:
60552
diff
changeset
|
269 TestOutputFormat, Doctests) |
|
29892
79ec7e302d53
Exercise Jim Fulton's new doctest extension for running doctests in a
Raymond Hettinger <python@rcn.com>
parents:
29719
diff
changeset
|
270 |
|
37550
0342c5f0f4ff
Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents:
36429
diff
changeset
|
271 if __name__ == '__main__': |
|
0342c5f0f4ff
Fix tests so they pass in -R mode
Neal Norwitz <nnorwitz@gmail.com>
parents:
36429
diff
changeset
|
272 test_main() |
