2 Test for import machinery
9 from modulegraph
import modulegraph
11 class TestModuleGraphImport (unittest
.TestCase
):
12 if not hasattr(unittest
.TestCase
, 'assertIsInstance'):
13 def assertIsInstance(self
, value
, types
):
14 if not isinstance(value
, types
):
15 self
.fail("%r is not an instance of %r"%(value
, types
))
18 self
.root
= os
.path
.join(
19 os
.path
.dirname(os
.path
.abspath(__file__
)),
21 self
.mf
= modulegraph
.ModuleGraph(path
=[ self
.root
] + sys
.path
)
24 def test_init_as_script(self
):
25 self
.mf
.run_script(os
.path
.join(self
.root
, 'pkg/__init__.py'))
26 n
= self
.mf
.findNode('mod1')
27 self
.assertIs(n
, None)
29 n
= self
.mf
.findNode('mod2')
30 self
.assertIsInstance(n
, modulegraph
.MissingModule
)
32 def test_subpkg_bad_import(self
):
33 self
.mf
.import_hook('pkg.sub')
35 n
= self
.mf
.findNode('toplevel')
36 self
.assertIs(n
, None)
38 n
= self
.mf
.findNode('pkg.mod1')
39 self
.assertIsInstance(n
, modulegraph
.SourceModule
)
41 n
= self
.mf
.findNode('pkg.mod3')
42 self
.assertIsInstance(n
, modulegraph
.SourceModule
)
44 if __name__
== "__main__":