blob: c86a24d10d6516e39ec438905fbd1feb59e57ef0 [file] [log] [blame]
Guido van Rossum4114a4a2001-10-18 18:49:37 +00001# Test the frozen module defined in frozen.c.
Thomas Woutersed03b412007-08-28 21:37:11 +00002from __future__ import with_statement
Guido van Rossum4114a4a2001-10-18 18:49:37 +00003
Thomas Woutersed03b412007-08-28 21:37:11 +00004from test.test_support import captured_stdout, run_unittest
5import unittest
Guido van Rossum4114a4a2001-10-18 18:49:37 +00006import sys, os
7
Thomas Woutersed03b412007-08-28 21:37:11 +00008class FrozenTests(unittest.TestCase):
9 def test_frozen(self):
Christian Heimesf19169f2007-11-12 19:19:07 +000010 try:
11 import __hello__
12 except ImportError as x:
13 self.fail("import __hello__ failed:" + str(x))
14 self.assertEqual(__hello__.initialized, True)
Christian Heimescbf3b5c2007-12-03 21:02:03 +000015 self.assertEqual(len(dir(__hello__)), 6, dir(__hello__))
Guido van Rossum4114a4a2001-10-18 18:49:37 +000016
Christian Heimesf19169f2007-11-12 19:19:07 +000017 try:
18 import __phello__
19 except ImportError as x:
20 self.fail("import __phello__ failed:" + str(x))
21 self.assertEqual(__phello__.initialized, True)
22 if not "__phello__.spam" in sys.modules:
Christian Heimesf19169f2007-11-12 19:19:07 +000023 self.assertEqual(len(dir(__phello__)), 7, dir(__phello__))
Christian Heimescbf3b5c2007-12-03 21:02:03 +000024 else:
25 self.assertEqual(len(dir(__phello__)), 8, dir(__phello__))
Guido van Rossum4114a4a2001-10-18 18:49:37 +000026
Christian Heimesf19169f2007-11-12 19:19:07 +000027 try:
28 import __phello__.spam
29 except ImportError as x:
30 self.fail("import __phello__.spam failed:" + str(x))
31 self.assertEqual(__phello__.spam.initialized, True)
Christian Heimescbf3b5c2007-12-03 21:02:03 +000032 self.assertEqual(len(dir(__phello__.spam)), 6)
33 self.assertEqual(len(dir(__phello__)), 8)
Guido van Rossum4114a4a2001-10-18 18:49:37 +000034
Christian Heimesf19169f2007-11-12 19:19:07 +000035 try:
36 import __phello__.foo
37 except ImportError:
38 pass
39 else:
40 self.fail("import __phello__.foo should have failed")
Thomas Woutersed03b412007-08-28 21:37:11 +000041
Christian Heimesdae2a892008-04-19 00:55:37 +000042 if sys.platform != "mac": # On the Mac this import does succeed.
43 try:
44 import __phello__.foo
45 except ImportError:
46 pass
47 else:
48 self.fail("import __phello__.foo should have failed")
49
50 del sys.modules['__hello__']
51 del sys.modules['__phello__']
52 del sys.modules['__phello__.spam']
53
Thomas Woutersed03b412007-08-28 21:37:11 +000054def test_main():
55 run_unittest(FrozenTests)
Guido van Rossum3b7210d2007-10-15 00:25:56 +000056
57if __name__ == "__main__":
58 test_main()