Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Roll back the changes with the __hello__ module.
  • Loading branch information
ericsnowcurrently committed Sep 15, 2021
commit b45e0d63fb4badf80138a18b46bf74080816c7b6
3 changes: 1 addition & 2 deletions Lib/ctypes/test/test_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import unittest
import sys
from ctypes import *
from test.support import import_helper
from test.support import import_helper, captured_stdout

import _ctypes_test

Expand Down Expand Up @@ -73,7 +73,6 @@ class struct_frozen(Structure):
self.assertTrue([entry.code[i] for i in range(abs(entry.size))])
# Check the module's package-ness.
with import_helper.frozen_modules():
# Hide the message written by the __hello__ module.
spec = importlib.util.find_spec(modname)
if entry.size < 0:
# It's a package.
Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ def test_frozen(self):
if name in sys.modules:
del sys.modules[name]
with import_helper.frozen_modules():
import __hello__
with captured_stdout() as out:
__hello__.main()
with captured_stdout() as out:
import __hello__
self.assertEqual(out.getvalue(), 'Hello world!\n')


Expand Down
35 changes: 14 additions & 21 deletions Lib/test/test_importlib/frozen/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def deprecated():
def fresh(name, *, oldapi=False):
with util.uncache(name):
with import_helper.frozen_modules():
if oldapi:
with deprecated():
yield
else:
yield
with captured_stdout() as stdout:
if oldapi:
with deprecated():
yield stdout
else:
yield stdout


class ExecModuleTests(abc.LoaderTests):
Expand All @@ -43,10 +44,8 @@ def exec_module(self, name):
module.__spec__ = spec
assert not hasattr(module, 'initialized')

with fresh(name):
with fresh(name) as stdout:
self.machinery.FrozenImporter.exec_module(module)
with captured_stdout() as stdout:
module.main()

self.assertTrue(module.initialized)
self.assertTrue(hasattr(module, '__spec__'))
Expand Down Expand Up @@ -120,10 +119,8 @@ def test_unloadable(self):
class LoaderTests(abc.LoaderTests):

def load_module(self, name):
with fresh(name, oldapi=True):
with fresh(name, oldapi=True) as stdout:
module = self.machinery.FrozenImporter.load_module(name)
with captured_stdout() as stdout:
module.main()
return module, stdout

def test_module(self):
Expand Down Expand Up @@ -168,18 +165,15 @@ def test_lacking_parent(self):
self.assertFalse(hasattr(module, '__file__'))

def test_module_reuse(self):
with fresh('__hello__', oldapi=True):
with fresh('__hello__', oldapi=True) as stdout:
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):
with fresh('__hello__', oldapi=True) as stdout:
module = self.machinery.FrozenImporter.load_module('__hello__')
repr_str = self.machinery.FrozenImporter.module_repr(module)
self.assertEqual(repr_str,
Expand Down Expand Up @@ -209,12 +203,11 @@ 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:
mod.main()
with import_helper.frozen_modules():
code = self.machinery.FrozenImporter.get_code(name)
mod = types.ModuleType(name)
exec(code, mod.__dict__)
self.assertTrue(hasattr(mod, 'initialized'))
self.assertEqual(stdout.getvalue(), 'Hello world!\n')

Expand Down
6 changes: 3 additions & 3 deletions Python/frozen_modules/MANIFEST

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 10 additions & 21 deletions Python/frozen_modules/hello.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions Tools/freeze/flag.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
initialized = True

def main():
print("Hello world!")

if __name__ == '__main__':
main()
print("Hello world!")
6 changes: 1 addition & 5 deletions Tools/freeze/hello.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
def main():
print("Hello world!")

if __name__ == '__main__':
main()
print('Hello world...')