Bug 458256. Use LoadLibraryW instead of LoadLibrary (patch by DougT). r+sr=vlad
[wine-gecko.git] / tools / relic / test / test.py
blob1bf41cb7530bd0a0d80a8ed4fcc27488d9d2bad2
1 #!python
3 # Copyright (c) 2004 Trent Mick
5 """
6 relic.py Regression Test Suite Harness
8 Usage:
9 python test.py [<options>...] [<tests>...]
11 Options:
12 -x <testname>, --exclude=<testname>
13 Exclude the named test from the set of tests to be
14 run. This can be used multiple times to specify
15 multiple exclusions.
16 -v, --verbose run tests in verbose mode with output to stdout
17 -q, --quiet don't print anything except if a test fails
18 -h, --help print this text and exit
20 This will find all modules whose name is "test_*" in the test
21 directory, and run them. Various command line options provide
22 additional facilities.
24 If non-option arguments are present, they are names for tests to run.
25 If no test names are given, all tests are run.
27 Test Setup Options:
28 -c, --clean Don't setup, just clean up the test workspace.
29 -n, --no-clean Don't clean up after setting up and running the
30 test suite.
31 """
33 import os
34 import sys
35 import getopt
36 import glob
37 import time
38 import types
39 import tempfile
40 import unittest
44 #---- exceptions
46 class TestError(Exception):
47 pass
50 #---- globals
52 gVerbosity = 2
55 #---- utility routines
57 def _rmtreeOnError(rmFunction, filePath, excInfo):
58 if excInfo[0] == OSError:
59 # presuming because file is read-only
60 os.chmod(filePath, 0777)
61 rmFunction(filePath)
63 def _rmtree(dirname):
64 import shutil
65 shutil.rmtree(dirname, 0, _rmtreeOnError)
68 def _getAllTests(testDir):
69 """Return a list of all tests to run."""
70 testPyFiles = glob.glob(os.path.join(testDir, "test_*.py"))
71 modules = [f[:-3] for f in testPyFiles if f and f.endswith(".py")]
73 packages = []
74 for f in glob.glob(os.path.join(testDir, "test_*")):
75 if os.path.isdir(f) and "." not in f:
76 if os.path.isfile(os.path.join(testDir, f, "__init__.py")):
77 packages.append(f)
79 return modules + packages
82 def _setUp():
83 # Ensure the *development* check is tested.
84 topDir = os.path.abspath(os.pardir)
85 sys.path.insert(0, topDir)
86 print "Setup to test:"
87 import relic
88 ver = "%s.%s.%s" % relic._version_
89 print "relic %s at '%s'" % (ver, relic.__file__)
90 print "-"*70 + '\n'
93 def _tearDown():
94 pass
97 def test(testModules, testDir=os.curdir, exclude=[]):
98 """Run the given regression tests and report the results."""
99 # Determine the test modules to run.
100 if not testModules:
101 testModules = _getAllTests(testDir)
102 testModules = [t for t in testModules if t not in exclude]
104 # Aggregate the TestSuite's from each module into one big one.
105 allSuites = []
106 for moduleFile in testModules:
107 module = __import__(moduleFile, globals(), locals(), [])
108 suite = getattr(module, "suite", None)
109 if suite is not None:
110 allSuites.append(suite())
111 else:
112 if gVerbosity >= 2:
113 print "WARNING: module '%s' did not have a suite() method."\
114 % moduleFile
115 suite = unittest.TestSuite(allSuites)
117 # Run the suite.
118 runner = unittest.TextTestRunner(sys.stdout, verbosity=gVerbosity)
119 result = runner.run(suite)
122 #---- mainline
124 def main(argv):
125 testDir = os.path.dirname(sys.argv[0])
127 # parse options
128 global gVerbosity
129 try:
130 opts, testModules = getopt.getopt(sys.argv[1:], 'hvqx:cn',
131 ['help', 'verbose', 'quiet', 'exclude=', 'clean',
132 'no-clean'])
133 except getopt.error, ex:
134 print "%s: ERROR: %s" % (argv[0], ex)
135 print __doc__
136 sys.exit(2)
137 exclude = []
138 setupOpts = {}
139 justClean = 0
140 clean = 1
141 for opt, optarg in opts:
142 if opt in ("-h", "--help"):
143 print __doc__
144 sys.exit(0)
145 elif opt in ("-v", "--verbose"):
146 gVerbosity += 1
147 elif opt in ("-q", "--quiet"):
148 gVerbosity -= 1
149 elif opt in ("-x", "--exclude"):
150 exclude.append(optarg)
151 elif opt in ("-c", "--clean"):
152 justClean = 1
153 elif opt in ("-n", "--no-clean"):
154 clean = 0
156 retval = None
157 if not justClean:
158 _setUp(**setupOpts)
159 try:
160 if not justClean:
161 retval = test(testModules, testDir=testDir, exclude=exclude)
162 finally:
163 if clean:
164 _tearDown(**setupOpts)
165 return retval
167 if __name__ == '__main__':
168 sys.exit( main(sys.argv) )