blob: 11a366c33871a4a82bb0f4dc86743bebcf97fe02 [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
Georg Brandl1b37e872010-03-14 10:45:50 +00005import sys
Guido van Rossum4114a4a2001-10-18 18:49:37 +00006
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)
Barry Warsaw28a691b2010-04-17 00:19:56 +000014 self.assertEqual(len(dir(__hello__)), 7, 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 Heimescbf3b5c2007-12-03 21:02:03 +000022 self.assertEqual(len(dir(__phello__)), 8, dir(__phello__))
Barry Warsaw28a691b2010-04-17 00:19:56 +000023 else:
24 self.assertEqual(len(dir(__phello__)), 9, dir(__phello__))
Benjamin Petersond968e272008-11-05 22:48:33 +000025 self.assertEquals(__phello__.__path__, [__phello__.__name__])
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)
Barry Warsaw28a691b2010-04-17 00:19:56 +000032 self.assertEqual(len(dir(__phello__.spam)), 7)
33 self.assertEqual(len(dir(__phello__)), 9)
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
Ronald Oussoren94f25282010-05-05 19:11:21 +000042 try:
43 import __phello__.foo
44 except ImportError:
45 pass
46 else:
47 self.fail("import __phello__.foo should have failed")
Christian Heimesdae2a892008-04-19 00:55:37 +000048
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()