Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_difflib.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 8733fa6d3cfa |
| 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 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
41501
diff
changeset
|
2 from 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 |
|
66440
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
7 |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
8 class TestWithAscii(unittest.TestCase): |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
9 def test_one_insert(self): |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
10 sm = difflib.SequenceMatcher(None, 'b' * 100, 'a' + 'b' * 100) |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
11 self.assertAlmostEqual(sm.ratio(), 0.995, places=3) |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
12 self.assertEqual(list(sm.get_opcodes()), |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
13 [ ('insert', 0, 0, 0, 1), |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
14 ('equal', 0, 100, 1, 101)]) |
|
66931
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
15 self.assertEqual(sm.bpopular, set()) |
|
66440
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
16 sm = difflib.SequenceMatcher(None, 'b' * 100, 'b' * 50 + 'a' + 'b' * 50) |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
17 self.assertAlmostEqual(sm.ratio(), 0.995, places=3) |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
18 self.assertEqual(list(sm.get_opcodes()), |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
19 [ ('equal', 0, 50, 0, 50), |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
20 ('insert', 50, 50, 50, 51), |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
21 ('equal', 50, 100, 51, 101)]) |
|
66931
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
22 self.assertEqual(sm.bpopular, set()) |
|
66440
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
23 |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
24 def test_one_delete(self): |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
25 sm = difflib.SequenceMatcher(None, 'a' * 40 + 'c' + 'b' * 40, 'a' * 40 + 'b' * 40) |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
26 self.assertAlmostEqual(sm.ratio(), 0.994, places=3) |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
27 self.assertEqual(list(sm.get_opcodes()), |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
28 [ ('equal', 0, 40, 0, 40), |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
29 ('delete', 40, 41, 40, 40), |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
30 ('equal', 41, 81, 40, 80)]) |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
31 |
|
66931
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
32 def test_bjunk(self): |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
33 sm = difflib.SequenceMatcher(isjunk=lambda x: x == ' ', |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
34 a='a' * 40 + 'b' * 40, b='a' * 44 + 'b' * 40) |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
35 self.assertEqual(sm.bjunk, set()) |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
36 |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
37 sm = difflib.SequenceMatcher(isjunk=lambda x: x == ' ', |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
38 a='a' * 40 + 'b' * 40, b='a' * 44 + 'b' * 40 + ' ' * 20) |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
39 self.assertEqual(sm.bjunk, {' '}) |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
40 |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
41 sm = difflib.SequenceMatcher(isjunk=lambda x: x in [' ', 'b'], |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
42 a='a' * 40 + 'b' * 40, b='a' * 44 + 'b' * 40 + ' ' * 20) |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
43 self.assertEqual(sm.bjunk, {' ', 'b'}) |
|
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
44 |
|
66440
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
45 |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
46 class TestAutojunk(unittest.TestCase): |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
47 """Tests for the autojunk parameter added in 2.7""" |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
48 def test_one_insert_homogenous_sequence(self): |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
49 # By default autojunk=True and the heuristic kicks in for a sequence |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
50 # of length 200+ |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
51 seq1 = 'b' * 200 |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
52 seq2 = 'a' + 'b' * 200 |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
53 |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
54 sm = difflib.SequenceMatcher(None, seq1, seq2) |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
55 self.assertAlmostEqual(sm.ratio(), 0, places=3) |
|
66931
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
56 self.assertEqual(sm.bpopular, {'b'}) |
|
66440
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
57 |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
58 # Now turn the heuristic off |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
59 sm = difflib.SequenceMatcher(None, seq1, seq2, autojunk=False) |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
60 self.assertAlmostEqual(sm.ratio(), 0.9975, places=3) |
|
66931
9a2e56d1146d
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Terry Reedy <tjreedy@udel.edu>
parents:
66440
diff
changeset
|
61 self.assertEqual(sm.bpopular, set()) |
|
66440
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
62 |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
63 |
|
29719
fa4cf878c538
Fix SF bug #763023, difflib.py: ratio() zero division not caught
Neal Norwitz <nnorwitz@gmail.com>
parents:
24364
diff
changeset
|
64 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
|
65 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
|
66 # 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 |
|
32612
5546c7ae24f7
SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
72 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
|
73 # Check fix for bug #979794 |
|
5546c7ae24f7
SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
74 group_gen = difflib.SequenceMatcher(None, [], []).get_grouped_opcodes() |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
37879
diff
changeset
|
75 self.assertRaises(StopIteration, next, group_gen) |
|
32612
5546c7ae24f7
SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
76 diff_gen = difflib.unified_diff([], []) |
|
41501
0c5019afc55b
PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents:
37879
diff
changeset
|
77 self.assertRaises(StopIteration, next, diff_gen) |
|
32612
5546c7ae24f7
SequenceMatcher(None, [], []).get_grouped_opcodes() now returns a generator
Brett Cannon <bcannon@gmail.com>
parents:
31389
diff
changeset
|
78 |
|
57417
3a2b149ae66e
Merged revisions 76469 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
54390
diff
changeset
|
79 def test_added_tab_hint(self): |
|
3a2b149ae66e
Merged revisions 76469 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
54390
diff
changeset
|
80 # Check fix for bug #1488943 |
|
3a2b149ae66e
Merged revisions 76469 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
54390
diff
changeset
|
81 diff = list(difflib.Differ().compare(["\tI am a buggy"],["\t\tI am a bug"])) |
|
3a2b149ae66e
Merged revisions 76469 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
54390
diff
changeset
|
82 self.assertEqual("- \tI am a buggy", diff[0]) |
|
3a2b149ae66e
Merged revisions 76469 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
54390
diff
changeset
|
83 self.assertEqual("? --\n", diff[1]) |
|
3a2b149ae66e
Merged revisions 76469 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
54390
diff
changeset
|
84 self.assertEqual("+ \t\tI am a bug", diff[2]) |
|
3a2b149ae66e
Merged revisions 76469 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
54390
diff
changeset
|
85 self.assertEqual("? +\n", diff[3]) |
|
3a2b149ae66e
Merged revisions 76469 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
54390
diff
changeset
|
86 |
|
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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 """ |
|
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 |
|
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 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
|
95 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
|
96 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
|
97 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
|
98 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
|
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 |
|
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 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
|
102 \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
|
103 \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
|
104 \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
|
105 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
|
106 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
|
107 """ |
|
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 |
|
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 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
|
110 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
|
111 \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
|
112 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
|
113 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
|
114 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
|
115 """ |
|
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_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
|
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 |
|
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 5 changed |
|
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
124 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
|
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 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
|
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 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
|
129 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
|
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 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
|
135 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
|
136 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
|
137 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
|
138 line 3 |
|
33326
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
139 line 4 chanGEd |
|
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
140 line 5a chanGed |
|
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 |
|
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 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
|
152 |
|
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 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
|
154 # 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 k = difflib.HtmlDiff(wrapcolumn=14) |
|
33326
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
170 |
|
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
|
171 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
|
172 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
|
173 [ |
|
33326
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
174 '<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
|
175 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
|
176 '<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
|
177 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
|
178 '<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
|
179 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
|
180 '<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
|
181 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
|
182 '<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
|
183 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
|
184 '<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
|
185 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
|
186 '<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
|
187 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
|
188 '<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
|
189 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
|
190 '<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
|
191 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
|
192 '<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
|
193 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
|
194 '<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
|
195 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
|
196 '<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
|
197 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
|
198 '<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
|
199 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
|
200 ]) |
|
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
|
201 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
|
202 |
|
54390
a6b73d80fbe2
Merged revisions 72979 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents:
47201
diff
changeset
|
203 # temporarily uncomment next two lines to baseline this test |
|
a6b73d80fbe2
Merged revisions 72979 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents:
47201
diff
changeset
|
204 #with open('test_difflib_expect.html','w') as fp: |
|
a6b73d80fbe2
Merged revisions 72979 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents:
47201
diff
changeset
|
205 # fp.write(actual) |
|
33326
787fff51bf2a
Whitespace normalization. test_difflib passes again.
Tim Peters <tim.peters@gmail.com>
parents:
33324
diff
changeset
|
206 |
|
54390
a6b73d80fbe2
Merged revisions 72979 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents:
47201
diff
changeset
|
207 with open(findfile('test_difflib_expect.html')) as fp: |
|
a6b73d80fbe2
Merged revisions 72979 via svnmerge from
Philip Jenvey <pjenvey@underboss.org>
parents:
47201
diff
changeset
|
208 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
|
209 |
|
36429
16bfe9386068
Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
33326
diff
changeset
|
210 def test_recursion_limit(self): |
|
16bfe9386068
Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
33326
diff
changeset
|
211 # 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
|
212 limit = sys.getrecursionlimit() |
|
16bfe9386068
Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
33326
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 |
|
16bfe9386068
Patch #1413711: Certain patterns of differences were making difflib
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
33326
diff
changeset
|
217 |
|
69277
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
218 class TestOutputFormat(unittest.TestCase): |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
219 def test_tab_delimiter(self): |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
220 args = ['one', 'two', 'Original', 'Current', |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
221 '2005-01-26 23:30:50', '2010-04-02 10:20:52'] |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
222 ud = difflib.unified_diff(*args, lineterm='') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
223 self.assertEqual(list(ud)[0:2], [ |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
224 "--- Original\t2005-01-26 23:30:50", |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
225 "+++ Current\t2010-04-02 10:20:52"]) |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
226 cd = difflib.context_diff(*args, lineterm='') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
227 self.assertEqual(list(cd)[0:2], [ |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
228 "*** Original\t2005-01-26 23:30:50", |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
229 "--- Current\t2010-04-02 10:20:52"]) |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
230 |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
231 def test_no_trailing_tab_on_empty_filedate(self): |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
232 args = ['one', 'two', 'Original', 'Current'] |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
233 ud = difflib.unified_diff(*args, lineterm='') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
234 self.assertEqual(list(ud)[0:2], ["--- Original", "+++ Current"]) |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
235 |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
236 cd = difflib.context_diff(*args, lineterm='') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
237 self.assertEqual(list(cd)[0:2], ["*** Original", "--- Current"]) |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
238 |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
239 def test_range_format_unified(self): |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
240 # Per the diff spec at http://www.unix.org/single_unix_specification/ |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
241 spec = '''\ |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
242 Each <range> field shall be of the form: |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
243 %1d", <beginning line number> if the range contains exactly one line, |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
244 and: |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
245 "%1d,%1d", <beginning line number>, <number of lines> otherwise. |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
246 If a range is empty, its beginning line number shall be the number of |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
247 the line just before the range, or 0 if the empty range starts the file. |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
248 ''' |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
249 fmt = difflib._format_range_unified |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
250 self.assertEqual(fmt(3,3), '3,0') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
251 self.assertEqual(fmt(3,4), '4') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
252 self.assertEqual(fmt(3,5), '4,2') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
253 self.assertEqual(fmt(3,6), '4,3') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
254 self.assertEqual(fmt(0,0), '0,0') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
255 |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
256 def test_range_format_context(self): |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
257 # Per the diff spec at http://www.unix.org/single_unix_specification/ |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
258 spec = '''\ |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
259 The range of lines in file1 shall be written in the following format |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
260 if the range contains two or more lines: |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
261 "*** %d,%d ****\n", <beginning line number>, <ending line number> |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
262 and the following format otherwise: |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
263 "*** %d ****\n", <ending line number> |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
264 The ending line number of an empty range shall be the number of the preceding line, |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
265 or 0 if the range is at the start of the file. |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
266 |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
267 Next, the range of lines in file2 shall be written in the following format |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
268 if the range contains two or more lines: |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
269 "--- %d,%d ----\n", <beginning line number>, <ending line number> |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
270 and the following format otherwise: |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
271 "--- %d ----\n", <ending line number> |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
272 ''' |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
273 fmt = difflib._format_range_context |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
274 self.assertEqual(fmt(3,3), '3') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
275 self.assertEqual(fmt(3,4), '4') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
276 self.assertEqual(fmt(3,5), '4,5') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
277 self.assertEqual(fmt(3,6), '4,6') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
278 self.assertEqual(fmt(0,0), '0') |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
279 |
|
707078ca0a77
Issue 11747: Fix output format for context diffs.
Raymond Hettinger <python@rcn.com>
parents:
57417
diff
changeset
|
280 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36429
diff
changeset
|
281 def test_main(): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36429
diff
changeset
|
282 difflib.HtmlDiff._default_prefix = 0 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36429
diff
changeset
|
283 Doctests = doctest.DocTestSuite(difflib) |
|
66440
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
284 run_unittest( |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
285 TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs, |
|
c54c411d3da7
Issue 2986: Add autojunk paramater to SequenceMatcher to turn off heuristic. Patch by Terry Reedy, Eli Bendersky, and Simon Cross
Terry Reedy <tjreedy@udel.edu>
parents:
60554
diff
changeset
|
286 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
|
287 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36429
diff
changeset
|
288 if __name__ == '__main__': |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36429
diff
changeset
|
289 test_main() |
