def trace_module(import_line): root_pt = tracer.init_stack() root_pt.import_line = "exec(%s)" % import_line with tracer.patch_import(): with root_pt: exec(import_line) return root_pt
def test__traceit_from_import(self): tr_pt = tracer.init_stack() with tracer.patch_import(): exec("from os import sys") self.assertEqual(1, len(tr_pt.children)) self.assertEqual("from os import sys", tr_pt.children[0].import_line)
def test__traceit(self): tr_pt = tracer.init_stack() with tracer.patch_import(): exec("import re") self.assertEqual(1, len(tr_pt.children)) self.assertEqual("import re", tr_pt.children[0].import_line) self.assertIsNotNone(tr_pt.children[0].filepath)
def test_patch_import(self, mock_traceit): normal_import = builtins.__import__ with tracer.patch_import(): self.assertEqual(mock_traceit.return_value, builtins.__import__) self.assertNotEqual(normal_import, builtins.__import__) self.assertEqual(normal_import, builtins.__import__)