Changeset 13
- Timestamp:
- Thu Mar 23 21:26:10 2006
- Files:
-
- trunk/nose/core.py (modified) (diff)
- trunk/nose/plugins/base.py (modified) (diff)
- trunk/nose/plugins/profile.py (modified) (diff)
- trunk/nose/selector.py (modified) (diff)
- trunk/nose/config.py (modified) (diff)
- trunk/st/unit_tests/test_selector.py (modified) (diff)
- trunk/st/unit_tests/test_plugins.py (modified) (diff)
- trunk/setup.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/nose/core.py
r9 r13 208 208 log.info("%s looking for tests in %s [%s]", self, dirname, package) 209 209 210 def test_last(a, b, m=self.conf.testMatch): 211 if m.search(a) and not m.search(b): 212 return 1 213 elif m.search(b) and not m.search(a): 214 return -1 215 return cmp(a, b) 216 210 217 if not os.path.isabs(dirname): 211 218 raise ValueError("Directory paths must be specified as " … … 214 221 215 222 entries = os.listdir(dirname) 223 224 # to ensure that lib paths are set up correctly before tests are 225 # run, examine directories that look like lib or package 226 # directories first and tests last 227 entries.sort(test_last) 216 228 for item in entries: 217 229 log.debug("candidate %s in %s", item, dirname) … … 353 365 Before returning the first collected test, any defined setup method 354 366 will be run. Packages may define setup, setUp, setup_package or 355 setUpPackage, modules setup, setUp, setup_module or 367 setUpPackage, modules setup, setUp, setup_module, setupModule or 355 367 setUpModule. Likewise, teardown will be run if defined and if setup 356 368 ran successfully; teardown methods follow the same naming rules as … … 415 427 """Compare functions by their line numbers 416 428 """ 417 a_ln = a.func_code.co_firstlineno 418 b_ln = b.func_code.co_firstlineno 429 try: 430 a_ln = a.func_code.co_firstlineno 431 b_ln = b.func_code.co_firstlineno 432 except AttributeError: 433 return 0 419 434 return cmp(a_ln, b_ln) 420 435 … … 491 506 492 507 if hasattr(self.module, '__path__'): 493 names = ['setupPackage', 'setup_package'] 508 names = ['setupPackage', 'setUpPackage', 'setup_package'] 493 508 else: 494 names = ['setupModule', 'setup_module'] 509 names = ['setupModule', 'setUpModule', 'setup_module'] 494 509 names += ['setUp', 'setup'] 495 510 try_run(self.module, names) … … 556 571 self.verbosity, 557 572 self.conf) 558 573 574 def run(self, test): 575 wrapper = call_plugins(self.conf.plugins, 'prepare_test', test) 576 if wrapper is not None: 577 test = wrapper 578 return super(TextTestRunner, self).run(test) 559 579 560 580 class TestProgram(unittest.TestProgram): -
trunk/nose/plugins/base.py
r9 r13 90 90 91 91 class Watcher(Plugin): 92 """ 93 FIXME extend this API 92 94 95 for 0.9a1: 96 Think about this naming... better to be on_error or test_error? or 97 just error(), failure(), etc? 98 - test_error 99 - test_failure 100 - test_deprecated 101 - test_skipped 102 - test_success 103 104 105 Probably will need to provide a delegater class for use with that, 106 so that other test methods besides __call__ aren't masked. 107 108 """ 93 109 def aftertest(self, test): 94 110 # call it result.stopTest … … 106 122 # installed as atexit by begin 107 123 pass 108 124 125 def prepare_test(self, test): 126 """Watchers may CHANGE the test callable. 127 """ 128 pass 129 109 130 def report(self, stream): 110 131 # call in result.printErrors -
trunk/nose/plugins/profile.py
r9 r13 22 22 self.pfile = 'nosetests.prof' 23 23 self.prof = hotshot.Profile(self.pfile) 24 self.prof.start()25 24 25 def prepare_test(self, test): 26 def run_and_profile(result, prof=self.prof, test=test): 27 prof.runcall(test, result) 28 return run_and_profile 29 26 30 def report(self, stream): 27 31 # FIXME sort -
trunk/nose/selector.py
r7 r13 192 192 wanted = (self.exclude is None or not self.exclude.search(tail)) 193 193 else: 194 wanted = self.matches(tail) 194 wanted = (self.matches(tail) 195 or (self.conf.src_dirs 196 and tail in self.conf.src_dirs)) 195 197 plug_wants = call_plugins(self.plugins, 'want_directory', 196 198 dirname) … … 234 236 requirements. 235 237 """ 236 funcname = function.__name__ 238 try: 239 funcname = function.__name__ 240 except AttributeError: 241 # not a function 242 return False 237 243 wanted = not funcname.startswith('_') and self.matches(funcname) 238 244 plug_wants = call_plugins(self.plugins, 'want_function', function) … … 248 254 name must match test requirements. 249 255 """ 250 wanted = (not method.__name__.startswith('_') 251 and self.matches(method.__name__)) 256 try: 257 method_name = method.__name__ 258 except AttributeError: 259 # not a method 260 return False 261 wanted = (not method_name.startswith('_') 262 and self.matches(method_name)) 252 263 plug_wants = call_plugins(self.plugins, 'want_method', method) 253 264 if plug_wants is not None: … … 258 269 """Is the module a test module? 259 270 260 If conf.module_only is defined, the module name must start with 261 conf.module_only. Otherwise, the tail of the module name must match 262 test requirements. 271 The tail of the module name must match test requirements. 263 272 264 273 If a module is wanted, it means that the module should be loaded, … … 277 286 278 287 def want_module_tests(self, module): 288 """Collect tests from this module? 289 290 The tail of the module name must match test requirements. 291 292 If the modules tests are wanted, they will be collected by the 293 standard test collector. If your plugin wants to collect tests 294 from a module in some other way, it MUST NOT return true for 295 want_module_tests; that would not allow the plugin to collect 296 tests, but instead cause the standard collector to collect tests. 297 """ 279 298 wanted = self.matches(module.__name__.split('.')[-1]) 280 299 in_tests = self.module_in_tests(module) -
trunk/nose/config.py
r5 r13 16 16 include=None, 17 17 plugins=[], 18 src_dirs=['lib', 'src'], 18 19 tests=None, 19 20 verbosity=1, -
trunk/st/unit_tests/test_selector.py
r5 r13 120 120 assert s.want_directory('whatever/test') 121 121 assert not s.want_directory('/some/path/to/unit_tests/support') 122 123 # default src directory 124 assert s.want_directory('lib') 125 assert s.want_directory('src') 122 126 123 127 # this looks on disk for ../stpackage, which is a package -
trunk/st/unit_tests/test_plugins.py
r9 r13 52 52 assert Doctest in plugs 53 53 assert AttributeSelector in plugs 54 assert len(plugs) == 3 54 assert Profile in plugs 55 assert len(plugs) == 4 55 56 56 57 for p in plugs: -
trunk/setup.py
r9 r13 37 37 'coverage = nose.plugins.cover:Coverage', 38 38 'doctest = nose.plugins.doctests:Doctest', 39 # FIXME not functional 40 # 'profile = nose.plugins.profile:Profile', 39 'profile = nose.plugins.profile:Profile', 41 40 'attrib = nose.plugins.attrib:AttributeSelector' 42 41 ]
