comparison tests/run-tests.py @ 21531:7fcda22acc43

run-tests: make keywords a named argument to TestSuite.__init__ This was the last usage of option in ``TextTestRunner.run``.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 25 Apr 2014 15:06:23 -0700
parents 78289625e986
children 9d2ba7e2324d
comparison
equal deleted inserted replaced
21530:78289625e986 21531:7fcda22acc43
1152 1152
1153 class TestSuite(unittest.TestSuite): 1153 class TestSuite(unittest.TestSuite):
1154 """Custom unitest TestSuite that knows how to execute Mercurial tests.""" 1154 """Custom unitest TestSuite that knows how to execute Mercurial tests."""
1155 1155
1156 def __init__(self, runner, jobs=1, whitelist=None, blacklist=None, 1156 def __init__(self, runner, jobs=1, whitelist=None, blacklist=None,
1157 retest=False, 1157 retest=False, keywords=None,
1158 *args, **kwargs): 1158 *args, **kwargs):
1159 """Create a new instance that can run tests with a configuration. 1159 """Create a new instance that can run tests with a configuration.
1160 1160
1161 jobs specifies the number of jobs to run concurrently. Each test 1161 jobs specifies the number of jobs to run concurrently. Each test
1162 executes on its own thread. Tests actually spawn new processes, so 1162 executes on its own thread. Tests actually spawn new processes, so
1169 backwards compatible behavior which reports skipped tests as part 1169 backwards compatible behavior which reports skipped tests as part
1170 of the results. 1170 of the results.
1171 1171
1172 retest denotes whether to retest failed tests. This arguably belongs 1172 retest denotes whether to retest failed tests. This arguably belongs
1173 outside of TestSuite. 1173 outside of TestSuite.
1174
1175 keywords denotes key words that will be used to filter which tests
1176 to execute. This arguably belongs outside of TestSuite.
1174 """ 1177 """
1175 super(TestSuite, self).__init__(*args, **kwargs) 1178 super(TestSuite, self).__init__(*args, **kwargs)
1176 1179
1177 self._runner = runner 1180 self._runner = runner
1178 self._jobs = jobs 1181 self._jobs = jobs
1179 self._whitelist = whitelist 1182 self._whitelist = whitelist
1180 self._blacklist = blacklist 1183 self._blacklist = blacklist
1181 self._retest = retest 1184 self._retest = retest
1185 self._keywords = keywords
1182 1186
1183 def run(self, result): 1187 def run(self, result):
1184 options = self._runner.options
1185
1186 # We have a number of filters that need to be applied. We do this 1188 # We have a number of filters that need to be applied. We do this
1187 # here instead of inside Test because it makes the running logic for 1189 # here instead of inside Test because it makes the running logic for
1188 # Test simpler. 1190 # Test simpler.
1189 tests = [] 1191 tests = []
1190 for test in self._tests: 1192 for test in self._tests:
1199 1201
1200 if self._retest and not os.path.exists(test.errpath): 1202 if self._retest and not os.path.exists(test.errpath):
1201 result.addIgnore(test, 'not retesting') 1203 result.addIgnore(test, 'not retesting')
1202 continue 1204 continue
1203 1205
1204 if options.keywords: 1206 if self._keywords:
1205 f = open(test.path) 1207 f = open(test.path)
1206 t = f.read().lower() + test.name.lower() 1208 t = f.read().lower() + test.name.lower()
1207 f.close() 1209 f.close()
1208 ignored = False 1210 ignored = False
1209 for k in options.keywords.lower().split(): 1211 for k in self._keywords.lower().split():
1210 if k not in t: 1212 if k not in t:
1211 result.addIgnore(test, "doesn't match keyword") 1213 result.addIgnore(test, "doesn't match keyword")
1212 ignored = True 1214 ignored = True
1213 break 1215 break
1214 1216
1506 1508
1507 suite = TestSuite(self, jobs=self.options.jobs, 1509 suite = TestSuite(self, jobs=self.options.jobs,
1508 whitelist=self.options.whitelisted, 1510 whitelist=self.options.whitelisted,
1509 blacklist=self.options.blacklist, 1511 blacklist=self.options.blacklist,
1510 retest=self.options.retest, 1512 retest=self.options.retest,
1513 keywords=self.options.keywords,
1511 tests=tests) 1514 tests=tests)
1512 verbosity = 1 1515 verbosity = 1
1513 if self.options.verbose: 1516 if self.options.verbose:
1514 verbosity = 2 1517 verbosity = 2
1515 runner = TextTestRunner(self, verbosity=verbosity) 1518 runner = TextTestRunner(self, verbosity=verbosity)