diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/__hello__.py | 7 | ||||
-rw-r--r-- | Lib/ctypes/test/test_values.py | 2 | ||||
-rw-r--r-- | Lib/test/test_frozen.py | 5 | ||||
-rw-r--r-- | Lib/test/test_importlib/frozen/test_loader.py | 35 |
4 files changed, 32 insertions, 17 deletions
diff --git a/Lib/__hello__.py b/Lib/__hello__.py new file mode 100644 index 0000000..d37bd27 --- /dev/null +++ b/Lib/__hello__.py @@ -0,0 +1,7 @@ +initialized = True + +def main(): + print("Hello world!") + +if __name__ == '__main__': + main() diff --git a/Lib/ctypes/test/test_values.py b/Lib/ctypes/test/test_values.py index 4f525cd..96521fd 100644 --- a/Lib/ctypes/test/test_values.py +++ b/Lib/ctypes/test/test_values.py @@ -7,7 +7,7 @@ import importlib.util import unittest import sys from ctypes import * -from test.support import import_helper, captured_stdout +from test.support import import_helper import _ctypes_test diff --git a/Lib/test/test_frozen.py b/Lib/test/test_frozen.py index 52d8f7c..3d212b9 100644 --- a/Lib/test/test_frozen.py +++ b/Lib/test/test_frozen.py @@ -21,8 +21,9 @@ class TestFrozen(unittest.TestCase): if name in sys.modules: del sys.modules[name] with import_helper.frozen_modules(): - with captured_stdout() as out: - import __hello__ + import __hello__ + with captured_stdout() as out: + __hello__.main() self.assertEqual(out.getvalue(), 'Hello world!\n') diff --git a/Lib/test/test_importlib/frozen/test_loader.py b/Lib/test/test_importlib/frozen/test_loader.py index 1b0a56f..cfa5e5b 100644 --- a/Lib/test/test_importlib/frozen/test_loader.py +++ b/Lib/test/test_importlib/frozen/test_loader.py @@ -21,12 +21,11 @@ def deprecated(): def fresh(name, *, oldapi=False): with util.uncache(name): with import_helper.frozen_modules(): - with captured_stdout() as stdout: - if oldapi: - with deprecated(): - yield stdout - else: - yield stdout + if oldapi: + with deprecated(): + yield + else: + yield class ExecModuleTests(abc.LoaderTests): @@ -44,8 +43,10 @@ class ExecModuleTests(abc.LoaderTests): module.__spec__ = spec assert not hasattr(module, 'initialized') - with fresh(name) as stdout: + with fresh(name): self.machinery.FrozenImporter.exec_module(module) + with captured_stdout() as stdout: + module.main() self.assertTrue(module.initialized) self.assertTrue(hasattr(module, '__spec__')) @@ -119,8 +120,10 @@ class ExecModuleTests(abc.LoaderTests): class LoaderTests(abc.LoaderTests): def load_module(self, name): - with fresh(name, oldapi=True) as stdout: + with fresh(name, oldapi=True): module = self.machinery.FrozenImporter.load_module(name) + with captured_stdout() as stdout: + module.main() return module, stdout def test_module(self): @@ -165,15 +168,18 @@ class LoaderTests(abc.LoaderTests): self.assertFalse(hasattr(module, '__file__')) def test_module_reuse(self): - with fresh('__hello__', oldapi=True) as stdout: + with fresh('__hello__', oldapi=True): module1 = self.machinery.FrozenImporter.load_module('__hello__') module2 = self.machinery.FrozenImporter.load_module('__hello__') + with captured_stdout() as stdout: + module1.main() + module2.main() self.assertIs(module1, module2) self.assertEqual(stdout.getvalue(), 'Hello world!\nHello world!\n') def test_module_repr(self): - with fresh('__hello__', oldapi=True) as stdout: + with fresh('__hello__', oldapi=True): module = self.machinery.FrozenImporter.load_module('__hello__') repr_str = self.machinery.FrozenImporter.module_repr(module) self.assertEqual(repr_str, @@ -203,11 +209,12 @@ class InspectLoaderTests: def test_get_code(self): # Make sure that the code object is good. name = '__hello__' + with import_helper.frozen_modules(): + code = self.machinery.FrozenImporter.get_code(name) + mod = types.ModuleType(name) + exec(code, mod.__dict__) with captured_stdout() as stdout: - with import_helper.frozen_modules(): - code = self.machinery.FrozenImporter.get_code(name) - mod = types.ModuleType(name) - exec(code, mod.__dict__) + mod.main() self.assertTrue(hasattr(mod, 'initialized')) self.assertEqual(stdout.getvalue(), 'Hello world!\n') |