Changeset 120
- Timestamp:
- Wed Nov 15 17:31:47 2006
- Files:
-
- branches/new_loader/unit_tests/test_utils.py (modified) (diff)
- branches/new_loader/nose/selector.py (modified) (diff)
- branches/new_loader/work.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
branches/new_loader/unit_tests/test_utils.py
r117 r120 13 13 assert not nose.file_like('some.package') 14 14 assert nose.file_like('a-file') 15 assert not nose.file_like('test') 15 16 16 17 def test_split_test_name(self): -
branches/new_loader/nose/selector.py
r119 r120 1 1 import logging 2 2 import os 3 import re 3 4 import sys 4 5 import unittest … … 18 19 self.configure(conf) 19 20 20 def anytest(self, func): 21 def _anytest(self, func): 20 21 """Check func against all tests. Funcs should return None if they 21 22 don't apply, False if they apply but don't match, True if they apply … … 41 42 return res 42 43 43 def classInTests(self, cls): 44 def classInTests(self, cls, tests): 45 if tests is None: 46 in_tests = match_all 47 else: 48 def in_tests(cls): 49 return filter(None, 50 [ t.matches_class(cls) for t in tests]) 51 return in_tests 52 53 def _classInTests(self, cls): 44 54 def match(filename, modname, funcname, cls=cls): 45 55 if funcname is None: … … 57 67 self.include = conf.include 58 68 self.plugins = conf.plugins 59 self.match = conf.testMatch 60 self.tests = conf.tests 69 self.match = conf.testMatch 61 70 62 71 def fileInTests(self, tests): 63 72 if tests is None: 64 def in_tests(file): 65 return True 73 in_tests = match_all 66 74 else: 67 75 def in_tests(file): … … 85 93 return self.anytest(match) 86 94 87 def filematch(self, filename, modname, funcname, file): 95 def _filematch(self, filename, modname, funcname, file): 87 95 log.debug("Filematch (%s, %s, %s, %s)", 88 96 filename, modname, funcname, file) … … 156 164 157 165 def methodInTests(self, tests): 166 """Determine if a method is listed in the requested tests. To 167 be consideed a match, the method's class must be in the class 168 part of the test address, and the function part of the test 169 address must match the method name or be None. 170 """ 158 171 if tests is None: 159 def in_tests(method): 160 return True 172 in_tests = match_all 161 173 else: 162 174 def in_tests(method): … … 190 202 """ 191 203 if tests is None: 192 def in_tests(module): 193 return True 204 in_tests = match_all 194 205 else: 195 206 def in_tests(module): … … 198 209 for t in tests ]) 199 210 return in_tests 200 201 def _moduleInTests(self, module, either=False):202 def match(filename, modname, funcname, module=module, either=either):203 log.debug("Checking module %s in test %s:%s (either: %s)",204 module.__name__, modname, funcname, either)205 if modname is None:206 if filename is None:207 return None208 mod_file = module.__file__209 if mod_file.endswith('.pyc') or mod_file.endswith('.pyo'):210 mod_file = mod_file[:-3] + 'py'211 log.debug("Checking module file %s against filename %s",212 mod_file, filename)213 return self.filematch(filename, modname, funcname,214 file=mod_file)215 mname = module.__name__216 result = (subpackage_of(mname, modname) or217 (either and subpackage_of(modname, mname)))218 log.debug("Module %s match %s (either: %s) result %s",219 module.__name__, modname, either, result)220 return result221 res = self.anytest(match)222 log.debug("Module %s in tests result: %s", module,res)223 return res224 211 225 212 def wantClass(self, cls, tests=None): … … 268 255 wanted = plug_wants 269 256 in_tests = self.fileInTests(tests)(dirname) 270 log.debug("wantDirectory wanted %s, in_tests %s", wanted, in_tests) 257 log.debug("wantDirectory %s wanted %s, in_tests %s", 258 dirname, wanted, in_tests) 271 259 return wanted and in_tests 272 260 … … 305 293 if plug_wants is not None: 306 294 wanted = plug_wants 307 return wanted or (pysrc and self.tests and in_tests) 295 result = wanted or (pysrc and in_tests) 296 log.debug("wantFile %s wanted %s pysrc %s in_tests %s", file, 297 wanted, pysrc, in_tests) 298 return result 308 299 309 300 def wantFunction(self, function, tests=None): … … 421 412 self.working_dir = working_dir 422 413 self.filename, self.module, self.call = split_test_name(name) 423 if not self.filename is None and not os.path.isabs(self.filename): 424 self.filename = os.path.abspath(os.path.join(working_dir, 425 self.filename)) 414 if self.filename is not None: 415 if (self.filename.endswith('.pyc') 416 or self.filename.endswith('.pyo')): 417 self.filename = self.filename[:-3] + 'py' 418 if not os.path.isabs(self.filename): 419 self.filename = os.path.abspath(os.path.join(working_dir, 420 self.filename)) 426 421 427 422 def __str__(self): … … 439 434 440 435 def matches_file(self, filename): 436 log.debug("matches_file? %s == %s", filename, self.filename) 441 437 fn = self.filename 442 438 if fn is None: … … 471 467 path fragment. This method should only be called when self.filename 472 468 is None. 473 """ 469 """ 473 469 mn = self.module 474 470 if mn is None: … … 477 473 # the only part we have defined is the call, which could be 478 474 # in any module 479 return True 475 return True 476 477 # Turn the module name into a path and compare against 478 # the filename, with the file extension and working_dir removed 480 479 mpath = os.path.sep.join(mn.split('.')) 481 return mpath in os.path.splitext(filename)[0] 480 base = os.path.splitext(filename)[0][len(self.working_dir):] 481 mod_match_re = re.compile(r'(^|/)%s(/|$)' % mpath) 482 result = mod_match_re.search(base) 483 return result 482 484 483 485 def matches_function(self, function): … … 498 500 match is valid only if module is a child of my module. 499 501 """ 500 pass 502 log.debug("Match module %s == %s?", module.__name__, self.module) 503 if self.module is None: 504 if self.filename is None: 505 # This test only has a callable part, so it could 506 # match a callable in any module 507 return True 508 return self.matches_module_as_file(module) 509 mname = module.__name__ 510 result = (subpackage_of(mname, self.module) or 511 (either and subpackage_of(self.module, mname))) 512 log.debug("Module %s match %s (either: %s) result %s", 513 module.__name__, self.module, either, result) 514 return result 515 516 def matches_module_as_file(self, module): 517 """Does this module match my filename property? The module name is 518 adjusted if it has been loaded from a .pyc or .pyo file, with the 519 extension replaced by .py. 520 """ 521 mod_file = module.__file__ 522 if mod_file.endswith('.pyc') or mod_file.endswith('.pyo'): 523 mod_file = mod_file[:-3] + 'py' 524 return self.matches_file(mod_file) 501 525 502 526 # Helpers 527 def match_all(*arg, **kw): 528 return True 503 529 504 530 def subpackage_of(modname, package): -
branches/new_loader/work.py
r119 r120 7 7 from nose.util import split_test_name 8 8 9 import logging 10 # logging.basicConfig() 11 # logging.getLogger('').setLevel(0) 9 #import logging 10 #logging.basicConfig() 11 #logging.getLogger('').setLevel(0) 12 12 13 13 conf = Config() … … 136 136 137 137 for filename in filenames: 138 if filename.endswith('.pyc') or filename.endswith('.pyo'): 139 continue 138 140 lname = os.path.join(dirpath, filename) 139 141 if selector.wantFile(lname, package=package, tests=tests): … … 188 190 #'test-dir' => 'support/test-dir/test.py' 189 191 #'test-dir/' => 'support/test-dir/test.py' 190 # 'test' => 'support/test.py', 'support/test-dir/test.py' -- not foo 192 #'test' => 'support/test.py' 193 # 'foo.bar' => 'support/foo/bar' * 191 194 192 195
