Neil Schemenauer | 1eaa116 | 2017-12-02 13:54:00 -0800 | [diff] [blame] | 1 | """Basic test of the frozen module (source is in Python/frozen.c).""" |
| 2 | |
| 3 | # The Python/frozen.c source code contains a marshalled Python module |
| 4 | # and therefore depends on the marshal format as well as the bytecode |
| 5 | # format. If those formats have been changed then frozen.c needs to be |
| 6 | # updated. |
| 7 | # |
| 8 | # The test_importlib also tests this module but because those tests |
| 9 | # are much more complicated, it might be unclear why they are failing. |
| 10 | # Invalid marshalled data in frozen.c could case the interpreter to |
| 11 | # crash when __hello__ is imported. |
| 12 | |
| 13 | import sys |
| 14 | import unittest |
| 15 | from test.support import captured_stdout |
Neil Schemenauer | 1eaa116 | 2017-12-02 13:54:00 -0800 | [diff] [blame] | 16 | |
| 17 | |
| 18 | class TestFrozen(unittest.TestCase): |
| 19 | def test_frozen(self): |
| 20 | name = '__hello__' |
| 21 | if name in sys.modules: |
| 22 | del sys.modules[name] |
| 23 | with captured_stdout() as out: |
| 24 | import __hello__ |
| 25 | self.assertEqual(out.getvalue(), 'Hello world!\n') |
| 26 | |
| 27 | |
| 28 | if __name__ == '__main__': |
| 29 | unittest.main() |