2012-01-06 08:55:05 -06:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
import nose.config
|
|
|
|
import nose.importer
|
|
|
|
|
|
|
|
class TestImporter(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.p = sys.path[:]
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
sys.path = self.p[:]
|
|
|
|
|
|
|
|
def test_add_paths(self):
|
|
|
|
where = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
|
|
|
'support'))
|
|
|
|
foo = os.path.join(where, 'foo')
|
|
|
|
foobar = os.path.join(foo, 'bar')
|
|
|
|
nose.importer.add_path(foobar)
|
|
|
|
|
|
|
|
assert not foobar in sys.path
|
|
|
|
assert not foo in sys.path
|
|
|
|
assert where in sys.path
|
|
|
|
assert sys.path[0] == where, "%s first should be %s" % (sys.path, where)
|
|
|
|
|
|
|
|
def test_import(self):
|
|
|
|
where = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
|
|
|
'support'))
|
|
|
|
foo = os.path.join(where, 'foo')
|
|
|
|
foobar = os.path.join(foo, 'bar')
|
|
|
|
|
|
|
|
imp = nose.importer.Importer()
|
|
|
|
mod = imp.importFromDir(foobar, 'buz')
|
|
|
|
assert where in sys.path
|
|
|
|
# buz has an intra-package import that sets boodle
|
|
|
|
assert mod.boodle
|
|
|
|
|
|
|
|
def test_module_no_file(self):
|
|
|
|
where = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
|
|
|
'support'))
|
|
|
|
foo = os.path.join(where, 'foo')
|
|
|
|
foobar = os.path.join(foo, 'bar')
|
|
|
|
|
|
|
|
# something that's not a real module and has no __file__
|
|
|
|
sys.modules['buz'] = 'Whatever'
|
|
|
|
|
|
|
|
imp = nose.importer.Importer()
|
|
|
|
mod = imp.importFromDir(foobar, 'buz')
|
|
|
|
assert where in sys.path
|
|
|
|
# buz has an intra-package import that sets boodle
|
|
|
|
assert mod.boodle
|
python updates: cartopy, cycler, cython, h5py, nose, pil, pyparsing, pygtk, pycairo, pint, python-dateutil, scientific
Former-commit-id: be884288b7c3019d0df8001a16452a605314623d
2016-06-27 15:10:22 -05:00
|
|
|
|
|
|
|
def test_module_init_prefix(self):
|
|
|
|
where = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
|
|
|
'support', 'init_prefix_bug'))
|
|
|
|
nose.importer.add_path(where)
|
|
|
|
mod = os.path.join(where, '__init__not.py')
|
|
|
|
fqname = 'init_prefix_bug.__init__not'
|
|
|
|
|
|
|
|
imp = nose.importer.Importer()
|
|
|
|
mod = imp.importFromPath(mod, fqname)
|
2012-01-06 08:55:05 -06:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|