import difflibfrom test.test_support import run_unittest, findfileimport unittestimport doctestimport sysclass TestSFbugs(unittest.TestCase):def test_ratio_for_null_seqn(self):# Check clearing of SF bug 763023s = 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 #979794group_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_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 01234567890123456789012345689012345line 1line 2line 3line 4 changedline 5 changedline 6 changedline 7line 8 subtractedline 91234567890123456789012345689012345short linejust fits in!!just fits in two lines yup!!the end"""patch914575_to3 = """line 01234567890123456789012345689012345line 1line 2 addedline 3line 4 chanGEdline 5a chanGedline 6a changEdline 7line 8line 91234567890another long line that needs to be wrappedjust 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 differencesf1a = ((patch914575_from1 + '123\n'*10)*3)t1a = (patch914575_to1 + '123\n'*10)*3f1b = '456\n'*10 + f1at1b = '456\n'*10 + t1af1a = f1a.splitlines()t1a = t1a.splitlines()f1b = f1b.splitlines()t1b = t1b.splitlines()f2 = patch914575_from2.splitlines()t2 = patch914575_to2.splitlines()f3 = patch914575_from3t3 = patch914575_to3i = 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)def test_recursion_limit(self):# Check if the problem described in patch #1413711 exists.limit = sys.getrecursionlimit()old = [(i%2 and "K:%d" or "V:A:%d") % i for i in range(limit*2)]new = [(i%2 and "K:%d" or "V:B:%d") % i for i in range(limit*2)]difflib.SequenceMatcher(None, old, new).get_opcodes()def test_main():difflib.HtmlDiff._default_prefix = 0Doctests = doctest.DocTestSuite(difflib)run_unittest(TestSFpatches, TestSFbugs, Doctests)if __name__ == '__main__':test_main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。