def test_import_hook (self): myimporter = myimport.MythonImporter # Other tests may install the import hook, so make sure it isn't there. if myimporter in sys.meta_path: if __debug__: sys.stderr.write("\n\nWarning in test_import_hook(): the " "MythonImporter hook is already installed. " "Uninstalling.\n\n") sys.meta_path.remove(myimporter) self.assert_(myimporter not in sys.meta_path) self.failUnlessRaises(ImportError, self._import_test04) myimport.install_import_hook() self.assert_(myimporter in sys.meta_path) stdout = sys.stdout txtbuf = StringIO.StringIO() sys.stdout = txtbuf self.assert_(self._import_test04()) sys.stdout = stdout test_output = txtbuf.getvalue() is_compiling = "compile" in test_output if __debug__: print(test_output) self.assert_(is_compiling) sys.meta_path.remove(myimporter) self.assert_(myimporter not in sys.meta_path)
def test_import_hook (self): self.failUnlessRaises(ImportError, self._import_test04) myimport.install_import_hook() stdout = sys.stdout txtbuf = StringIO.StringIO() sys.stdout = txtbuf self.assert_(self._import_test04()) sys.stdout = stdout test_output = txtbuf.getvalue() is_compiling = "compile" in test_output if __debug__: print test_output self.assert_(is_compiling) sys.meta_path.remove(myimport.MythonImporter)
# ______________________________________________________________________ """test_regex.py Unit tests for the basil.lang.regex module. Jonathan Riehl """ # ______________________________________________________________________ # Module imports import os import dis import unittest from basil.lang.mython.MyFrontUtils import toplevel_compile from basil.lang.mython import myimport myimport.install_import_hook() # ______________________________________________________________________ # Test case definitions class TestMythonRegex (unittest.TestCase): def _getmyre0 (self): mython_module_path = os.path.join(os.path.split(__file__)[0], "test_regex01.my") module_co, _ = toplevel_compile(mython_module_path) if __debug__: dis.dis(module_co) exec module_co return myre0