Home | History | Annotate | Download | only in test
      1 # Test the frozen module defined in frozen.c.
      2 
      3 from test.test_support import captured_stdout, run_unittest
      4 import unittest
      5 import sys
      6 
      7 class FrozenTests(unittest.TestCase):
      8     def test_frozen(self):
      9 
     10         with captured_stdout() as stdout:
     11             try:
     12                 import __hello__
     13             except ImportError, x:
     14                 self.fail("import __hello__ failed:" + str(x))
     15 
     16             try:
     17                 import __phello__
     18             except ImportError, x:
     19                 self.fail("import __phello__ failed:" + str(x))
     20 
     21             try:
     22                 import __phello__.spam
     23             except ImportError, x:
     24                 self.fail("import __phello__.spam failed:" + str(x))
     25 
     26             try:
     27                 import __phello__.foo
     28             except ImportError:
     29                 pass
     30             else:
     31                 self.fail("import __phello__.foo should have failed")
     32 
     33         self.assertEqual(stdout.getvalue(),
     34                          'Hello world...\nHello world...\nHello world...\n')
     35 
     36         del sys.modules['__hello__']
     37         del sys.modules['__phello__']
     38         del sys.modules['__phello__.spam']
     39 
     40 
     41 def test_main():
     42     run_unittest(FrozenTests)
     43 
     44 
     45 
     46 if __name__ == '__main__':
     47     test_main()
     48