Changeset 76
- Timestamp:
- Wed Jul 12 20:22:44 2006
- Files:
-
- trunk/unit_tests/test_utils.py (modified) (diff)
- trunk/unit_tests/test_plugins.py (modified) (diff)
- trunk/nose/core.py (modified) (diff)
- trunk/nose/plugins/doctests.py (modified) (diff)
- trunk/nose/plugins/base.py (modified) (diff)
- trunk/nose/plugins/cover.py (modified) (diff)
- trunk/nose/plugins/attrib.py (modified) (diff)
- trunk/nose/plugins/prof.py (modified) (diff)
- trunk/nose/util.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/unit_tests/test_utils.py
r29 r76 88 88 self.assertEqual(nose.test_address(foo_mtc), 89 89 (me, __name__, 'Foo.bar')) 90 91 def test_tolist(self): 92 from nose.util import tolist 93 assert tolist('foo') == ['foo'] 94 assert tolist(['foo', 'bar']) == ['foo', 'bar'] 95 assert tolist('foo,bar') == ['foo', 'bar'] 96 self.assertEqual(tolist('.*foo/.*,.1'), ['.*foo/.*', '.1']) 97 98 90 99 if __name__ == '__main__': 91 100 unittest.main() -
trunk/unit_tests/test_plugins.py
r70 r76 89 89 assert plug.enabled 90 90 91 def test_tolist(self):92 plug = P()93 assert plug.tolist('foo') == ['foo']94 assert plug.tolist(['foo', 'bar']) == ['foo', 'bar']95 assert plug.tolist('foo,bar') == ['foo', 'bar']96 self.assertEqual(plug.tolist('.*foo/.*,.1'), ['.*foo/.*', '.1'])97 91 98 92 class TestDoctestPlugin(unittest.TestCase): -
trunk/nose/core.py
r75 r76 16 16 from nose.result import Result 17 17 from nose.suite import LazySuite 18 from nose.util import absdir 18 from nose.util import absdir, tolist 18 18 from nose.importer import add_path 19 19 … … 38 38 39 39 def loadtests(self): 40 for test in self.loader.loadTestsFromDir(self.path): 41 yield test 40 for path in tolist(self.path): 41 for test in self.loader.loadTestsFromDir(path): 42 yield test 42 43 43 44 def __repr__(self): … … 262 263 parser.add_option("-q", "--quiet", action="store_const", 263 264 const=0, dest="verbosity") 264 parser.add_option("-w", "--where", action="store", dest="where", 265 default=env.get('NOSE_WHERE', os.getcwd()), 265 parser.add_option("-w", "--where", action="append", dest="where", 266 266 help="Look for tests in this directory [NOSE_WHERE]") 267 267 parser.add_option("-e", "--exclude", action="store", dest="exclude", … … 336 336 sys.exit(0) 337 337 338 # where is an append action, so it can't have a default value 339 # in the parser, or that default will always be in the list 340 if not options.where: 341 options.where = env.get('NOSE_WHERE', os.getcwd()) 342 338 343 configure_logging(options) 339 344 … … 363 368 364 369 if options.where is not None: 365 conf.where = absdir(options.where) 366 if conf.where is None: 367 raise Exception("Working directory %s not found, or " 368 "not a directory" % options.where) 369 log.info("Looking for tests in %s", conf.where) 370 if conf.addPaths and \ 371 os.path.exists(os.path.join(conf.where, '__init__.py')): 372 log.info("Working directory is a package; adding to sys.path") 373 add_path(conf.where) 370 conf.where = [] 371 for path in tolist(options.where): 372 abs_path = absdir(path) 373 if abs_path is None: 374 raise ValueError("Working directory %s not found, or " 375 "not a directory" % path) 376 conf.where.append(abs_path) 377 log.info("Looking for tests in %s", abs_path) 378 if conf.addPaths and \ 379 os.path.exists(os.path.join(abs_path, '__init__.py')): 380 log.info("Working directory %s is a package; " 381 "adding to sys.path" % abs_path) 382 add_path(abs_path) 374 383 375 384 if options.include: -
trunk/nose/plugins/doctests.py
r70 r76 19 19 import os 20 20 from nose.plugins.base import Plugin 21 from nose.util import anyp 21 from nose.util import anyp, tolist 21 21 22 22 log = logging.getLogger(__name__) … … 51 51 self.doctest_tests = options.doctest_tests 52 52 try: 53 self.extension = self.tolist(options.doctestExtension)53 self.extension = tolist(options.doctestExtension) 53 53 except AttributeError: 54 54 # 2.3, no other-file option -
trunk/nose/plugins/base.py
r29 r76 2 2 import re 3 3 import textwrap 4 from nose.util import tolist 4 5 5 6 class Plugin(object): … … 64 65 return "(no help available)" 65 66 67 # Compatiblity shim 66 68 def tolist(self, val): 67 # might already be a list 68 if val is None: 69 return None 70 try: 71 val.extend([]) 72 return val 73 except AttributeError: 74 pass 75 # might be a string 76 try: 77 return re.split(r'\s*,\s*', val) 78 except TypeError: 79 # who knows... 80 return list(val) 81 69 from warnings import warn 70 warn("Plugin.tolist is deprecated. Use nose.util.tolist instead", 71 DeprecationWarning) 72 return tolist(val) 82 73 83 74 class IPluginInterface(object): -
trunk/nose/plugins/cover.py
r70 r76 15 15 import sys 16 16 from nose.plugins.base import Plugin 17 from nose.util import tolist 17 18 18 19 log = logging.getLogger(__name__) … … 63 64 self.coverErase = options.cover_erase 64 65 self.coverTests = options.cover_tests 65 self.coverPackages = self.tolist(options.cover_packages)66 self.coverPackages = tolist(options.cover_packages) 65 66 if self.coverPackages: 66 67 log.info("Coverage report will include only packages: %s", -
trunk/nose/plugins/attrib.py
r62 r76 33 33 34 34 from nose.plugins.base import Plugin 35 from nose.util import tolist 35 36 36 37 pyvrs = sys.version_info … … 83 84 # handle python eval-expression parameter 84 85 if compat_24 and options.eval_attr: 85 eval_attr = self.tolist(options.eval_attr)86 eval_attr = tolist(options.eval_attr) 85 86 for attr in eval_attr: 86 87 # "<python expression>" … … 94 95 # 'key=value' pairs 95 96 if options.attr: 96 std_attr = self.tolist(options.attr)97 std_attr = tolist(options.attr) 96 97 for attr in std_attr: 97 98 # all attributes within an attribute group must match -
trunk/nose/plugins/prof.py
r62 r76 14 14 import tempfile 15 15 from nose.plugins.base import Plugin 16 from nose.util import tolist 16 17 17 18 log = logging.getLogger('nose.plugins') … … 54 55 self.pfile = filename 55 56 self.sort = options.profile_sort 56 self.restrict = self.tolist(options.profile_restrict)57 self.restrict = tolist(options.profile_restrict) 56 57 57 58 def prepareTest(self, test): -
trunk/nose/util.py
r30 r76 30 30 return path 31 31 32 32 33 def absfile(path, where=None): 33 34 """Return absolute, normalized path to file (optionally in directory … … 56 57 return None 57 58 59 58 60 def anyp(predicate, iterable): 59 61 for item in iterable: … … 62 64 return False 63 65 66 64 67 def file_like(name): 65 68 return os.path.dirname(name) or name.endswith('.py') 66 69 70 67 71 def is_generator(func): 68 72 try: … … 71 75 return False 72 76 77 73 78 def split_test_name(test): 74 79 """Split a test name into a 3-tuple containing file, module, and callable … … 113 118 return (None, None, fn) 114 119 120 115 121 def test_address(test): 116 122 """Find the test address for a test, which may be a module, filename, … … 151 157 raise TypeError("I don't know what %s is (%s)" % (test, t)) 152 158 159 153 160 def try_run(obj, names): 154 161 """Given a list of possible method names, try to run them with the … … 167 174 log.debug("call fixture %s.%s", obj, name) 168 175 return func() 169 176 177 178 def tolist(val): 179 """Convert a value that may be a list or a (possibly comma-separated) 180 string into a list. The exception: None is returned as None, not [None]. 181 """ 182 if val is None: 183 return None 184 try: 185 # might already be a list 186 val.extend([]) 187 return val 188 except AttributeError: 189 pass 190 # might be a string 191 try: 192 return re.split(r'\s*,\s*', val) 193 except TypeError: 194 # who knows... 195 return list(val)
