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. ...@@ -41,15 +41,16 @@ defaults to tests/input/test01.xml.
Regression test 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 There are a number of test files in the 'tests' subdirectory, named
tests/input/test<number>.xml and tests/input/test<number>.html. The tests/input/test<number>.xml and tests/input/test<number>.html. The
Python script ./runtest.py calls driver.main() for each test file, and Python script ./runtest.py calls driver.main() for each test file, and
should print "<file> OK" for each one. 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.
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.
What's Here What's Here
----------- -----------
...@@ -65,9 +66,10 @@ driver.py script to demonstrate TAL expansion ...@@ -65,9 +66,10 @@ driver.py script to demonstrate TAL expansion
timer.py script to time various processing phases timer.py script to time various processing phases
setpath.py hack to set sys.path and import ZODB setpath.py hack to set sys.path and import ZODB
__init__.py empty file that makes this directory a package __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 ndiff.py helper for runtest.py to produce diffs
tests/ drectory with test files and output tests/ drectory with test files and output
tests/run.py Python script to run all tests
Author and License Author and License
------------------ ------------------
......
...@@ -118,9 +118,13 @@ def main(): ...@@ -118,9 +118,13 @@ def main():
opts = [] opts = []
args = sys.argv[1:] args = sys.argv[1:]
quiet = 0 quiet = 0
unittesting = 0
if args and args[0] == "-q": if args and args[0] == "-q":
quiet = 1 quiet = 1
del args[0] del args[0]
if args and args[0] == "-Q":
unittesting = 1
del args[0]
while args and args[0][:1] == '-': while args and args[0][:1] == '-':
opts.append(args[0]) opts.append(args[0])
del args[0] del args[0]
...@@ -136,8 +140,9 @@ def main(): ...@@ -136,8 +140,9 @@ def main():
sys.exit(1) sys.exit(1)
errors = 0 errors = 0
for arg in args: for arg in args:
print arg, if not unittesting:
sys.stdout.flush() print arg,
sys.stdout.flush()
save = sys.stdout, sys.argv save = sys.stdout, sys.argv
try: try:
try: try:
...@@ -154,8 +159,11 @@ def main(): ...@@ -154,8 +159,11 @@ def main():
print sys.exc_type print sys.exc_type
sys.stdout.flush() sys.stdout.flush()
else: else:
print "Failed:" if unittesting:
sys.stdout.flush() print
else:
print "Failed:"
sys.stdout.flush()
traceback.print_exc() traceback.print_exc()
continue continue
head, tail = os.path.split(arg) head, tail = os.path.split(arg)
...@@ -176,9 +184,13 @@ def main(): ...@@ -176,9 +184,13 @@ def main():
else: else:
actual = readlines(stdout) actual = readlines(stdout)
if actual == expected: if actual == expected:
print "OK" if not unittesting:
print "OK"
else: else:
print "not OK" if unittesting:
print
else:
print "not OK"
errors = 1 errors = 1
if not quiet and expected is not None: if not quiet and expected is not None:
showdiff(expected, actual) showdiff(expected, actual)
......
"""Empty file to make this directory a Python package."""
...@@ -8,6 +8,7 @@ import test_htmlparser ...@@ -8,6 +8,7 @@ import test_htmlparser
import test_htmltalparser import test_htmltalparser
import test_xmlparser import test_xmlparser
import test_talinterpreter import test_talinterpreter
import test_files
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
...@@ -15,6 +16,7 @@ def test_suite(): ...@@ -15,6 +16,7 @@ def test_suite():
suite.addTest(test_htmltalparser.test_suite()) suite.addTest(test_htmltalparser.test_suite())
suite.addTest(test_xmlparser.test_suite()) suite.addTest(test_xmlparser.test_suite())
suite.addTest(test_talinterpreter.test_suite()) suite.addTest(test_talinterpreter.test_suite())
suite.addTest(test_files.test_suite())
return suite return suite
def main(): 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