blob: 4835e475f859e86bcb71e57469c2ba23ac20525c [file] [log] [blame]
Guido van Rossum4114a4a2001-10-18 18:49:37 +00001# Test the frozen module defined in frozen.c.
Georg Brandl692bbc42007-08-24 18:22:54 +00002from __future__ import with_statement
Guido van Rossum4114a4a2001-10-18 18:49:37 +00003
Georg Brandl692bbc42007-08-24 18:22:54 +00004from test.test_support import captured_stdout, run_unittest
5import unittest
Guido van Rossum4114a4a2001-10-18 18:49:37 +00006import sys, os
7
Georg Brandl692bbc42007-08-24 18:22:54 +00008class FrozenTests(unittest.TestCase):
9 def test_frozen(self):
Guido van Rossum4114a4a2001-10-18 18:49:37 +000010
Georg Brandl692bbc42007-08-24 18:22:54 +000011 with captured_stdout() as stdout:
12 try:
13 import __hello__
14 except ImportError, x:
15 self.fail("import __hello__ failed:" + str(x))
Guido van Rossum4114a4a2001-10-18 18:49:37 +000016
Georg Brandl692bbc42007-08-24 18:22:54 +000017 try:
18 import __phello__
19 except ImportError, x:
20 self.fail("import __phello__ failed:" + str(x))
Guido van Rossum4114a4a2001-10-18 18:49:37 +000021
Georg Brandl692bbc42007-08-24 18:22:54 +000022 try:
23 import __phello__.spam
24 except ImportError, x:
25 self.fail("import __phello__.spam failed:" + str(x))
26
27 if sys.platform != "mac": # On the Mac this import does succeed.
28 try:
29 import __phello__.foo
30 except ImportError:
31 pass
32 else:
33 self.fail("import __phello__.foo should have failed")
34
35 self.assertEquals(stdout.getvalue(),
36 'Hello world...\nHello world...\nHello world...\n')
37
Amaury Forgeot d'Arc607bff12008-04-18 23:31:33 +000038 del sys.modules['__hello__']
39 del sys.modules['__phello__']
40 del sys.modules['__phello__.spam']
41
Georg Brandl692bbc42007-08-24 18:22:54 +000042
43def test_main():
44 run_unittest(FrozenTests)
Brett Cannon8820f2a2008-04-01 12:46:02 +000045
46
47
48if __name__ == '__main__':
49 test_main()