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
))
17 def test_compat(self
):
19 os
.path
.dirname(os
.path
.abspath(__file__
)),
20 'testpkg-compatmodule')
21 mf
= modulegraph
.ModuleGraph(path
=[ root
] + sys
.path
)
22 mf
.import_hook('pkg.api')
24 node
= mf
.findNode('pkg')
25 self
.assertIsInstance(node
, modulegraph
.Package
)
27 node
= mf
.findNode('pkg.api')
28 self
.assertIsInstance(node
, modulegraph
.SourceModule
)
30 if sys
.version_info
[0] == 2:
31 node
= mf
.findNode('pkg.api2')
32 self
.assertIsInstance(node
, modulegraph
.SourceModule
)
34 node
= mf
.findNode('pkg.api3')
35 self
.assertIsInstance(node
, modulegraph
.InvalidSourceModule
)
37 node
= mf
.findNode('http.client')
38 self
.assertIs(node
, None)
40 node
= mf
.findNode('urllib2')
41 self
.assertIsInstance(node
, modulegraph
.SourceModule
)
44 node
= mf
.findNode('pkg.api2')
45 self
.assertIsInstance(node
, modulegraph
.InvalidSourceModule
)
47 node
= mf
.findNode('pkg.api3')
48 self
.assertIsInstance(node
, modulegraph
.SourceModule
)
50 node
= mf
.findNode('http.client')
51 self
.assertIsInstance(node
, modulegraph
.SourceModule
)
53 node
= mf
.findNode('urllib2')
54 self
.assertIs(node
, None)
59 if __name__
== "__main__":