diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-03 19:30:49 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-07-03 19:30:49 (GMT) |
commit | bae75cf3fe975d21c0c20baa595d21ebeca54681 (patch) | |
tree | 5d1b8a52a7c505d5eacd37f8525ccb230776ba27 | |
parent | 7e160ce356036bccda2608d9ee10bfe276dfa97a (diff) | |
parent | a793037d803abf098d172f686e2b95d27863c54d (diff) | |
download | cpython-bae75cf3fe975d21c0c20baa595d21ebeca54681.zip cpython-bae75cf3fe975d21c0c20baa595d21ebeca54681.tar.gz cpython-bae75cf3fe975d21c0c20baa595d21ebeca54681.tar.bz2 |
Issue #19527: Fixed tests with defined COUNT_ALLOCS.
-rw-r--r-- | Lib/test/support/__init__.py | 3 | ||||
-rw-r--r-- | Lib/test/test_gc.py | 7 | ||||
-rw-r--r-- | Lib/test/test_io.py | 2 | ||||
-rw-r--r-- | Lib/test/test_logging.py | 1 | ||||
-rw-r--r-- | Lib/test/test_module.py | 4 | ||||
-rw-r--r-- | Lib/test/test_regrtest.py | 3 | ||||
-rw-r--r-- | Lib/test/test_sys.py | 8 | ||||
-rw-r--r-- | Lib/test/test_threading.py | 4 | ||||
-rw-r--r-- | Lib/test/test_traceback.py | 1 | ||||
-rw-r--r-- | Lib/test/test_warnings/__init__.py | 1 | ||||
-rw-r--r-- | Lib/test/test_weakref.py | 1 |
11 files changed, 29 insertions, 6 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 86ff734..ef6b4f5 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2071,6 +2071,9 @@ def strip_python_stderr(stderr): stderr = re.sub(br"\[\d+ refs, \d+ blocks\]\r?\n?", b"", stderr).strip() return stderr +requires_type_collecting = unittest.skipIf(hasattr(sys, 'getcounts'), + 'types are immortal if COUNT_ALLOCS is defined') + def args_from_interpreter_flags(): """Return a list of command-line arguments reproducing the current settings in sys.flags and sys.warnoptions.""" diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index 872ca62..e727499 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -1,7 +1,7 @@ import unittest from test.support import (verbose, refcount_test, run_unittest, - strip_python_stderr, cpython_only, start_threads, - temp_dir) + strip_python_stderr, cpython_only, start_threads, + temp_dir, requires_type_collecting) from test.support.script_helper import assert_python_ok, make_script import sys @@ -118,6 +118,7 @@ class GCTests(unittest.TestCase): del a self.assertNotEqual(gc.collect(), 0) + @requires_type_collecting def test_newinstance(self): class A(object): pass @@ -678,6 +679,7 @@ class GCTests(unittest.TestCase): stderr = run_command(code % "gc.DEBUG_SAVEALL") self.assertNotIn(b"uncollectable objects at shutdown", stderr) + @requires_type_collecting def test_gc_main_module_at_shutdown(self): # Create a reference cycle through the __main__ module and check # it gets collected at interpreter shutdown. @@ -691,6 +693,7 @@ class GCTests(unittest.TestCase): rc, out, err = assert_python_ok('-c', code) self.assertEqual(out.strip(), b'__del__ called') + @requires_type_collecting def test_gc_ordinary_module_at_shutdown(self): # Same as above, but with a non-__main__ module. with temp_dir() as script_dir: diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 0bfaba9..c48ec3a 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -3165,6 +3165,7 @@ class TextIOWrapperTest(unittest.TestCase): """.format(iomod=iomod, kwargs=kwargs) return assert_python_ok("-c", code) + @support.requires_type_collecting def test_create_at_shutdown_without_encoding(self): rc, out, err = self._check_create_at_shutdown() if err: @@ -3174,6 +3175,7 @@ class TextIOWrapperTest(unittest.TestCase): else: self.assertEqual("ok", out.decode().strip()) + @support.requires_type_collecting def test_create_at_shutdown_with_encoding(self): rc, out, err = self._check_create_at_shutdown(encoding='utf-8', errors='strict') diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 9e391dc..062df0f 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3389,6 +3389,7 @@ class ModuleLevelMiscTest(BaseTest): logging.setLoggerClass(logging.Logger) self.assertEqual(logging.getLoggerClass(), logging.Logger) + @support.requires_type_collecting def test_logging_at_shutdown(self): # Issue #20037 code = """if 1: diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py index ea6e897..6d0d594 100644 --- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -1,7 +1,7 @@ # Test the module type import unittest import weakref -from test.support import gc_collect +from test.support import gc_collect, requires_type_collecting from test.support.script_helper import assert_python_ok import sys @@ -101,6 +101,7 @@ class ModuleTests(unittest.TestCase): gc_collect() self.assertEqual(f().__dict__["bar"], 4) + @requires_type_collecting def test_clear_dict_in_ref_cycle(self): destroyed = [] m = ModuleType("foo") @@ -214,6 +215,7 @@ a = A(destroyed)""" self.assertEqual(r[-len(ends_with):], ends_with, '{!r} does not end with {!r}'.format(r, ends_with)) + @requires_type_collecting 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") diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index c11408d..32edff8 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -763,6 +763,9 @@ class ArgsTestCase(BaseTestCase): with open(filename) as fp: reflog = fp.read() + if hasattr(sys, 'getcounts'): + # Types are immportal if COUNT_ALLOCS is defined + reflog = reflog.splitlines(True)[-1] self.assertEqual(reflog, line2) def test_list_tests(self): diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index a531879..4435d69 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -803,6 +803,7 @@ class SysModuleTest(unittest.TestCase): c = sys.getallocatedblocks() self.assertIn(c, range(b - 50, b + 50)) + @test.support.requires_type_collecting def test_is_finalizing(self): self.assertIs(sys.is_finalizing(), False) # Don't use the atexit module because _Py_Finalizing is only set @@ -1083,9 +1084,12 @@ class SizeofTest(unittest.TestCase): check((1,2,3), vsize('') + 3*self.P) # type # static type: PyTypeObject - s = vsize('P2n15Pl4Pn9Pn11PIP') + fmt = 'P2n15Pl4Pn9Pn11PIP' + if hasattr(sys, 'getcounts'): + fmt += '3n2P' + s = vsize(fmt) check(int, s) - s = vsize('P2n15Pl4Pn9Pn11PIP' # PyTypeObject + s = vsize(fmt + # PyTypeObject '3P' # PyAsyncMethods '36P' # PyNumberMethods '3P' # PyMappingMethods diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index d6317c7..a4aa49f 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -3,7 +3,8 @@ Tests for the threading module. """ import test.support -from test.support import verbose, import_module, cpython_only +from test.support import (verbose, import_module, cpython_only, + requires_type_collecting) from test.support.script_helper import assert_python_ok, assert_python_failure import random @@ -987,6 +988,7 @@ class ThreadingExceptionTests(BaseTestCase): self.assertIn("ZeroDivisionError", err) self.assertNotIn("Unhandled exception", err) + @requires_type_collecting def test_print_exception_stderr_is_none_1(self): script = r"""if True: import sys diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 5e4b6a2..787409c 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -178,6 +178,7 @@ class SyntaxTracebackCases(unittest.TestCase): # Issue #18960: coding spec should have no effect do_test("x=0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5) + @support.requires_type_collecting 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 diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 497c5cc..e7b85f1 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -1035,6 +1035,7 @@ class BootstrapTest(unittest.TestCase): class FinalizationTest(unittest.TestCase): + @support.requires_type_collecting def test_finalization(self): # Issue #19421: warnings.warn() should not crash # during Python finalization diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index f49cb7e..6d50a66 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -589,6 +589,7 @@ class ReferencesTestCase(TestBase): del c1, c2, C, D gc.collect() + @support.requires_type_collecting def test_callback_in_cycle_resurrection(self): import gc |