Skip to content

Commit 0452fca

Browse files
committed
* ietf/tests.py, in reduce(): add ad-hoc fix for pathologic case of not
closing <li> tags. BeautifulSoup can handle it, but the recursive text rendering code in soup2text recurses too deeply with a sufficiently long list... * ietf/tests.py, in setUp(): grab the right tuple element when extracting the URLs from the url test tuples * ietf/tests.py, in read_testurls(): close opened file * ietf/tests.py, in doUrlsTest(): narrower try/except clause, and a new one * soup2text.py, in para(): undo previous change - Legacy-Id: 304
1 parent b42e072 commit 0452fca

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

ietf/tests.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
2323

2424
def reduce(html):
2525
html = re.sub(" :", ":", html)
26+
if html.count("<li>") > 5*html.count("</li>"):
27+
html = html.replace("<li>", "</li><li>")
2628
text = html2text(html)
2729
text = re.sub('\."', '".', text)
28-
#text = re.sub("\n\n+", "\n\n", text)
29-
#text = "\n\n".join([textwrap.fill(para, 80) for para in text.split("\n\n")])
30-
#text = re.sub(" +", " ", text)
3130
text = [ line.strip() for line in text.split("\n") ]
3231
return text
3332

@@ -68,6 +67,7 @@ def read_testurls(filename):
6867
raise ValueError("Expected 'HTTP_CODE TESTURL [GOODURL]' in %s line, found '%s'." % (filename, line))
6968
codes = codes.split(",")
7069
tuples += [ (codes, testurl, goodurl) ]
70+
file.close()
7171
return tuples
7272

7373
class UrlTestCase(TestCase):
@@ -83,7 +83,7 @@ def setUp(self):
8383
self.testtuples += read_testurls(root+"/testurl.list")
8484
if "testurls.list" in files:
8585
self.testtuples += read_testurls(root+"/testurls.list")
86-
self.testurls = [ tuple[0] for tuple in self.testtuples ]
86+
self.testurls = [ tuple[1] for tuple in self.testtuples ]
8787
# Use the default database for the url tests, instead of the test database
8888
self.testdb = settings.DATABASE_NAME
8989
connection.close()
@@ -136,8 +136,10 @@ def doUrlsTest(self, lst):
136136
#print "Fetching", master, "...",
137137
mfile = urllib.urlopen(master)
138138
goodhtml = mfile.read()
139+
except urllib.URLError, e:
140+
print "Failed retrieving master text for comparison: %s" % e
141+
try:
139142
mfile.close()
140-
print ""
141143
if goodhtml and response.content:
142144
testtext = reduce(response.content)
143145
goodtext = reduce(goodhtml)
@@ -158,8 +160,9 @@ def doUrlsTest(self, lst):
158160
else:
159161
print "Diff: %s" % (url)
160162
print diff
161-
except urllib.URLError, e:
162-
print "Failed retrieving master text for comparison: %s" % e
163+
except:
164+
print "Exception occurred for url %s" % (url)
165+
raise
163166

164167
if not res in response_count:
165168
response_count[res] = 0

ietf/utils/soup2text.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ def para(words, pre):
2727
text = text.replace(entity, char)
2828
if not pre:
2929
text = re.sub("[\r\n\t ]+", " ", text)
30-
try: # On OS-X / Python 2.5 textwrap can throw a runtime error
31-
text = textwrap.fill(text)
32-
except RuntimeError:
33-
pass
30+
text = textwrap.fill(text)
3431
return text
3532

3633
def render(node, encoding='latin-1', pre=False):

0 commit comments

Comments
 (0)