5 from modulegraph
import modulegraph
7 class ImpliesTestCase(unittest
.TestCase
):
8 if not hasattr(unittest
.TestCase
, 'assertIsInstance'):
9 def assertIsInstance(self
, object, types
, message
=None):
10 self
.assertTrue(isinstance(object, types
),
11 message
or '%r is not an instance of %r'%(object, types
))
13 def testBasicImplies(self
):
15 os
.path
.dirname(os
.path
.abspath(__file__
)),
18 # First check that 'syslog' isn't accidently in the graph:
19 mg
= modulegraph
.ModuleGraph(path
=[root
]+sys
.path
)
20 mg
.run_script(os
.path
.join(root
, 'script.py'))
21 node
= mg
.findNode('mod')
22 self
.assertIsInstance(node
, modulegraph
.SourceModule
)
24 node
= mg
.findNode('syslog')
25 self
.assertEqual(node
, None)
27 # Now check that adding an implied dependency actually adds
28 # 'syslog' to the graph:
29 mg
= modulegraph
.ModuleGraph(path
=[root
]+sys
.path
, implies
={
31 self
.assertEqual(node
, None)
32 mg
.run_script(os
.path
.join(root
, 'script.py'))
33 node
= mg
.findNode('mod')
34 self
.assertIsInstance(node
, modulegraph
.SourceModule
)
36 node
= mg
.findNode('syslog')
37 self
.assertIsInstance(node
, modulegraph
.Extension
)
39 # Check that the edges are correct:
40 self
.assertTrue(mg
.findNode('mod') in mg
.get_edges(node
)[1])
41 self
.assertTrue(node
in mg
.get_edges(mg
.findNode('mod'))[0])
43 def testPackagedImplies(self
):
45 os
.path
.dirname(os
.path
.abspath(__file__
)),
48 # First check that 'syslog' isn't accidently in the graph:
49 mg
= modulegraph
.ModuleGraph(path
=[root
]+sys
.path
)
50 mg
.run_script(os
.path
.join(root
, 'script.py'))
51 node
= mg
.findNode('mod')
52 self
.assertIsInstance(node
, modulegraph
.SourceModule
)
54 node
= mg
.findNode('syslog')
55 self
.assertEqual(node
, None)
58 # Now check that adding an implied dependency actually adds
59 # 'syslog' to the graph:
60 mg
= modulegraph
.ModuleGraph(path
=[root
]+sys
.path
, implies
={
61 'pkg.relative': ['syslog']})
62 node
= mg
.findNode('syslog')
63 self
.assertEqual(node
, None)
65 mg
.run_script(os
.path
.join(root
, 'script.py'))
66 node
= mg
.findNode('pkg.relative')
67 self
.assertIsInstance(node
, modulegraph
.SourceModule
)
69 node
= mg
.findNode('syslog')
70 self
.assertIsInstance(node
, modulegraph
.Extension
)
72 # Check that the edges are correct:
73 self
.assertTrue(mg
.findNode('pkg.relative') in mg
.get_edges(node
)[1])
74 self
.assertTrue(node
in mg
.get_edges(mg
.findNode('pkg.relative'))[0])
77 if __name__
== '__main__':