blob: 1654be0eaafed11172c6d2958a3040ada760b046 [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
Guido van Rossum4114a4a2001-10-18 18:49:37 +00005import sys, os
6
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
26 if sys.platform != "mac": # On the Mac this import does succeed.
27 try:
28 import __phello__.foo
29 except ImportError:
30 pass
31 else:
32 self.fail("import __phello__.foo should have failed")
33
34 self.assertEquals(stdout.getvalue(),
35 'Hello world...\nHello world...\nHello world...\n')
36
Amaury Forgeot d'Arc607bff12008-04-18 23:31:33 +000037 del sys.modules['__hello__']
38 del sys.modules['__phello__']
39 del sys.modules['__phello__.spam']
40
Georg Brandl692bbc42007-08-24 18:22:54 +000041
42def test_main():
43 run_unittest(FrozenTests)
Brett Cannon8820f2a2008-04-01 12:46:02 +000044
45
46
47if __name__ == '__main__':
48 test_main()