Adding the ability to define generic diff chunks which should be ignored. Fixing the inverted filename indication in the unified diff.

- Legacy-Id: 311
This commit is contained in:
Henrik Levkowetz 2007-06-11 16:41:24 +00:00
parent d856877885
commit 8f81a7a7de

View file

@ -70,6 +70,18 @@ def read_testurls(filename):
file.close() file.close()
return tuples return tuples
def filetext(filename):
file = open(filename)
chunk = file.read()
file.close()
return chunk
def filetime(name):
if os.path.exists(name):
return os.stat(name)[stat.ST_MTIME]
else:
return 0
class UrlTestCase(TestCase): class UrlTestCase(TestCase):
def setUp(self): def setUp(self):
from django.test.client import Client from django.test.client import Client
@ -78,6 +90,7 @@ class UrlTestCase(TestCase):
# find test urls # find test urls
self.testtuples = [] self.testtuples = []
self.testurls = [] self.testurls = []
self.diffchunks = []
for root, dirs, files in os.walk(settings.BASE_DIR): for root, dirs, files in os.walk(settings.BASE_DIR):
if "testurl.list" in files: if "testurl.list" in files:
self.testtuples += read_testurls(root+"/testurl.list") self.testtuples += read_testurls(root+"/testurl.list")
@ -85,6 +98,13 @@ class UrlTestCase(TestCase):
self.testtuples += read_testurls(root+"/testurls.list") self.testtuples += read_testurls(root+"/testurls.list")
self.testurls = [ tuple[1] for tuple in self.testtuples ] self.testurls = [ tuple[1] for tuple in self.testtuples ]
# find diff chunks
testdir = os.path.abspath(settings.BASE_DIR+"/../test/diff/")
for item in os.listdir(testdir):
path = testdir + "/" + item
if item.startswith("generic-") and os.path.isfile(path):
self.diffchunks.append(filetext(path))
# extract application urls: # extract application urls:
self.patterns = get_patterns(ietf.urls) self.patterns = get_patterns(ietf.urls)
# Use the default database for the url tests, instead of the test database # Use the default database for the url tests, instead of the test database
@ -148,7 +168,11 @@ class UrlTestCase(TestCase):
if testtext == goodtext: if testtext == goodtext:
print "OK cmp %s" % (url) print "OK cmp %s" % (url)
else: else:
diff = "\n".join(unified_diff(goodtext, testtext, url, master, lineterm=False)) contextlines = 0
diff = "\n".join(unified_diff(goodtext, testtext, master, url, "", "", contextlines, lineterm=""))
for chunk in self.diffchunks:
if chunk in diff:
diff = diff.replace(chunk, "")
dfile = "%s/../test/diff/%s" % (settings.BASE_DIR, url.replace("/", "_")) dfile = "%s/../test/diff/%s" % (settings.BASE_DIR, url.replace("/", "_"))
if os.path.exists(dfile): if os.path.exists(dfile):
dfile = open(dfile) dfile = open(dfile)