Skip to content

Commit 0e2173a

Browse files
committed
Add testing support for selectively ignoring regex patterns. First use case is to ignore datestamps for page creation. Also add ignore:date to the spec. in urltest.list for agenda and meeting pages, and add some ignore date regex patterns.
- Legacy-Id: 542
1 parent 8b85983 commit 0e2173a

5 files changed

Lines changed: 47 additions & 19 deletions

File tree

ietf/meeting/testurl.list

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
200 /meeting/68/agenda.html https://datatracker.ietf.org/public/meeting_agenda_html.cgi?meeting_num=68
2-
200 /meeting/68/agenda.txt https://datatracker.ietf.org/public/meeting_agenda_text.cgi?meeting_num=68
3-
200 /meeting/69/materials.html https://datatracker.ietf.org/public/meeting_materials.cgi?meeting_num=69
4-
404 /meeting/70/agenda.html
5-
404 /meeting/70/materials.html
1+
200,ignore:date /meeting/68/agenda.html https://datatracker.ietf.org/public/meeting_agenda_html.cgi?meeting_num=68
2+
200,ignore:date /meeting/68/agenda.txt https://datatracker.ietf.org/public/meeting_agenda_text.cgi?meeting_num=68
3+
200,ignore:date /meeting/69/materials.html https://datatracker.ietf.org/public/meeting_materials.cgi?meeting_num=69
4+
404 /meeting/70/agenda.html
5+
404 /meeting/70/materials.html

ietf/tests.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ def reduce_text(html, pre=False, fill=True):
3232
text = text.replace(" : ", ": ").replace(" :", ": ")
3333
text = text.replace('."', '".')
3434
text = text.replace(',"', '",')
35+
return text
36+
37+
def lines(text, pre=False):
3538
if pre:
3639
text = text.split("\n")
3740
else:
3841
text = [ line.strip() for line in text.split("\n") if line.strip()]
39-
return text
42+
43+
def sorted(lst):
44+
lst.sort()
45+
return lst
4046

4147
def get_patterns(module):
4248
all = []
@@ -81,7 +87,10 @@ def read_testurls(filename):
8187
codes, testurl, goodurl = urlspec
8288
else:
8389
raise ValueError("Expected 'HTTP_CODE TESTURL [GOODURL]' in %s line, found '%s'." % (filename, line))
84-
codes = codes.split(",")
90+
91+
92+
codes = dict([ (item, "") for item in codes.split(",") if not":" in item] +
93+
[ (item.split(":")[:2]) for item in codes.split(",") if ":" in item] )
8594
tuples += [ (codes, testurl, goodurl) ]
8695
file.close()
8796
return tuples
@@ -119,6 +128,7 @@ def module_setup(module):
119128
module.testtuples = []
120129
module.testurls = []
121130
module.diffchunks = []
131+
module.ignores = {}
122132
module.testtuples = get_testurls()
123133
module.testurls = [ tuple[1] for tuple in module.testtuples ]
124134

@@ -131,10 +141,19 @@ def module_setup(module):
131141
chunk = re.sub(r"([\[\]().|+*?])", r"\\\1", chunk)
132142
# @@ -27,0 \+23,1 @@
133143
chunk = re.sub(r"(?m)^@@ -\d+,(\d+) \\\+\d+,(\d+) @@$", r"@@ -\d+,\1 \+\d+,\2 @@", chunk)
134-
#print "*** Installing diff chunk:"
135-
#print chunk
136144
module.diffchunks.append(chunk)
137145

146+
# find ignore chunks
147+
for root, dirs, files in os.walk(settings.BASE_DIR+"/../test/ignore/"):
148+
# This only expects one directory level below test/ignore/:
149+
for file in files:
150+
path = root + "/" + file
151+
dir = root.split("/")[-1]
152+
chunk = filetext(path).strip()
153+
if not dir in module.ignores:
154+
module.ignores[dir] = []
155+
module.ignores[dir].append(chunk)
156+
138157
# extract application urls:
139158
module.patterns = get_patterns(ietf.urls)
140159

@@ -273,28 +292,34 @@ def doUrlsTest(self, lst):
273292
try:
274293
if goodhtml and response.content:
275294
if "sort" in codes:
276-
def sorted(l):
277-
l.sort()
278-
return l
279-
testtext = sorted(reduce_text(response.content, fill=False))
295+
testtext = reduce_text(response.content, fill=False)
296+
goodtext = reduce_text(goodhtml, fill=False)
297+
else:
298+
testtext = reduce_text(response.content)
299+
goodtext = reduce_text(goodhtml)
300+
if "ignore" in codes:
301+
ignores = codes["ignore"].split("/")
302+
for ignore in ignores:
303+
for regex in module.ignores[ignore]:
304+
testtext = re.sub(regex, "", testtext)
305+
goodtext = re.sub(regex, "", goodtext)
306+
testtext = lines(testtext)
307+
goodtext = lines(goodtext)
308+
if "sort" in codes:
309+
testtext = sorted(testtext)
280310
while testtext and not testtext[0]:
281311
del testtext[0]
282-
goodtext = sorted(reduce_text(goodhtml, fill=False))
312+
goodtext = sorted(goodtext)
283313
while goodtext and not goodtext[0]:
284314
del goodtext[0]
285-
else:
286-
testtext = reduce_text(response.content)
287-
goodtext = reduce_text(goodhtml)
288315
if testtext == goodtext:
289316
note("OK cmp %s" % (url))
290317
else:
291318
contextlines = 0
292319
difflist = list(unified_diff(goodtext, testtext, master, url, "", "", contextlines, lineterm=""))
293320
diff = "\n".join(difflist)
294321
for chunk in module.diffchunks:
295-
#print "*** Checking for chunk:", chunk[:24]
296322
while re.search(chunk, diff):
297-
#print "*** Removing chunk of %s lines" % (len(chunk.split("\n")))
298323
diff = re.sub(chunk, "", diff)
299324
if len(diff.strip().splitlines()) == 2:
300325
# only the initial 2 lines of the diff remains --

test/ignore/date/iso-date.regex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20\d\d-\d\d-\d\d \d\d?:\d\d:\d\d( \(\w+\))?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d\d, [12]0\d\d, \d\d?:\d\d?:\d\d?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(January|February|March|April|May|June|July|August|September|October|November|December) \d\d, [12]0\d\d, \d\d?:\d\d?:\d\d?

0 commit comments

Comments
 (0)