Skip to content

Commit 0e1bda0

Browse files
committed
Adding diff capability to the URL tests.
If you list a second url or file on a line in an urltest.list file, the second url will be downloaded, both urls will be converted to text, and then compared. If there are differences, a unified diff will be output. - Legacy-Id: 278
1 parent 10ce0e0 commit 0e1bda0

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

ietf/tests.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import os
22
import re
3+
import sys
34
import traceback
5+
import urllib2 as urllib
6+
7+
from ietf.utils import soup2text as html2text
8+
from difflib import unified_diff
9+
import textwrap
410

511
import django.test.simple
612
from django.test import TestCase
@@ -18,6 +24,16 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
1824
# during the search for a 'tests' module ...
1925
return django.test.simple.run_tests(module_list, verbosity, extra_tests)
2026

27+
def reduce(html):
28+
html = re.sub(" :", ":", html)
29+
text = html2text(html)
30+
text = re.sub('\."', '".', text)
31+
#text = re.sub("\n\n+", "\n\n", text)
32+
#text = "\n\n".join([textwrap.fill(para, 80) for para in text.split("\n\n")])
33+
#text = re.sub(" +", " ", text)
34+
text = [ line.strip() for line in text.split("\n") ]
35+
return text
36+
2137
def get_patterns(module):
2238
all = []
2339
try:
@@ -113,6 +129,22 @@ def doUrlsTest(self, lst):
113129
res = ("Fail", "Exc")
114130
print "Exception for URL '%s'" % url
115131
traceback.print_exc()
132+
if master:
133+
try:
134+
print "Fetching", master, "...",
135+
mfile = urllib.urlopen(master)
136+
goodhtml = mfile.read()
137+
mfile.close()
138+
print ""
139+
if goodhtml and response.content:
140+
testtext = reduce(response.content)
141+
goodtext = reduce(goodhtml)
142+
if not testtext == goodtext:
143+
for line in unified_diff(goodtext, testtext, url, master, lineterm=False):
144+
print line
145+
except urllib.URLError, e:
146+
print "Failed retrieving master text for comparison: %s" % e
147+
116148
if not res in response_count:
117149
response_count[res] = 0
118150
response_count[res] += 1
@@ -131,7 +163,7 @@ def testUrlsList(self):
131163
print "\nTesting specified URLs:"
132164
self.doUrlsTest(self.testtuples)
133165

134-
def testUrlsFallback(self):
166+
def XtestUrlsFallback(self):
135167
patterns = get_patterns(ietf.urls)
136168
lst = []
137169
for pattern in patterns:

0 commit comments

Comments
 (0)