Example #1
0
 def test_no_import_sideeffects(self):
   # A parser with no symbols registered.
   parser = LegacyPythonCallbacksParser(SymbolTable({}), BuildFileAliases(), build_file_imports_behavior='allow')
   # Call to import a module should succeed.
   parser.parse('/dev/null', b'''import os; os.path.join('x', 'y')''')
   # But the imported module should not be visible as a symbol in further parses.
   with self.assertRaises(NameError):
     parser.parse('/dev/null', b'''os.path.join('x', 'y')''')
Example #2
0
 def test_no_import_sideeffects(self) -> None:
     # A parser with no symbols registered.
     parser = LegacyPythonCallbacksParser(
         SymbolTable({}),
         BuildFileAliases(),
         build_file_imports_behavior=BuildFileImportsBehavior.warn,
     )
     # Call to import a module should succeed.
     parser.parse(
         "/dev/null",
         b"""import os; os.path.join('x', 'y')""",
         BuildFilePreludeSymbols(FrozenDict()),
     )
     # But the imported module should not be visible as a symbol in further parses.
     with self.assertRaises(NameError):
         parser.parse("/dev/null", b"""os.path.join('x', 'y')""",
                      BuildFilePreludeSymbols(FrozenDict()))