Former-commit-id:2b462d8665
[formerly133dc97f67
] [formerlya02aeb236c
] [formerlya02aeb236c
[formerly9f19e3f712
]] [formerly2b462d8665
[formerly133dc97f67
] [formerlya02aeb236c
] [formerlya02aeb236c
[formerly9f19e3f712
]] [formerly06a8b51d6d
[formerlya02aeb236c
[formerly9f19e3f712
] [formerly06a8b51d6d
[formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f]]]]] Former-commit-id:06a8b51d6d
Former-commit-id:2c3569dd39
[formerly9bb8decbcf
] [formerly8e80217e59
] [formerlye2ecdcfe33
[formerly377dcd10b9
] [formerly8e80217e59
[formerly3360eb6c5f
]]] Former-commit-id:e2ecdcfe33
[formerly377dcd10b9
] Former-commit-id:e2ecdcfe33
Former-commit-id:7dbd17a5aa
55 lines
1.7 KiB
Python
Executable file
55 lines
1.7 KiB
Python
Executable file
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
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|