Changeset 86
- Timestamp:
- Tue Aug 8 12:23:39 2006
- Files:
-
- trunk/unit_tests/mock.py (modified) (diff)
- trunk/unit_tests/test_loader.py (modified) (diff)
- trunk/unit_tests/test_selector.py (modified) (diff)
- trunk/unit_tests/support/pkgorg (added)
- trunk/unit_tests/support/pkgorg/tests (added)
- trunk/unit_tests/support/pkgorg/tests/test_mod.py (added)
- trunk/unit_tests/support/pkgorg/lib (added)
- trunk/unit_tests/support/pkgorg/lib/modernity.py (added)
- trunk/nose/core.py (modified) (diff)
- trunk/nose/suite.py (modified) (diff)
- trunk/nose/selector.py (modified) (diff)
- trunk/nose/importer.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/unit_tests/mock.py
r21 r86 26 26 def __init__(self, name, **kw): 27 27 self.__name__ = name 28 if 'file' in kw: 29 self.__file__ = kw.pop('file') 30 else: 31 if 'path' in kw: 32 path = kw.pop('path') 33 else: 34 path = '' 35 self.__file__ = "%s/%s.pyc" % (path, name.replace('.', '/')) 36 self.__path__ = [ self.__file__ ] # FIXME? 28 37 self.__dict__.update(kw) 38 39 40 class Result(object): 41 def __init__(self): 42 from nose.result import Result 43 import types 44 self.errors = [] 45 for attr in dir(Result): 46 if type(getattr(Result, attr)) is types.MethodType: 47 if not hasattr(self, attr): 48 setattr(self, attr, lambda s, *a, **kw: None) 49 elif not attr.startswith('__'): 50 setattr(self, attr, None) 51 52 def addError(self, test, err): 53 self.errors.append(err) -
trunk/unit_tests/test_loader.py
r80 r86 228 228 assert not m.test_func_not_really in sel.funcs 229 229 assert len(sel.funcs) == 1 230 231 def test_pkg_layout_lib_tests(self): 232 from mock import Result 233 r = Result() 234 l = loader.TestLoader() 235 where = os.path.join(os.path.dirname(__file__), 'support/pkgorg') 236 print "where", where 237 print "on path?", where + '/lib' in sys.path 238 tests = l.loadTestsFromDir(where) 239 print "on path?", where + '/lib' in sys.path 240 print "tests", tests 241 for t in tests: 242 print "test", t 243 assert t(r), "No tests loaded: %s" % r.errors 244 assert where + '/lib' in sys.path 230 245 231 246 if __name__ == '__main__': -
trunk/unit_tests/test_selector.py
r81 r86 6 6 from nose.selector import log, Selector 7 7 from nose.util import absdir 8 9 class Mod: 10 def __init__(self, name): 11 self.__name__ = name 8 from mock import Mod 12 9 13 10 class TestSelector(unittest.TestCase): … … 159 156 def test_want_file(self): 160 157 c = Config() 161 c.where = absdir(os.path.join(os.path.dirname(__file__), 'support'))158 c.where = [absdir(os.path.join(os.path.dirname(__file__), 'support'))] 161 158 s = Selector(c) 162 159 … … 352 349 assert not s.moduleInTests(f_e) 353 350 assert not s.moduleInTests(f_e, True) 351 352 def test_module_in_tests_file(self): 353 base = absdir(os.path.join(os.path.dirname(__file__), 'support')) 354 c = Config() 355 c.where = [base] 356 s = Selector(c) 357 358 f = Mod('foo', file=base+'/foo/__init__.pyc') 359 t = Mod('test', path=base) 360 f_t_f = Mod('foo.test_foo', path=base) 361 d_t_t = Mod('test', path=base+'/test-dir') 362 363 s.tests = [ 'test.py' ] 364 assert not s.moduleInTests(f) 365 assert s.moduleInTests(t) 366 assert not s.moduleInTests(f_t_f) 367 assert not s.moduleInTests(d_t_t) 368 369 s.tests = [ 'foo/' ] 370 assert s.moduleInTests(f) 371 assert s.moduleInTests(f_t_f) 372 assert not s.moduleInTests(t) 373 assert not s.moduleInTests(d_t_t) 374 375 s.tests = [ 'foo/test_foo.py' ] 376 assert not s.moduleInTests(f) 377 assert s.moduleInTests(f_t_f) 378 assert not s.moduleInTests(t) 379 assert not s.moduleInTests(d_t_t) 380 381 s.tests = [ 'test-dir/test.py' ] 382 assert not s.moduleInTests(f) 383 assert not s.moduleInTests(t) 384 assert not s.moduleInTests(f_t_f) 385 assert s.moduleInTests(d_t_t) 386 387 354 388 355 389 if __name__ == '__main__': -
trunk/nose/core.py
r77 r86 370 370 conf.where = [] 371 371 for path in tolist(options.where): 372 log.debug('Adding %s as nose working directory', path) 372 373 abs_path = absdir(path) 373 374 if abs_path is None: -
trunk/nose/suite.py
r83 r86 188 188 the test package or module will be passed to the setup function. 189 189 """ 190 log.debug('TestModule.setUp') 190 191 if self.module is None: 191 192 self.module = _import(self.moduleName, [self.path], self.conf) 192 193 log.debug('Imported %s from %s on %s', self.module, 194 self.moduleName, self.path) 193 195 if hasattr(self.module, '__path__'): 194 196 names = ['setupPackage', 'setUpPackage', 'setup_package'] -
trunk/nose/selector.py
r82 r86 69 69 return False 70 70 return True 71 def match(filename, modname, funcname, file=file):72 if filename is None:73 if modname is None:74 return None75 # be liberal... could this file possibly be this module?76 # return None if the module name, converted to a file77 # path, matches any part of the full filename78 mpath = os.path.sep.join(modname.split('.'))79 log.debug("Is module path %s in file %s?", mpath, file)80 if mpath in file:81 return None82 else:83 return False84 if not os.path.isabs(filename):85 filename = absfile(filename, self.conf.working_dir)86 return filename == file87 71 log.debug('Check file in tests') 72 def match(filename, modname, funcname, file=file): 73 return self.filematch(filename, modname, funcname, file) 88 74 return self.anytest(match) 89 75 76 def filematch(self, filename, modname, funcname, file): 77 log.debug("Filematch (%s, %s, %s, %s)", 78 filename, modname, funcname, file) 79 if filename is None: 80 if modname is None: 81 return None 82 # be liberal... could this file possibly be this module? 83 # return None if the module name, converted to a file 84 # path, matches any part of the full filename 85 mpath = os.path.sep.join(modname.split('.')) 86 log.debug("Is module path %s in file %s?", mpath, file) 87 if mpath in file: 88 return None 89 else: 90 return False 91 if not os.path.isabs(filename): 92 filename = absfile(filename, self.conf.working_dir) 93 log.debug("Abs match file: %s", filename) 94 95 # A file is a match if it is an exact match, or if 96 # the filename to match against is a directory (or package init file) 97 # and the file appears to be under that directory. Files that 98 # don't exist can't match. 99 if filename is None: 100 return False 101 102 if filename.endswith('__init__.py'): 103 dirname = os.path.dirname(filename) 104 elif os.path.isdir(filename): 105 dirname = filename 106 else: 107 dirname = None 108 109 log.debug("Files are same: %s", filename == file) 110 log.debug("Dirname: %s", dirname) 111 if dirname is not None: 112 log.debug("File startswith dirname: %s", file.startswith(dirname)) 113 log.debug("File has sep at end of dirname: %s == %s", 114 file[len(dirname)], os.path.sep) 115 116 return filename == file \ 117 or (dirname is not None 118 and file.startswith(dirname) 119 and file[len(dirname)] == os.path.sep) 120 90 121 def funcInTests(self, func): 91 122 def match(filename, modname, funcname, func=func): … … 129 160 module.__name__, modname, funcname, either) 130 161 if modname is None: 131 return None 162 if filename is None: 163 return None 164 mod_file = module.__file__ 165 if mod_file.endswith('.pyc') or mod_file.endswith('.pyo'): 166 mod_file = mod_file[:-3] + 'py' 167 log.debug("Checking module file %s against filename %s", 168 mod_file, filename) 169 return self.filematch(filename, modname, funcname, 170 file=mod_file) 132 171 mname = module.__name__ 133 172 result = (subpackage_of(mname, modname) or … … 137 176 return result 138 177 res = self.anytest(match) 139 log.debug("Module %s in tests result: %s", module .__name__,res)178 log.debug("Module %s in tests result: %s", module,res) 139 178 return res 140 179 -
trunk/nose/importer.py
r62 r86 94 94 else: 95 95 del sys.modules[fqname] 96 log.debug("Loading %s from %s", fqname, filename) 96 97 mod = load_module(fqname, fh, filename, desc) 98 log.debug("%s from %s yields %s", fqname, filename, mod) 97 99 cache[fqname] = mod 98 100 finally:
