Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / tools / telemetry / third_party / modulegraph / modulegraph_tests / test_relimport2.py
blob0a465a28075c4e0f504cd1449b5fa5023f1be759
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 setUp(self):
18 self.root = os.path.join(
19 os.path.dirname(os.path.abspath(__file__)),
20 'testpkg-relimport2')
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__":
45 unittest.main()