Commit d7508240 authored by Guido van Rossum's avatar Guido van Rossum

Add the file comparison test suite to the unit tests. Make tests a package.

parent 47451f5e
......@@ -41,15 +41,16 @@ defaults to tests/input/test01.xml.
Regression test
---------------
There are unit test suites in the 'tests' subdirectory; these can be
run with tests/run.py. This should print the testcase names plus
progress info, followed by a final line saying "OK". It requires that
../unittest.py exists.
There are a number of test files in the 'tests' subdirectory, named
tests/input/test<number>.xml and tests/input/test<number>.html. The
Python script ./runtest.py calls driver.main() for each test file, and
should print "<file> OK" for each one.
In addition, there are unit test suites in the 'tests' subdirectory;
these can be run with tests/run.py. This should print a number of
testcase names plus progress info, ending with a line saying "OK".
It requires that ../unittest.py exists.
should print "<file> OK" for each one. These tests are also run as
part of the unit test suites, so tests/run.py is all you need.
What's Here
-----------
......@@ -65,9 +66,10 @@ driver.py script to demonstrate TAL expansion
timer.py script to time various processing phases
setpath.py hack to set sys.path and import ZODB
__init__.py empty file that makes this directory a package
runtest.py Python script to run regression tests
runtest.py Python script to run file-comparison tests
ndiff.py helper for runtest.py to produce diffs
tests/ drectory with test files and output
tests/run.py Python script to run all tests
Author and License
------------------
......
......@@ -118,9 +118,13 @@ def main():
opts = []
args = sys.argv[1:]
quiet = 0
unittesting = 0
if args and args[0] == "-q":
quiet = 1
del args[0]
if args and args[0] == "-Q":
unittesting = 1
del args[0]
while args and args[0][:1] == '-':
opts.append(args[0])
del args[0]
......@@ -136,8 +140,9 @@ def main():
sys.exit(1)
errors = 0
for arg in args:
print arg,
sys.stdout.flush()
if not unittesting:
print arg,
sys.stdout.flush()
save = sys.stdout, sys.argv
try:
try:
......@@ -154,8 +159,11 @@ def main():
print sys.exc_type
sys.stdout.flush()
else:
print "Failed:"
sys.stdout.flush()
if unittesting:
print
else:
print "Failed:"
sys.stdout.flush()
traceback.print_exc()
continue
head, tail = os.path.split(arg)
......@@ -176,9 +184,13 @@ def main():
else:
actual = readlines(stdout)
if actual == expected:
print "OK"
if not unittesting:
print "OK"
else:
print "not OK"
if unittesting:
print
else:
print "not OK"
errors = 1
if not quiet and expected is not None:
showdiff(expected, actual)
......
"""Empty file to make this directory a Python package."""
......@@ -8,6 +8,7 @@ import test_htmlparser
import test_htmltalparser
import test_xmlparser
import test_talinterpreter
import test_files
def test_suite():
suite = unittest.TestSuite()
......@@ -15,6 +16,7 @@ def test_suite():
suite.addTest(test_htmltalparser.test_suite())
suite.addTest(test_xmlparser.test_suite())
suite.addTest(test_talinterpreter.test_suite())
suite.addTest(test_files.test_suite())
return suite
def main():
......
#! /usr/bin/env python1.5
"""Tests that run driver.py over input files comparing to output files."""
import os
import sys
import glob
import utils
import unittest
from TAL import runtest
class FileTestCase(unittest.TestCase):
def __init__(self, file, dir):
self.__file = file
self.__dir = dir
unittest.TestCase.__init__(self)
def runTest(self):
sys.stdout.write(os.path.basename(self.__file) + " ")
sys.stdout.flush()
sys.argv = ["", "-Q", self.__file]
pwd = os.getcwd()
try:
try:
os.chdir(self.__dir)
runtest.main()
finally:
os.chdir(pwd)
except SystemExit, what:
if what.code:
self.fail("output for %s didn't match" % self.__file)
try:
script = __file__
except NameError:
script = sys.argv[0]
def test_suite():
suite = unittest.TestSuite()
dir = os.path.dirname(script)
dir = os.path.abspath(dir)
parentdir = os.path.dirname(dir)
prefix = os.path.join(dir, "input", "test*.")
xmlargs = glob.glob(prefix + "xml")
xmlargs.sort()
htmlargs = glob.glob(prefix + "html")
htmlargs.sort()
args = xmlargs + htmlargs
if not args:
sys.stderr.write("Warning: no test input files found!!!\n")
for arg in args:
case = FileTestCase(arg, parentdir)
suite.addTest(case)
return suite
if __name__ == "__main__":
errs = utils.run_suite(test_suite())
sys.exit(errs and 1 or 0)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment