Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / tools / telemetry / third_party / modulegraph / modulegraph_tests / test_pycompat_pkg.py
blobb5dcdb7c63f99c16e5249c25c066885f38fcf1ee
1 """
2 Test for import machinery
3 """
4 import unittest
5 import sys
6 import textwrap
7 import subprocess
8 import os
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):
18 root = os.path.join(
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)
43 else:
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__":
60 unittest.main()