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

Skip to content

Commit a793037

Browse files
Issue #19527: Fixed tests with defined COUNT_ALLOCS.
1 parent af65872 commit a793037

10 files changed

Lines changed: 26 additions & 6 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,9 @@ def strip_python_stderr(stderr):
20692069
stderr = re.sub(br"\[\d+ refs, \d+ blocks\]\r?\n?", b"", stderr).strip()
20702070
return stderr
20712071

2072+
requires_type_collecting = unittest.skipIf(hasattr(sys, 'getcounts'),
2073+
'types are immortal if COUNT_ALLOCS is defined')
2074+
20722075
def args_from_interpreter_flags():
20732076
"""Return a list of command-line arguments reproducing the current
20742077
settings in sys.flags and sys.warnoptions."""

Lib/test/test_gc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
from test.support import (verbose, refcount_test, run_unittest,
3-
strip_python_stderr, cpython_only, start_threads,
4-
temp_dir)
3+
strip_python_stderr, cpython_only, start_threads,
4+
temp_dir, requires_type_collecting)
55
from test.support.script_helper import assert_python_ok, make_script
66

77
import sys
@@ -118,6 +118,7 @@ class A:
118118
del a
119119
self.assertNotEqual(gc.collect(), 0)
120120

121+
@requires_type_collecting
121122
def test_newinstance(self):
122123
class A(object):
123124
pass
@@ -678,6 +679,7 @@ def run_command(code):
678679
stderr = run_command(code % "gc.DEBUG_SAVEALL")
679680
self.assertNotIn(b"uncollectable objects at shutdown", stderr)
680681

682+
@requires_type_collecting
681683
def test_gc_main_module_at_shutdown(self):
682684
# Create a reference cycle through the __main__ module and check
683685
# it gets collected at interpreter shutdown.
@@ -692,6 +694,7 @@ def __del__(self):
692694
rc, out, err = assert_python_ok('-c', code)
693695
self.assertEqual(out.strip(), b'__del__ called')
694696

697+
@requires_type_collecting
695698
def test_gc_ordinary_module_at_shutdown(self):
696699
# Same as above, but with a non-__main__ module.
697700
with temp_dir() as script_dir:

Lib/test/test_io.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,6 +3135,7 @@ def __del__(self):
31353135
""".format(iomod=iomod, kwargs=kwargs)
31363136
return assert_python_ok("-c", code)
31373137

3138+
@support.requires_type_collecting
31383139
def test_create_at_shutdown_without_encoding(self):
31393140
rc, out, err = self._check_create_at_shutdown()
31403141
if err:
@@ -3144,6 +3145,7 @@ def test_create_at_shutdown_without_encoding(self):
31443145
else:
31453146
self.assertEqual("ok", out.decode().strip())
31463147

3148+
@support.requires_type_collecting
31473149
def test_create_at_shutdown_with_encoding(self):
31483150
rc, out, err = self._check_create_at_shutdown(encoding='utf-8',
31493151
errors='strict')

Lib/test/test_logging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,6 +3389,7 @@ class MyLogger(logging.Logger):
33893389
logging.setLoggerClass(logging.Logger)
33903390
self.assertEqual(logging.getLoggerClass(), logging.Logger)
33913391

3392+
@support.requires_type_collecting
33923393
def test_logging_at_shutdown(self):
33933394
# Issue #20037
33943395
code = """if 1:

Lib/test/test_module.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Test the module type
22
import unittest
33
import weakref
4-
from test.support import gc_collect
4+
from test.support import gc_collect, requires_type_collecting
55
from test.support.script_helper import assert_python_ok
66

77
import sys
@@ -101,6 +101,7 @@ def f():
101101
gc_collect()
102102
self.assertEqual(f().__dict__["bar"], 4)
103103

104+
@requires_type_collecting
104105
def test_clear_dict_in_ref_cycle(self):
105106
destroyed = []
106107
m = ModuleType("foo")
@@ -214,6 +215,7 @@ def test_module_repr_source(self):
214215
self.assertEqual(r[-len(ends_with):], ends_with,
215216
'{!r} does not end with {!r}'.format(r, ends_with))
216217

218+
@requires_type_collecting
217219
def test_module_finalization_at_shutdown(self):
218220
# Module globals and builtins should still be available during shutdown
219221
rc, out, err = assert_python_ok("-c", "from test import final_a")

Lib/test/test_sys.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ def test_getallocatedblocks(self):
803803
c = sys.getallocatedblocks()
804804
self.assertIn(c, range(b - 50, b + 50))
805805

806+
@test.support.requires_type_collecting
806807
def test_is_finalizing(self):
807808
self.assertIs(sys.is_finalizing(), False)
808809
# Don't use the atexit module because _Py_Finalizing is only set
@@ -1083,9 +1084,12 @@ def delx(self): del self.__x
10831084
check((1,2,3), vsize('') + 3*self.P)
10841085
# type
10851086
# static type: PyTypeObject
1086-
s = vsize('P2n15Pl4Pn9Pn11PIP')
1087+
fmt = 'P2n15Pl4Pn9Pn11PIP'
1088+
if hasattr(sys, 'getcounts'):
1089+
fmt += '3n2P'
1090+
s = vsize(fmt)
10871091
check(int, s)
1088-
s = vsize('P2n15Pl4Pn9Pn11PIP' # PyTypeObject
1092+
s = vsize(fmt + # PyTypeObject
10891093
'3P' # PyAsyncMethods
10901094
'36P' # PyNumberMethods
10911095
'3P' # PyMappingMethods

Lib/test/test_threading.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"""
44

55
import test.support
6-
from test.support import verbose, strip_python_stderr, import_module, cpython_only
6+
from test.support import (verbose, import_module, cpython_only,
7+
requires_type_collecting)
78
from test.support.script_helper import assert_python_ok, assert_python_failure
89

910
import random
@@ -987,6 +988,7 @@ def run():
987988
self.assertIn("ZeroDivisionError", err)
988989
self.assertNotIn("Unhandled exception", err)
989990

991+
@requires_type_collecting
990992
def test_print_exception_stderr_is_none_1(self):
991993
script = r"""if True:
992994
import sys

Lib/test/test_traceback.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def do_test(firstlines, message, charset, lineno):
178178
# Issue #18960: coding spec should has no effect
179179
do_test("0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)
180180

181+
@support.requires_type_collecting
181182
def test_print_traceback_at_exit(self):
182183
# Issue #22599: Ensure that it is possible to use the traceback module
183184
# to display an exception at Python exit

Lib/test/test_warnings/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ def test_issue_8766(self):
990990

991991

992992
class FinalizationTest(unittest.TestCase):
993+
@support.requires_type_collecting
993994
def test_finalization(self):
994995
# Issue #19421: warnings.warn() should not crash
995996
# during Python finalization

Lib/test/test_weakref.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ class D:
589589
del c1, c2, C, D
590590
gc.collect()
591591

592+
@support.requires_type_collecting
592593
def test_callback_in_cycle_resurrection(self):
593594
import gc
594595

0 commit comments

Comments
 (0)