blob: 545941bedc7d277bed5615d4020e1abd9605f510 [file] [log] [blame]
Guido van Rossum4114a4a2001-10-18 18:49:37 +00001# Test the frozen module defined in frozen.c.
2
Benjamin Petersonee8712c2008-05-20 21:35:26 +00003from test.support import captured_stdout, run_unittest
Thomas Woutersed03b412007-08-28 21:37:11 +00004import unittest
Guido van Rossum4114a4a2001-10-18 18:49:37 +00005import sys, os
6
Thomas Woutersed03b412007-08-28 21:37:11 +00007class FrozenTests(unittest.TestCase):
8 def test_frozen(self):
Christian Heimesf19169f2007-11-12 19:19:07 +00009 try:
10 import __hello__
11 except ImportError as x:
12 self.fail("import __hello__ failed:" + str(x))
13 self.assertEqual(__hello__.initialized, True)
Christian Heimescbf3b5c2007-12-03 21:02:03 +000014 self.assertEqual(len(dir(__hello__)), 6, dir(__hello__))
Guido van Rossum4114a4a2001-10-18 18:49:37 +000015
Christian Heimesf19169f2007-11-12 19:19:07 +000016 try:
17 import __phello__
18 except ImportError as x:
19 self.fail("import __phello__ failed:" + str(x))
20 self.assertEqual(__phello__.initialized, True)
21 if not "__phello__.spam" in sys.modules:
Christian Heimesf19169f2007-11-12 19:19:07 +000022 self.assertEqual(len(dir(__phello__)), 7, dir(__phello__))
Christian Heimescbf3b5c2007-12-03 21:02:03 +000023 else:
24 self.assertEqual(len(dir(__phello__)), 8, dir(__phello__))
Guido van Rossum4114a4a2001-10-18 18:49:37 +000025
Christian Heimesf19169f2007-11-12 19:19:07 +000026 try:
27 import __phello__.spam
28 except ImportError as x:
29 self.fail("import __phello__.spam failed:" + str(x))
30 self.assertEqual(__phello__.spam.initialized, True)
Christian Heimescbf3b5c2007-12-03 21:02:03 +000031 self.assertEqual(len(dir(__phello__.spam)), 6)
32 self.assertEqual(len(dir(__phello__)), 8)
Guido van Rossum4114a4a2001-10-18 18:49:37 +000033
Christian Heimesf19169f2007-11-12 19:19:07 +000034 try:
35 import __phello__.foo
36 except ImportError:
37 pass
38 else:
39 self.fail("import __phello__.foo should have failed")
Thomas Woutersed03b412007-08-28 21:37:11 +000040
Christian Heimesdae2a892008-04-19 00:55:37 +000041 if sys.platform != "mac": # On the Mac this import does succeed.
42 try:
43 import __phello__.foo
44 except ImportError:
45 pass
46 else:
47 self.fail("import __phello__.foo should have failed")
48
49 del sys.modules['__hello__']
50 del sys.modules['__phello__']
51 del sys.modules['__phello__.spam']
52
Thomas Woutersed03b412007-08-28 21:37:11 +000053def test_main():
54 run_unittest(FrozenTests)
Guido van Rossum3b7210d2007-10-15 00:25:56 +000055
56if __name__ == "__main__":
57 test_main()