Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
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
Next Next commit
Re-enable tests
  • Loading branch information
eduardo-elizondo committed Feb 21, 2022
commit 22bb98c311d4cf6a9d0d6d262137e8aed53b98ce
7 changes: 4 additions & 3 deletions Lib/concurrent/futures/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ def __init__(self, executor):
self.thread_wakeup = executor._executor_manager_thread_wakeup
self.shutdown_lock = executor._shutdown_lock

# Make mp.util.debug available even during runtime shutdown
self._debugp = mp.util.debug
# A weakref.ref to the ProcessPoolExecutor that owns this thread. Used
# to determine if the ProcessPoolExecutor has been garbage collected
# and that the manager can exit.
Expand All @@ -297,9 +299,8 @@ def __init__(self, executor):
def weakref_cb(_,
thread_wakeup=self.thread_wakeup,
shutdown_lock=self.shutdown_lock):
# TODO(eelizondo): mp doesn't exist anymore here
# mp.util.debug('Executor collected: triggering callback for'
# ' QueueManager wakeup')
self._debugp('Executor collected: triggering callback for'
' QueueManager wakeup')
# ./python Lib/test/test_concurrent_futures.py ProcessPoolForkProcessPoolShutdownTest.test_interpreter_shutdown
with shutdown_lock:
thread_wakeup.wakeup()
Expand Down
4 changes: 3 additions & 1 deletion Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,8 @@ def __init__(self, name, level=NOTSET):
self.handlers = []
self.disabled = False
self._cache = {}
# Make normcase available even during runtime shutdown
self._normcase = os.path.normcase

def setLevel(self, level):
"""
Expand Down Expand Up @@ -1569,7 +1571,7 @@ def findCaller(self, stack_info=False, stacklevel=1):
rv = "(unknown file)", 0, "(unknown function)", None
while hasattr(f, "f_code"):
co = f.f_code
filename = os.path.normcase(co.co_filename)
filename = self._normcase(co.co_filename)
if filename == _srcfile:
f = f.f_back
continue
Expand Down
5 changes: 4 additions & 1 deletion Lib/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,9 @@ def __init__(self, suffix=None, prefix=None, dir=None,
warn_message="Implicitly cleaning up {!r}".format(self),
ignore_errors=self._ignore_cleanup_errors)

# Make _os.path.exists available even during runtime shutdown
self._exists = _os.path.exists

@classmethod
def _rmtree(cls, name, ignore_errors=False):
def onerror(func, path, exc_info):
Expand Down Expand Up @@ -850,7 +853,7 @@ def __exit__(self, exc, value, tb):
self.cleanup()

def cleanup(self):
if self._finalizer.detach() or _os.path.exists(self.name):
if self._finalizer.detach() or self._exists(self.name):
self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)

__class_getitem__ = classmethod(_types.GenericAlias)
11 changes: 6 additions & 5 deletions Lib/test/final_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
"""

import shutil
import sys
import test.final_b

x = 'a'

class C:
def __del__(self):
def __del__(self, sys=sys):
# Inspect module globals and builtins
print("x =", x)
print("final_b.x =", test.final_b.x)
print("shutil.rmtree =", getattr(shutil.rmtree, '__name__', None))
print("len =", getattr(len, '__name__', None))
print("x =", x, file=sys.stderr)
print("final_b.x =", test.final_b.x, file=sys.stderr)
print("shutil.rmtree =", getattr(shutil.rmtree, '__name__', None), sys.stderr)
print("len =", getattr(len, '__name__', None), sys.stderr)

c = C()
_underscored = C()
11 changes: 6 additions & 5 deletions Lib/test/final_b.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
"""

import shutil
import sys
import test.final_a

x = 'b'

class C:
def __del__(self):
def __del__(self, sys=sys):
# Inspect module globals and builtins
print("x =", x)
print("final_a.x =", test.final_a.x)
print("shutil.rmtree =", getattr(shutil.rmtree, '__name__', None))
print("len =", getattr(len, '__name__', None))
print("x =", x, file=sys.stderr)
print("final_a.x =", test.final_a.x, file=sys.stderr)
print("shutil.rmtree =", getattr(shutil.rmtree, '__name__', None), file=sys.stderr)
print("len =", getattr(len, '__name__', None), file=sys.stderr)

c = C()
_underscored = C()
17 changes: 5 additions & 12 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3518,36 +3518,29 @@ def _check_create_at_shutdown(self, **kwargs):
code = """if 1:
import codecs
import {iomod} as io
import sys

# Avoid looking up codecs at shutdown
codecs.lookup('utf-8')

class C:
def __init__(self):
self.buf = io.BytesIO()
def __del__(self):
def __del__(self, sys=sys):
io.TextIOWrapper(self.buf, **{kwargs})
print("ok")
print("ok", file=sys.stderr)
c = C()
""".format(iomod=iomod, kwargs=kwargs)
return assert_python_ok("-c", code)

@unittest.skipIf(True, 'TODO(eelizondo): Modules unavailable for __del__')
def test_create_at_shutdown_without_encoding(self):
rc, out, err = self._check_create_at_shutdown()
if err:
# Can error out with a RuntimeError if the module state
# isn't found.
self.assertIn(self.shutdown_error, err.decode())
else:
self.assertEqual("ok", out.decode().strip())
self.assertEqual("ok", err.decode().strip())

@unittest.skipIf(True, 'TODO(eelizondo): Modules unavailable for __del__')
def test_create_at_shutdown_with_encoding(self):
rc, out, err = self._check_create_at_shutdown(encoding='utf-8',
errors='strict')
self.assertFalse(err)
self.assertEqual("ok", out.decode().strip())
self.assertEqual("ok", err.decode().strip())

def test_read_byteslike(self):
r = MemviewBytesIO(b'Just some random string\n')
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4374,7 +4374,6 @@ def __init__(self, name='MyLogger', level=logging.NOTSET):
h.close()
logging.setLoggerClass(logging.Logger)

@unittest.skipIf(True, 'TODO(eelizondo): Modules unavailable for __del__')
def test_logging_at_shutdown(self):
# bpo-20037: Doing text I/O late at interpreter shutdown must not crash
code = textwrap.dedent("""
Expand All @@ -4394,7 +4393,6 @@ def __del__(self):
self.assertIn("exception in __del__", err)
self.assertIn("ValueError: some error", err)

@unittest.skipIf(True, 'TODO(eelizondo): Modules unavailable for __del__')
def test_logging_at_shutdown_open(self):
# bpo-26789: FileHandler keeps a reference to the builtin open()
# function to be able to open or reopen the file during Python
Expand Down
22 changes: 13 additions & 9 deletions Lib/test/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,23 @@ def test_module_repr_source(self):
self.assertEqual(r[-len(ends_with):], ends_with,
'{!r} does not end with {!r}'.format(r, ends_with))

@unittest.skipIf(True, 'TODO(eelizondo): Modules unavailable for __del__')
def test_module_finalization_at_shutdown(self):
# Module globals and builtins should still be available during shutdown
rc, out, err = assert_python_ok("-c", "from test import final_a")
self.assertFalse(err)
lines = out.splitlines()
lines = err.splitlines()
self.assertEqual(set(lines), {
b"x = a",
b"x = b",
b"final_a.x = a",
b"final_b.x = b",
b"len = len",
b"shutil.rmtree = rmtree"})
b'x = a',
b'final_b.x = b',
b'x = b',
b'final_a.x = a',
b'shutil.rmtree = rmtree',
b'len = len',
b'x = None',
b'final_b.x = b',
b'x = None',
b'final_a.x = None',
b'shutil.rmtree = rmtree',
b'len = len'})

def test_descriptor_errors_propagate(self):
class Descr:
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,6 @@ def test_del_on_shutdown_ignore_errors(self):
self.assertNotIn("Error", err)
self.assertIn("ResourceWarning: Implicitly cleaning up", err)

@unittest.skipIf(True, 'TODO(eelizondo): Modules unavailable for __del__')
def test_exit_on_shutdown(self):
# Issue #22427
with self.do_create() as dir:
Expand Down
22 changes: 11 additions & 11 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,33 +645,33 @@ def func():
self.assertEqual(err, b"")
self.assertEqual(data, "Thread-1 (func)\nTrue\nTrue\n")

@unittest.skipIf(True, 'TODO(eelizondo): Modules unavailable for __del__')
def test_main_thread_during_shutdown(self):
# bpo-31516: current_thread() should still point to the main thread
# at shutdown
code = """if 1:
import gc, threading
import gc, sys, threading

main_thread = threading.current_thread()
assert main_thread is threading.main_thread() # sanity check

class RefCycle:
def __init__(self):
def __init__(self, main_thread):
self.cycle = self
self.main_thread = main_thread

def __del__(self):
def __del__(self, sys=sys):
print("GC:",
threading.current_thread() is main_thread,
threading.main_thread() is main_thread,
threading.enumerate() == [main_thread])
threading.current_thread() is self.main_thread,
threading.main_thread() is self.main_thread,
threading.enumerate() == [self.main_thread],
file=sys.stderr)

RefCycle()
RefCycle(main_thread)
gc.collect() # sanity check
x = RefCycle()
x = RefCycle(main_thread)
"""
_, out, err = assert_python_ok("-c", code)
data = out.decode()
self.assertEqual(err, b"")
data = err.decode()
self.assertEqual(data.splitlines(),
["GC: True True True"] * 2)

Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ def do_test(firstlines, message, charset, lineno):
# Issue #18960: coding spec should have no effect
do_test("x=0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)

@unittest.skipIf(True, 'TODO(eelizondo): Modules unavailable for __del__')
def test_print_traceback_at_exit(self):
# Issue #22599: Ensure that it is possible to use the traceback module
# to display an exception at Python exit
Expand Down
6 changes: 2 additions & 4 deletions Lib/test/test_warnings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,23 +1233,21 @@ def test_issue_8766(self):


class FinalizationTest(unittest.TestCase):
@unittest.skipIf(True, 'TODO(eelizondo): Modules unavailable for __del__')
def test_finalization(self):
# Issue #19421: warnings.warn() should not crash
# during Python finalization
code = """
import warnings
warn = warnings.warn

class A:
def __del__(self):
warn("test")
warnings.warn("test")

a=A()
"""
rc, out, err = assert_python_ok("-c", code)
self.assertEqual(err.decode().rstrip(),
'<string>:7: UserWarning: test')
'<string>:6: UserWarning: test')

def test_late_resource_warning(self):
# Issue #21925: Emitting a ResourceWarning late during the Python
Expand Down