import difflib from test import test_support import unittest import doctest class TestSFbugs(unittest.TestCase): def test_ratio_for_null_seqn(self): # Check clearing of SF bug 763023 s = difflib.SequenceMatcher(None, [], []) self.assertEqual(s.ratio(), 1) self.assertEqual(s.quick_ratio(), 1) self.assertEqual(s.real_quick_ratio(), 1) def test_comparing_empty_lists(self): # Check fix for bug #979794 group_gen = difflib.SequenceMatcher(None, [], []).get_grouped_opcodes() self.assertRaises(StopIteration, group_gen.next) diff_gen = difflib.unified_diff([], []) self.assertRaises(StopIteration, diff_gen.next) patch914575_from = ''' 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_to = ''' 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_full_expectation = ''' Full Side by Side Difference

full

from
to
1 f 1
2   1. Beautiful is beTTer than ugly. n 2   1. Beautiful is better than ugly.
3   2. Explicit is better than implicit.
4   3. Simple is better than complex. 3   3.   Simple is better than complex.
5   4. Complex is better than complicated. 4   4. Complicated is better than complex.
5   5. Flat is better than nested.
6123 6123
7123 7123
8123 8123
9123 9123
10123 10123
11123 11123
12123 12123
13123 13123
14123 14123
15123 15123
16 16
17   1. Beautiful is beTTer than ugly. n 17   1. Beautiful is better than ugly.
18   2. Explicit is better than implicit.
19   3. Simple is better than complex. 18   3.   Simple is better than complex.
20   4. Complex is better than complicated. 19   4. Complicated is better than complex.
20   5. Flat is better than nested.
21123 21123
22123 22123
23123 23123
24123 24123
25123 25123
26123 26123
27123 27123
28123 28123
29123 29123
30123 30123
31 31
32   1. Beautiful is beTTer than ugly. t 32   1. Beautiful is better than ugly.
33   2. Explicit is better than implicit.
34   3. Simple is better than complex. 33   3.   Simple is better than complex.
35   4. Complex is better than complicated. 34   4. Complicated is better than complex.
35   5. Flat is better than nested.
36123 36123
37123 37123
38123 38123
39123 39123
40123 40123
41123 41123
42123 42123
43123 43123
44123 44123
45123 45123
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op
''' patch914575_context_expectation = ''' Context Side by Side Difference

context

from
to
1 f 1
2   1. Beautiful is beTTer than ugly. n 2   1. Beautiful is better than ugly.
3   2. Explicit is better than implicit.
4   3. Simple is better than complex. 3   3.   Simple is better than complex.
5   4. Complex is better than complicated. 4   4. Complicated is better than complex.
5   5. Flat is better than nested.
6123 6123
7123 7123
8123 8123
9123 9123
14123 14123
15123 15123
16 16
17   1. Beautiful is beTTer than ugly. n 17   1. Beautiful is better than ugly.
18   2. Explicit is better than implicit.
19   3. Simple is better than complex. 18   3.   Simple is better than complex.
20   4. Complex is better than complicated. 19   4. Complicated is better than complex.
20   5. Flat is better than nested.
21123 21123
22123 22123
23123 23123
24123 24123
29123 29123
30123 30123
31 31
32   1. Beautiful is beTTer than ugly. t 32   1. Beautiful is better than ugly.
33   2. Explicit is better than implicit.
34   3. Simple is better than complex. 33   3.   Simple is better than complex.
35   4. Complex is better than complicated. 34   4. Complicated is better than complex.
35   5. Flat is better than nested.
36123 36123
37123 37123
38123 38123
39123 39123
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op
''' class TestSFpatches(unittest.TestCase): def test_html_diff(self): # Check SF patch 914575 for generating HTML differences a = patch914575_from + '123\n'*10 a = a * 3 a = a.splitlines(1) b = patch914575_to + '123\n'*10 b = b * 3 b = b.splitlines(1) i = difflib.HtmlDiff(prefix=['from1_','to1_']) full = i.make_file(a,b,'from','to',context=False, numlines=5,title='Full Side by Side Difference',header='

full

',summary='s_full') context = i.make_file(a,b,'from','to',context=True, numlines=3,title='Context Side by Side Difference',header='

context

',summary='s_context') # Save following two lines for baselining test #open('full.html','w').write(full) #open('context.html','w').write(context) self.assertEqual(patch914575_full_expectation,full) self.assertEqual(patch914575_context_expectation,context) Doctests = doctest.DocTestSuite(difflib) test_support.run_unittest(TestSFpatches, TestSFbugs, Doctests)