|
6 | 6 | on the command line which contain the test cases to be run.
|
7 | 7 |
|
8 | 8 | Usage:
|
9 |
| - python AllTests.py - Runs all the unittests |
10 |
| - python AllTests.py mypackage.MyFile - Runs the tests in 'mypackage/MyFile' |
| 9 | + python AllTests.py - Runs all the unittests |
| 10 | + python AllTests.py mypackage.MyFile - Runs the tests in 'mypackage/MyFile' |
11 | 11 |
|
12 | 12 | This module also has a test-wide configuration file which can be accessed by
|
13 | 13 | the function AllTests.config().
|
|
17 | 17 |
|
18 | 18 | alltestnames = [
|
19 | 19 |
|
20 |
| - 'WebUtils.Tests.TestHTMLTag.makeTestSuite', |
| 20 | + 'WebUtils.Tests.TestHTMLTag.makeTestSuite', |
21 | 21 |
|
22 |
| - 'MiscUtils.Tests.TestCSVParser.CSVParserTests', |
23 |
| - 'MiscUtils.Tests.TestNamedValueAccess.makeTestSuite', |
24 |
| - 'MiscUtils.Tests.TestError.TestError', |
25 |
| - 'MiscUtils.Tests.TestFuncs.TestFuncs', |
26 |
| - 'MiscUtils.Tests.TestPickleCache.TestPickleCache', |
27 |
| - 'MiscUtils.Tests.TestDataTable.TestDataTable', |
28 |
| - 'MiscUtils.Tests.TestDateInterval.TestDateInterval', |
29 |
| - 'MiscUtils.Tests.TestDictForArgs', |
| 22 | + 'MiscUtils.Tests.TestCSVParser.CSVParserTests', |
| 23 | + 'MiscUtils.Tests.TestNamedValueAccess.makeTestSuite', |
| 24 | + 'MiscUtils.Tests.TestError.TestError', |
| 25 | + 'MiscUtils.Tests.TestFuncs.TestFuncs', |
| 26 | + 'MiscUtils.Tests.TestPickleCache.TestPickleCache', |
| 27 | + 'MiscUtils.Tests.TestDataTable.TestDataTable', |
| 28 | + 'MiscUtils.Tests.TestDateInterval.TestDateInterval', |
| 29 | + 'MiscUtils.Tests.TestDictForArgs', |
30 | 30 |
|
31 |
| - 'WebKit.Tests.Basic.Test', |
| 31 | + 'WebKit.Tests.Basic.Test', |
32 | 32 |
|
33 |
| - 'TaskKit.Tests.Test.makeTestSuite', |
| 33 | + 'TaskKit.Tests.Test.makeTestSuite', |
34 | 34 |
|
35 |
| - 'PSP.Tests.PSPUtilsTest', |
36 |
| - 'PSP.Tests.CompileTest', |
| 35 | + 'PSP.Tests.PSPUtilsTest', |
| 36 | + 'PSP.Tests.CompileTest', |
37 | 37 |
|
38 |
| - 'UserKit.Tests.ExampleTest', |
39 |
| - 'UserKit.Tests.Test', |
40 |
| - 'UserKit.Tests.UserManagerTest.makeTestSuite', |
| 38 | + 'UserKit.Tests.ExampleTest', |
| 39 | + 'UserKit.Tests.Test', |
| 40 | + 'UserKit.Tests.UserManagerTest.makeTestSuite', |
41 | 41 |
|
42 | 42 | ]
|
43 | 43 |
|
44 | 44 | try:
|
45 |
| - import unittest |
| 45 | + import unittest |
46 | 46 | except ImportError: # Python < 2.1
|
47 |
| - print "This module needs the Python unittest package (PyUnit)" |
48 |
| - print "available at http://pyunit.sourceforge.net" |
49 |
| - raise |
| 47 | + print "This module needs the Python unittest package (PyUnit)" |
| 48 | + print "available at http://pyunit.sourceforge.net" |
| 49 | + raise |
50 | 50 | try:
|
51 |
| - import logging |
| 51 | + import logging |
52 | 52 | except ImportError: # Python < 2.3
|
53 |
| - print "This module needs the Python logging system" |
54 |
| - print "available at http://www.red-dove.com/python_logging.html" |
55 |
| - raise |
| 53 | + print "This module needs the Python logging system" |
| 54 | + print "available at http://www.red-dove.com/python_logging.html" |
| 55 | + raise |
56 | 56 | try:
|
57 |
| - True, False |
| 57 | + True, False |
58 | 58 | except NameError: # Python < 2.3
|
59 |
| - True, False = 1, 0 |
| 59 | + True, False = 1, 0 |
60 | 60 |
|
61 | 61 | import sys, os, site
|
62 | 62 | from MiscUtils.Configurable import Configurable
|
|
66 | 66 |
|
67 | 67 |
|
68 | 68 | class _AllTestsConfig(Configurable):
|
69 |
| - """Configuration for tests. |
| 69 | + """Configuration for tests. |
70 | 70 |
|
71 |
| - E.g. which DBs to test, where to find DB utilities. |
| 71 | + E.g. which DBs to test, where to find DB utilities. |
72 | 72 |
|
73 |
| - If individual tests need some configuration, put it here so it |
74 |
| - is easy for a new user to configure all the tests in one place. |
| 73 | + If individual tests need some configuration, put it here so it |
| 74 | + is easy for a new user to configure all the tests in one place. |
75 | 75 |
|
76 |
| - """ |
| 76 | + """ |
77 | 77 |
|
78 |
| - _defaultConfig = ''' |
79 |
| -{ # Edit this file to activate more tests |
| 78 | + _defaultConfig = ''' |
| 79 | +{ # Edit this file to activate more tests |
80 | 80 |
|
81 |
| - # Turn on tests that use MySQL? |
82 |
| - 'hasMysql': False, |
| 81 | + # Turn on tests that use MySQL? |
| 82 | + 'hasMysql': False, |
83 | 83 |
|
84 |
| - # If hasMysql is true, then these are used to connect: |
85 |
| - 'mysqlTestInfo' : { |
| 84 | + # If hasMysql is true, then these are used to connect: |
| 85 | + 'mysqlTestInfo' : { |
86 | 86 |
|
87 |
| - # Where is MySQLdb lib located? |
88 |
| - # 'extraSysPath': ['/somewhere/MySQL-python-1.2.2/build/lib'], |
89 |
| - 'extraSysPath': [], |
| 87 | + # Where is MySQLdb lib located? |
| 88 | + # 'extraSysPath': ['/somewhere/MySQL-python-1.2.2/build/lib'], |
| 89 | + 'extraSysPath': [], |
90 | 90 |
|
91 |
| - # Where is the MySQL client located (if not on the path)? |
92 |
| - # 'mysqlClient': '/usr/local/mysql/bin/mysql', |
93 |
| - # 'mysqlClient': 'c:/progra~1/mysql/mysqls~1.0/bin/mysql.exe', |
94 |
| - 'mysqlClient': 'mysql', |
| 91 | + # Where is the MySQL client located (if not on the path)? |
| 92 | + # 'mysqlClient': '/usr/local/mysql/bin/mysql', |
| 93 | + # 'mysqlClient': 'c:/progra~1/mysql/mysqls~1.0/bin/mysql.exe', |
| 94 | + 'mysqlClient': 'mysql', |
95 | 95 |
|
96 |
| - # The name of the MySQL database to be used: |
97 |
| - 'database': 'test', # Test case uses this, |
98 |
| - # but UserManagerTest.mkmodel/Settings.config also defines it. |
| 96 | + # The name of the MySQL database to be used: |
| 97 | + 'database': 'test', # Test case uses this, |
| 98 | + # but UserManagerTest.mkmodel/Settings.config also defines it. |
99 | 99 |
|
100 |
| - # This is passed to MySQLObjectStore(): |
101 |
| - 'DatabaseArgs': { |
102 |
| - 'host': 'localhost', |
103 |
| - 'port': 3306, |
104 |
| - 'user': 'test', # should have all database privileges |
105 |
| - 'passwd': '', |
106 |
| - }, |
107 |
| - } |
| 100 | + # This is passed to MySQLObjectStore(): |
| 101 | + 'DatabaseArgs': { |
| 102 | + 'host': 'localhost', |
| 103 | + 'port': 3306, |
| 104 | + 'user': 'test', # should have all database privileges |
| 105 | + 'passwd': '', |
| 106 | + }, |
| 107 | + } |
108 | 108 | }
|
109 | 109 | '''
|
110 | 110 |
|
111 |
| - def configFilename(self): |
112 |
| - theFilename = os.path.join(os.path.dirname(__file__), 'AllTests.config') |
113 |
| - # The first time we are run, write a new configuration file. |
114 |
| - if not os.path.exists(theFilename): |
115 |
| - _log.info(' Creating new configuration file at "%s".' |
116 |
| - ' You can customize it to run more tests.', theFilename) |
117 |
| - fp = open(theFilename, 'w') |
118 |
| - fp.write(_AllTestsConfig._defaultConfig) |
119 |
| - fp.close() |
120 |
| - return theFilename |
121 |
| - |
122 |
| - def defaultConfig(self): |
123 |
| - default = eval(_AllTestsConfig._defaultConfig) |
124 |
| - return default |
| 111 | + def configFilename(self): |
| 112 | + theFilename = os.path.join(os.path.dirname(__file__), 'AllTests.config') |
| 113 | + # The first time we are run, write a new configuration file. |
| 114 | + if not os.path.exists(theFilename): |
| 115 | + _log.info(' Creating new configuration file at "%s".' |
| 116 | + ' You can customize it to run more tests.', theFilename) |
| 117 | + fp = open(theFilename, 'w') |
| 118 | + fp.write(_AllTestsConfig._defaultConfig) |
| 119 | + fp.close() |
| 120 | + return theFilename |
| 121 | + |
| 122 | + def defaultConfig(self): |
| 123 | + default = eval(_AllTestsConfig._defaultConfig) |
| 124 | + return default |
125 | 125 |
|
126 | 126 | def config():
|
127 |
| - """Return singleton of configuration file.""" |
128 |
| - global _alltestConfig |
129 |
| - if _alltestConfig is None: |
130 |
| - _alltestConfig = _AllTestsConfig() |
131 |
| - return _alltestConfig |
| 127 | + """Return singleton of configuration file.""" |
| 128 | + global _alltestConfig |
| 129 | + if _alltestConfig is None: |
| 130 | + _alltestConfig = _AllTestsConfig() |
| 131 | + return _alltestConfig |
132 | 132 |
|
133 | 133 |
|
134 | 134 | def checkAndAddPaths(listOfPaths):
|
135 |
| - """Check paths. |
| 135 | + """Check paths. |
136 | 136 |
|
137 |
| - Pass me a list of paths, and I will check that each one exists and |
138 |
| - add it to sys.paths. This is used by tests which need to use some |
139 |
| - required library such as database drivers. |
| 137 | + Pass me a list of paths, and I will check that each one exists and |
| 138 | + add it to sys.paths. This is used by tests which need to use some |
| 139 | + required library such as database drivers. |
140 | 140 |
|
141 |
| - """ |
142 |
| - numBadPaths = 0 |
143 |
| - for p in listOfPaths: |
144 |
| - p = os.path.abspath(p) |
145 |
| - if os.path.exists(p): |
146 |
| - site.addsitedir(p) |
147 |
| - else: |
148 |
| - numBadPaths += 1 |
149 |
| - print 'WARNING: Trying to add paths to sys.path,' |
150 |
| - print ' but could not find "%s".' % p |
151 |
| - return numBadPaths # 0 = all were found |
| 141 | + """ |
| 142 | + numBadPaths = 0 |
| 143 | + for p in listOfPaths: |
| 144 | + p = os.path.abspath(p) |
| 145 | + if os.path.exists(p): |
| 146 | + site.addsitedir(p) |
| 147 | + else: |
| 148 | + numBadPaths += 1 |
| 149 | + print 'WARNING: Trying to add paths to sys.path,' |
| 150 | + print ' but could not find "%s".' % p |
| 151 | + return numBadPaths # 0 = all were found |
152 | 152 |
|
153 | 153 |
|
154 | 154 | if __name__ == '__main__':
|
155 |
| - # Configure logging |
156 |
| - logging.basicConfig() # default level is WARN |
157 |
| - print |
158 |
| - print |
159 |
| - # If no arguments are given, all of the test cases are run. |
160 |
| - if len(sys.argv) == 1: |
161 |
| - testnames = alltestnames |
162 |
| - verbosity = 2 |
163 |
| - logging.getLogger().setLevel(logging.INFO) |
164 |
| - print 'Loading all Webware Tests...' |
165 |
| - else: |
166 |
| - testnames = sys.argv[1:] |
167 |
| - # Turn up verbosity and logging level |
168 |
| - verbosity = 3 |
169 |
| - logging.getLogger().setLevel(logging.DEBUG) |
170 |
| - print 'Loading tests %s...' % testnames |
171 |
| - |
172 |
| - tests = unittest.TestSuite() |
173 |
| - |
174 |
| - # We could just use defaultTestLoader.loadTestsFromNames(), |
175 |
| - # but it doesn't give a good error message when it cannot load a test. |
176 |
| - # So we load all tests individually and raise appropriate exceptions. |
177 |
| - for t in testnames: |
178 |
| - try: |
179 |
| - tests.addTest(unittest.defaultTestLoader.loadTestsFromName(t)) |
180 |
| - except Exception: |
181 |
| - print 'ERROR: Skipping tests from "%s".' % t |
182 |
| - try: |
183 |
| - __import__(t) # just try to import the test after loadig failed |
184 |
| - except ImportError: |
185 |
| - print 'Could not import the test module.' |
186 |
| - else: |
187 |
| - print 'Could not load the test suite.' |
188 |
| - from traceback import print_exc |
189 |
| - print_exc() |
190 |
| - |
191 |
| - print |
192 |
| - print 'Running the tests...' |
193 |
| - unittest.TextTestRunner(verbosity=verbosity).run(tests) |
| 155 | + # Configure logging |
| 156 | + logging.basicConfig() # default level is WARN |
| 157 | + print |
| 158 | + print |
| 159 | + # If no arguments are given, all of the test cases are run. |
| 160 | + if len(sys.argv) == 1: |
| 161 | + testnames = alltestnames |
| 162 | + verbosity = 2 |
| 163 | + logging.getLogger().setLevel(logging.INFO) |
| 164 | + print 'Loading all Webware Tests...' |
| 165 | + else: |
| 166 | + testnames = sys.argv[1:] |
| 167 | + # Turn up verbosity and logging level |
| 168 | + verbosity = 3 |
| 169 | + logging.getLogger().setLevel(logging.DEBUG) |
| 170 | + print 'Loading tests %s...' % testnames |
| 171 | + |
| 172 | + tests = unittest.TestSuite() |
| 173 | + |
| 174 | + # We could just use defaultTestLoader.loadTestsFromNames(), |
| 175 | + # but it doesn't give a good error message when it cannot load a test. |
| 176 | + # So we load all tests individually and raise appropriate exceptions. |
| 177 | + for t in testnames: |
| 178 | + try: |
| 179 | + tests.addTest(unittest.defaultTestLoader.loadTestsFromName(t)) |
| 180 | + except Exception: |
| 181 | + print 'ERROR: Skipping tests from "%s".' % t |
| 182 | + try: |
| 183 | + __import__(t) # just try to import the test after loadig failed |
| 184 | + except ImportError: |
| 185 | + print 'Could not import the test module.' |
| 186 | + else: |
| 187 | + print 'Could not load the test suite.' |
| 188 | + from traceback import print_exc |
| 189 | + print_exc() |
| 190 | + |
| 191 | + print |
| 192 | + print 'Running the tests...' |
| 193 | + unittest.TextTestRunner(verbosity=verbosity).run(tests) |
0 commit comments