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 = '''
| 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. | |||
| 6 | 123 | 6 | 123 | |
| 7 | 123 | 7 | 123 | |
| 8 | 123 | 8 | 123 | |
| 9 | 123 | 9 | 123 | |
| 10 | 123 | 10 | 123 | |
| 11 | 123 | 11 | 123 | |
| 12 | 123 | 12 | 123 | |
| 13 | 123 | 13 | 123 | |
| 14 | 123 | 14 | 123 | |
| 15 | 123 | 15 | 123 | |
| 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. | |||
| 21 | 123 | 21 | 123 | |
| 22 | 123 | 22 | 123 | |
| 23 | 123 | 23 | 123 | |
| 24 | 123 | 24 | 123 | |
| 25 | 123 | 25 | 123 | |
| 26 | 123 | 26 | 123 | |
| 27 | 123 | 27 | 123 | |
| 28 | 123 | 28 | 123 | |
| 29 | 123 | 29 | 123 | |
| 30 | 123 | 30 | 123 | |
| 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. | |||
| 36 | 123 | 36 | 123 | |
| 37 | 123 | 37 | 123 | |
| 38 | 123 | 38 | 123 | |
| 39 | 123 | 39 | 123 | |
| 40 | 123 | 40 | 123 | |
| 41 | 123 | 41 | 123 | |
| 42 | 123 | 42 | 123 | |
| 43 | 123 | 43 | 123 | |
| 44 | 123 | 44 | 123 | |
| 45 | 123 | 45 | 123 | |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| 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. | |||
| 6 | 123 | 6 | 123 | |
| 7 | 123 | 7 | 123 | |
| 8 | 123 | 8 | 123 | |
| 9 | 123 | 9 | 123 | |
| 14 | 123 | 14 | 123 | |
| 15 | 123 | 15 | 123 | |
| 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. | |||
| 21 | 123 | 21 | 123 | |
| 22 | 123 | 22 | 123 | |
| 23 | 123 | 23 | 123 | |
| 24 | 123 | 24 | 123 | |
| 29 | 123 | 29 | 123 | |
| 30 | 123 | 30 | 123 | |
| 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. | |||
| 36 | 123 | 36 | 123 | |
| 37 | 123 | 37 | 123 | |
| 38 | 123 | 38 | 123 | |
| 39 | 123 | 39 | 123 | |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||