@@ -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
4147def 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 --
0 commit comments