blob: 771f5999742daa0ca854dcceb89530ab2b1caead [file] [log] [blame]
Guido van Rossum4114a4a2001-10-18 18:49:37 +00001# Test the frozen module defined in frozen.c.
2
Georg Brandl692bbc42007-08-24 18:22:54 +00003from test.test_support import captured_stdout, run_unittest
4import unittest
Georg Brandla4f46e12010-02-07 17:03:15 +00005import sys
Guido van Rossum4114a4a2001-10-18 18:49:37 +00006
Georg Brandl692bbc42007-08-24 18:22:54 +00007class FrozenTests(unittest.TestCase):
8 def test_frozen(self):
Guido van Rossum4114a4a2001-10-18 18:49:37 +00009
Georg Brandl692bbc42007-08-24 18:22:54 +000010 with captured_stdout() as stdout:
11 try:
12 import __hello__
13 except ImportError, x:
14 self.fail("import __hello__ failed:" + str(x))
Guido van Rossum4114a4a2001-10-18 18:49:37 +000015
Georg Brandl692bbc42007-08-24 18:22:54 +000016 try:
17 import __phello__
18 except ImportError, x:
19 self.fail("import __phello__ failed:" + str(x))
Guido van Rossum4114a4a2001-10-18 18:49:37 +000020
Georg Brandl692bbc42007-08-24 18:22:54 +000021 try:
22 import __phello__.spam
23 except ImportError, x:
24 self.fail("import __phello__.spam failed:" + str(x))
25
Ronald Oussoren9545a232010-05-05 19:09:31 +000026 try:
27 import __phello__.foo
28 except ImportError:
29 pass
30 else:
31 self.fail("import __phello__.foo should have failed")
Georg Brandl692bbc42007-08-24 18:22:54 +000032
Ezio Melotti2623a372010-11-21 13:34:58 +000033 self.assertEqual(stdout.getvalue(),
34 'Hello world...\nHello world...\nHello world...\n')
Georg Brandl692bbc42007-08-24 18:22:54 +000035
Amaury Forgeot d'Arc607bff12008-04-18 23:31:33 +000036 del sys.modules['__hello__']
37 del sys.modules['__phello__']
38 del sys.modules['__phello__.spam']
39
Georg Brandl692bbc42007-08-24 18:22:54 +000040
41def test_main():
42 run_unittest(FrozenTests)
Brett Cannon8820f2a2008-04-01 12:46:02 +000043
44
45
46if __name__ == '__main__':
47 test_main()