/
usr
/
lib
/
python2.6
/
site-packages
/
nose
/
/usr/lib/python2.6/site-packages/nose
mkdir
upload
Name
Size
Mode
Actions
ext/
-
0755
rm
plugins/
-
0755
rm
case.py
12508
0644
edit
dl
rm
case.pyc
14282
0644
edit
dl
rm
case.pyo
14282
0644
edit
dl
rm
commands.py
4570
0644
edit
dl
rm
commands.pyc
5003
0644
edit
dl
rm
commands.pyo
5003
0644
edit
dl
rm
config.py
20203
0644
edit
dl
rm
config.pyc
19890
0644
edit
dl
rm
config.pyo
19890
0644
edit
dl
rm
core.py
17175
0644
edit
dl
rm
core.pyc
17549
0644
edit
dl
rm
core.pyo
17549
0644
edit
dl
rm
exc.py
376
0644
edit
dl
rm
exc.pyc
576
0644
edit
dl
rm
exc.pyo
576
0644
edit
dl
rm
failure.py
850
0644
edit
dl
rm
failure.pyc
1367
0644
edit
dl
rm
failure.pyo
1367
0644
edit
dl
rm
importer.py
5490
0644
edit
dl
rm
importer.pyc
5094
0644
edit
dl
rm
importer.pyo
5094
0644
edit
dl
rm
inspector.py
6904
0644
edit
dl
rm
inspector.pyc
5925
0644
edit
dl
rm
inspector.pyo
5925
0644
edit
dl
rm
loader.py
21437
0644
edit
dl
rm
loader.pyc
16080
0644
edit
dl
rm
loader.pyo
16080
0644
edit
dl
rm
proxy.py
5840
0644
edit
dl
rm
proxy.pyc
7327
0644
edit
dl
rm
proxy.pyo
7120
0644
edit
dl
rm
result.py
5849
0644
edit
dl
rm
result.pyc
5913
0644
edit
dl
rm
result.pyo
5913
0644
edit
dl
rm
selector.py
9003
0644
edit
dl
rm
selector.pyc
8876
0644
edit
dl
rm
selector.pyo
8876
0644
edit
dl
rm
suite.py
18693
0644
edit
dl
rm
suite.pyc
18663
0644
edit
dl
rm
suite.pyo
18663
0644
edit
dl
rm
tools.py
5023
0644
edit
dl
rm
tools.pyc
7209
0644
edit
dl
rm
tools.pyo
7129
0644
edit
dl
rm
twistedtools.py
5268
0644
edit
dl
rm
twistedtools.pyc
5815
0644
edit
dl
rm
twistedtools.pyo
5815
0644
edit
dl
rm
util.py
19275
0644
edit
dl
rm
util.pyc
20125
0644
edit
dl
rm
util.pyo
20125
0644
edit
dl
rm
__init__.py
14985
0644
edit
dl
rm
__init__.pyc
15283
0644
edit
dl
rm
__init__.pyo
15283
0644
edit
dl
rm
Edit:
/usr/lib/python2.6/site-packages/nose/importer.py
(5490B)
"""Implements an importer that looks only in specific path (ignoring sys.path), and uses a per-path cache in addition to sys.modules. This is necessary because test modules in different directories frequently have the same names, which means that the first loaded would mask the rest when using the builtin importer. """ import logging import os import sys from nose.config import Config from imp import find_module, load_module, acquire_lock, release_lock log = logging.getLogger(__name__) class Importer(object): """An importer class that does only path-specific imports. That is, the given module is not searched for on sys.path, but only at the path or in the directory specified. """ def __init__(self, config=None): if config is None: config = Config() self.config = config def importFromPath(self, path, fqname): """Import a dotted-name package whose tail is at path. In other words, given foo.bar and path/to/foo/bar.py, import foo from path/to/foo then bar from path/to/foo/bar, returning bar. """ # find the base dir of the package path_parts = os.path.normpath(os.path.abspath(path)).split(os.sep) name_parts = fqname.split('.') if path_parts[-1].startswith('__init__'): path_parts.pop() path_parts = path_parts[:-(len(name_parts))] dir_path = os.sep.join(path_parts) # then import fqname starting from that dir return self.importFromDir(dir_path, fqname) def importFromDir(self, dir, fqname): """Import a module *only* from path, ignoring sys.path and reloading if the version in sys.modules is not the one we want. """ dir = os.path.normpath(os.path.abspath(dir)) log.debug("Import %s from %s", fqname, dir) # FIXME reimplement local per-dir cache? # special case for __main__ if fqname == '__main__': return sys.modules[fqname] if self.config.addPaths: add_path(dir, self.config) path = [dir] parts = fqname.split('.') part_fqname = '' mod = parent = fh = None for part in parts: if part_fqname == '': part_fqname = part else: part_fqname = "%s.%s" % (part_fqname, part) try: acquire_lock() log.debug("find module part %s (%s) in %s", part, part_fqname, path) fh, filename, desc = find_module(part, path) old = sys.modules.get(part_fqname) if old is not None: # test modules frequently have name overlap; make sure # we get a fresh copy of anything we are trying to load # from a new path log.debug("sys.modules has %s as %s", part_fqname, old) if self.sameModule(old, filename): mod = old else: del sys.modules[part_fqname] mod = load_module(part_fqname, fh, filename, desc) else: mod = load_module(part_fqname, fh, filename, desc) finally: if fh: fh.close() release_lock() if parent: setattr(parent, part, mod) if hasattr(mod, '__path__'): path = mod.__path__ parent = mod return mod def sameModule(self, mod, filename): mod_paths = [] if hasattr(mod, '__path__'): for path in mod.__path__: mod_paths.append(os.path.dirname( os.path.normpath( os.path.abspath(path)))) elif hasattr(mod, '__file__'): mod_paths.append(os.path.dirname( os.path.normpath( os.path.abspath(mod.__file__)))) else: # builtin or other module-like object that # doesn't have __file__; must be new return False new_path = os.path.dirname(os.path.normpath(filename)) for mod_path in mod_paths: log.debug( "module already loaded? mod: %s new: %s", mod_path, new_path) if mod_path == new_path: return True return False def add_path(path, config=None): """Ensure that the path, or the root of the current package (if path is in a package) is in sys.path. """ # FIXME add any src-looking dirs seen too... need to get config for that log.debug('Add path %s' % path) if not path: return [] added = [] parent = os.path.dirname(path) if (parent and os.path.exists(os.path.join(path, '__init__.py'))): added.extend(add_path(parent, config)) elif not path in sys.path: log.debug("insert %s into sys.path", path) sys.path.insert(0, path) added.append(path) if config and config.srcDirs: for dirname in config.srcDirs: dirpath = os.path.join(path, dirname) if os.path.isdir(dirpath): sys.path.insert(0, dirpath) added.append(dirpath) return added def remove_path(path): log.debug('Remove path %s' % path) if path in sys.path: sys.path.remove(path)
Save
cmd:
run