10c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi# Test the frozen module defined in frozen.c. 20c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 30c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yifrom test.test_support import captured_stdout, run_unittest 40c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yiimport unittest 50c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yiimport sys 60c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 70c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yiclass FrozenTests(unittest.TestCase): 80c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi def test_frozen(self): 90c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 100c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi with captured_stdout() as stdout: 110c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi try: 120c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi import __hello__ 130c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi except ImportError, x: 140c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi self.fail("import __hello__ failed:" + str(x)) 150c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 160c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi try: 170c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi import __phello__ 180c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi except ImportError, x: 190c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi self.fail("import __phello__ failed:" + str(x)) 200c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 210c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi try: 220c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi import __phello__.spam 230c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi except ImportError, x: 240c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi self.fail("import __phello__.spam failed:" + str(x)) 250c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 260c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi try: 270c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi import __phello__.foo 280c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi except ImportError: 290c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi pass 300c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi else: 310c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi self.fail("import __phello__.foo should have failed") 320c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 330c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi self.assertEqual(stdout.getvalue(), 340c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 'Hello world...\nHello world...\nHello world...\n') 350c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 360c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi del sys.modules['__hello__'] 370c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi del sys.modules['__phello__'] 380c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi del sys.modules['__phello__.spam'] 390c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 400c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 410c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yidef test_main(): 420c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi run_unittest(FrozenTests) 430c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 440c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 450c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi 460c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yiif __name__ == '__main__': 470c5958b1636c47ed7c284f859c8e805fd06a0e6Bill Yi test_main() 48