Index: test_frozen.py =================================================================== --- test_frozen.py (revision 54868) +++ test_frozen.py (working copy) @@ -1,27 +1,53 @@ # Test the frozen module defined in frozen.c. -from test.test_support import TestFailed -import sys, os +from test.test_support import TestFailed, run_unittest +import cStringIO +import sys +import unittest -try: - import __hello__ -except ImportError, x: - raise TestFailed, "import __hello__ failed:" + str(x) -try: - import __phello__ -except ImportError, x: - raise TestFailed, "import __phello__ failed:" + str(x) +class ImportTest(unittest.TestCase): + def setUp(self): + self.stdout = sys.stdout + sys.stdout = cStringIO.StringIO() + + def tearDown(self): + sys.stdout = self.stdout -try: - import __phello__.spam -except ImportError, x: - raise TestFailed, "import __phello__.spam failed:" + str(x) + def assertSaidHello(self): + sys.stdout.seek(0) + s = sys.stdout.getvalue() + self.assertEquals(s, "Hello world...\n") + + def assertHelloNotSaid(self): + sys.stdout.seek(0) + s = sys.stdout.getvalue() + self.assertEquals(s, "") + + def testModuleImport(self): + import __hello__ + self.assertSaidHello() -if sys.platform != "mac": # On the Mac this import does succeed. - try: - import __phello__.foo - except ImportError: - pass - else: - raise TestFailed, "import __phello__.foo should have failed" + def testPackageImport(self): + import __phello__ + self.assertHelloNotSaid() + + def testPackageModuleImport(self): + import __phello__.spam + self.assertSaidHello() + + def testImportNonexistentFunction(self): + if sys.platform == "mac": + import __phello__.foo + self.assertHelloNotSaid() + else: + try: + import __phello__.foo + except ImportError: + pass + else: + raise TestFailed, "import __phello__.foo should have failed" + + +if __name__ == "__main__": + run_unittest(ImportTest) \ No newline at end of file