MCPcopy Index your code
hub / github.com/python/cpython / test_html_diff

Method test_html_diff

Lib/test/test_difflib.py:200–255  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

198class TestSFpatches(unittest.TestCase):
199
200 def test_html_diff(self):
201 # Check SF patch 914575 for generating HTML differences
202 f1a = ((patch914575_from1 + '123\n'*10)*3)
203 t1a = (patch914575_to1 + '123\n'*10)*3
204 f1b = '456\n'*10 + f1a
205 t1b = '456\n'*10 + t1a
206 f1a = f1a.splitlines()
207 t1a = t1a.splitlines()
208 f1b = f1b.splitlines()
209 t1b = t1b.splitlines()
210 f2 = patch914575_from2.splitlines()
211 t2 = patch914575_to2.splitlines()
212 f3 = patch914575_from3
213 t3 = patch914575_to3
214 i = difflib.HtmlDiff()
215 j = difflib.HtmlDiff(tabsize=2)
216 k = difflib.HtmlDiff(wrapcolumn=14)
217
218 full = i.make_file(f1a,t1a,'from','to',context=False,numlines=5)
219 tables = '\n'.join(
220 [
221 '<h2>Context (first diff within numlines=5(default))</h2>',
222 i.make_table(f1a,t1a,'from','to',context=True),
223 '<h2>Context (first diff after numlines=5(default))</h2>',
224 i.make_table(f1b,t1b,'from','to',context=True),
225 '<h2>Context (numlines=6)</h2>',
226 i.make_table(f1a,t1a,'from','to',context=True,numlines=6),
227 '<h2>Context (numlines=0)</h2>',
228 i.make_table(f1a,t1a,'from','to',context=True,numlines=0),
229 '<h2>Same Context</h2>',
230 i.make_table(f1a,f1a,'from','to',context=True),
231 '<h2>Same Full</h2>',
232 i.make_table(f1a,f1a,'from','to',context=False),
233 '<h2>Empty Context</h2>',
234 i.make_table([],[],'from','to',context=True),
235 '<h2>Empty Full</h2>',
236 i.make_table([],[],'from','to',context=False),
237 '<h2>tabsize=2</h2>',
238 j.make_table(f2,t2),
239 '<h2>tabsize=default</h2>',
240 i.make_table(f2,t2),
241 '<h2>Context (wrapcolumn=14,numlines=0)</h2>',
242 k.make_table(f3.splitlines(),t3.splitlines(),context=True,numlines=0),
243 '<h2>wrapcolumn=14,splitlines()</h2>',
244 k.make_table(f3.splitlines(),t3.splitlines()),
245 '<h2>wrapcolumn=14,splitlines(True)</h2>',
246 k.make_table(f3.splitlines(True),t3.splitlines(True)),
247 ])
248 actual = full.replace('</body>','\n%s\n</body>' % tables)
249
250 # temporarily uncomment next two lines to baseline this test
251 #with open('test_difflib_expect.html','w') as fp:
252 # fp.write(actual)
253
254 with open(findfile('test_difflib_expect.html'), encoding="utf-8") as fp:
255 self.assertEqual(actual, fp.read())
256
257 def test_recursion_limit(self):

Callers

nothing calls this directly

Calls 9

make_fileMethod · 0.95
make_tableMethod · 0.95
findfileFunction · 0.90
openFunction · 0.50
splitlinesMethod · 0.45
joinMethod · 0.45
replaceMethod · 0.45
assertEqualMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected