@@ -51,6 +51,25 @@ def get_patterns(module):
5151 all .append (item .regex .pattern + ".*" + sub )
5252 return all
5353
54+ def read_testurls (filename ):
55+ tuples = []
56+ file = open (filename )
57+ for line in file :
58+ line = line .strip ()
59+ if line and not line .startswith ('#' ):
60+ line = line .split ("#" , 1 )[0 ]
61+ urlspec = line .split ()
62+ if len (urlspec ) == 2 :
63+ codes , testurl = urlspec
64+ goodurl = None
65+ elif len (urlspec ) == 3 :
66+ codes , testurl , goodurl = urlspec
67+ else :
68+ raise ValueError ("Expected 'HTTP_CODE TESTURL [GOODURL]' in %s line, found '%s'." % (filename , line ))
69+ codes = codes .split ("," )
70+ tuples += [ (codes , testurl , goodurl ) ]
71+ return tuples
72+
5473class UrlTestCase (TestCase ):
5574 def setUp (self ):
5675 from django .test .client import Client
@@ -61,24 +80,10 @@ def setUp(self):
6180 self .testurls = []
6281 for root , dirs , files in os .walk (settings .BASE_DIR ):
6382 if "testurl.list" in files :
64- filename = root + "/testurl.list" # yes, this is non-portable
65- file = open (filename )
66- for line in file :
67- line = line .strip ()
68- if line and not line .startswith ('#' ):
69- line = line .split ("#" , 1 )[0 ]
70- urlspec = line .split ()
71- if len (urlspec ) == 2 :
72- codes , testurl = urlspec
73- goodurl = None
74- elif len (urlspec ) == 3 :
75- codes , testurl , goodurl = urlspec
76- else :
77- raise ValueError ("Expected 'HTTP_CODE TESTURL [GOODURL]' in %s line, found '%s'." % (filename , line ))
78- codes = codes .split ("," )
79- self .testtuples += [ (codes , testurl , goodurl ) ]
80- self .testurls += [ testurl ]
81- #print "(%s, %s, %s)" % (code, testurl, goodurl)
83+ self .testtuples += read_testurls (root + "/testurl.list" )
84+ if "testurls.list" in files :
85+ self .testtuples += read_testurls (root + "/testurls.list" )
86+ self .testurls = [ tuple [0 ] for tuple in self .testtuples ]
8287 # Use the default database for the url tests, instead of the test database
8388 self .testdb = settings .DATABASE_NAME
8489 connection .close ()
@@ -136,7 +141,9 @@ def doUrlsTest(self, lst):
136141 if goodhtml and response .content :
137142 testtext = reduce (response .content )
138143 goodtext = reduce (goodhtml )
139- if not testtext == goodtext :
144+ if testtext == goodtext :
145+ print "OK cmp %s" % (url )
146+ else :
140147 diff = "\n " .join (unified_diff (goodtext , testtext , url , master , lineterm = False ))
141148 dfile = "%s/../test/diff/%s" % (settings .BASE_DIR , url .replace ("/" , "_" ))
142149 if os .path .exists (dfile ):
0 commit comments