diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2004-08-29 16:34:40 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2004-08-29 16:34:40 (GMT) |
commit | e064b41f5ac046fc361fa80af551f5bfab01141c (patch) | |
tree | 803e0b0152e38d58174856dcc1bc3754b2229b2c /Lib/test/test_difflib.py | |
parent | 87fa785f0f8ce187db2bd55871dc18fd57bc9f4e (diff) | |
download | cpython-e064b41f5ac046fc361fa80af551f5bfab01141c.zip cpython-e064b41f5ac046fc361fa80af551f5bfab01141c.tar.gz cpython-e064b41f5ac046fc361fa80af551f5bfab01141c.tar.bz2 |
Patch #914575: difflib side by side diff support, diff.py s/b/s HTML option.
Diffstat (limited to 'Lib/test/test_difflib.py')
-rw-r--r-- | Lib/test/test_difflib.py | 128 |
1 files changed, 126 insertions, 2 deletions
diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py index 9819c84..37fc548 100644 --- a/Lib/test/test_difflib.py +++ b/Lib/test/test_difflib.py @@ -1,5 +1,5 @@ import difflib -from test import test_support +from test.test_support import run_unittest, findfile import unittest import doctest @@ -19,6 +19,130 @@ class TestSFbugs(unittest.TestCase): diff_gen = difflib.unified_diff([], []) self.assertRaises(StopIteration, diff_gen.next) +patch914575_from1 = """ + 1. Beautiful is beTTer than ugly. + 2. Explicit is better than implicit. + 3. Simple is better than complex. + 4. Complex is better than complicated. +""" + +patch914575_to1 = """ + 1. Beautiful is better than ugly. + 3. Simple is better than complex. + 4. Complicated is better than complex. + 5. Flat is better than nested. +""" + +patch914575_from2 = """ +\t\tLine 1: preceeded by from:[tt] to:[ssss] + \t\tLine 2: preceeded by from:[sstt] to:[sssst] + \t \tLine 3: preceeded by from:[sstst] to:[ssssss] +Line 4: \thas from:[sst] to:[sss] after : +Line 5: has from:[t] to:[ss] at end\t +""" + +patch914575_to2 = """ + Line 1: preceeded by from:[tt] to:[ssss] + \tLine 2: preceeded by from:[sstt] to:[sssst] + Line 3: preceeded by from:[sstst] to:[ssssss] +Line 4: has from:[sst] to:[sss] after : +Line 5: has from:[t] to:[ss] at end +""" + +patch914575_from3 = """line 0 +1234567890123456789012345689012345 +line 1 +line 2 +line 3 +line 4 changed +line 5 changed +line 6 changed +line 7 +line 8 subtracted +line 9 +1234567890123456789012345689012345 +short line +just fits in!! +just fits in two lines yup!! +the end""" + +patch914575_to3 = """line 0 +1234567890123456789012345689012345 +line 1 +line 2 added +line 3 +line 4 chanGEd +line 5a chanGed +line 6a changEd +line 7 +line 8 +line 9 +1234567890 +another long line that needs to be wrapped +just fitS in!! +just fits in two lineS yup!! +the end""" + +class TestSFpatches(unittest.TestCase): + + def test_html_diff(self): + # Check SF patch 914575 for generating HTML differences + f1a = ((patch914575_from1 + '123\n'*10)*3) + t1a = (patch914575_to1 + '123\n'*10)*3 + f1b = '456\n'*10 + f1a + t1b = '456\n'*10 + t1a + f1a = f1a.splitlines() + t1a = t1a.splitlines() + f1b = f1b.splitlines() + t1b = t1b.splitlines() + f2 = patch914575_from2.splitlines() + t2 = patch914575_to2.splitlines() + f3 = patch914575_from3 + t3 = patch914575_to3 + i = difflib.HtmlDiff() + j = difflib.HtmlDiff(tabsize=2) + k = difflib.HtmlDiff(wrapcolumn=14) + + full = i.make_file(f1a,t1a,'from','to',context=False,numlines=5) + tables = '\n'.join( + [ + '<h2>Context (first diff within numlines=5(default))</h2>', + i.make_table(f1a,t1a,'from','to',context=True), + '<h2>Context (first diff after numlines=5(default))</h2>', + i.make_table(f1b,t1b,'from','to',context=True), + '<h2>Context (numlines=6)</h2>', + i.make_table(f1a,t1a,'from','to',context=True,numlines=6), + '<h2>Context (numlines=0)</h2>', + i.make_table(f1a,t1a,'from','to',context=True,numlines=0), + '<h2>Same Context</h2>', + i.make_table(f1a,f1a,'from','to',context=True), + '<h2>Same Full</h2>', + i.make_table(f1a,f1a,'from','to',context=False), + '<h2>Empty Context</h2>', + i.make_table([],[],'from','to',context=True), + '<h2>Empty Full</h2>', + i.make_table([],[],'from','to',context=False), + '<h2>tabsize=2</h2>', + j.make_table(f2,t2), + '<h2>tabsize=default</h2>', + i.make_table(f2,t2), + '<h2>Context (wrapcolumn=14,numlines=0)</h2>', + k.make_table(f3.splitlines(),t3.splitlines(),context=True,numlines=0), + '<h2>wrapcolumn=14,splitlines()</h2>', + k.make_table(f3.splitlines(),t3.splitlines()), + '<h2>wrapcolumn=14,splitlines(True)</h2>', + k.make_table(f3.splitlines(True),t3.splitlines(True)), + ]) + actual = full.replace('</body>','\n%s\n</body>' % tables) + # temporarily uncomment next three lines to baseline this test + #f = open('test_difflib_expect.html','w') + #f.write(actual) + #f.close() + expect = open(findfile('test_difflib_expect.html')).read() + + + self.assertEqual(actual,expect) + Doctests = doctest.DocTestSuite(difflib) -test_support.run_unittest(TestSFbugs, Doctests) +run_unittest(TestSFpatches, TestSFbugs, Doctests) |