mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #19527: Fixed tests with defined COUNT_ALLOCS.
This commit is contained in:
		
						commit
						bae75cf3fe
					
				
					 11 changed files with 29 additions and 6 deletions
				
			
		|  | @ -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.""" | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| import unittest | ||||
| from test.support import (verbose, refcount_test, run_unittest, | ||||
|                           strip_python_stderr, cpython_only, start_threads, | ||||
|                             temp_dir) | ||||
|                           temp_dir, requires_type_collecting) | ||||
| from test.support.script_helper import assert_python_ok, make_script | ||||
| 
 | ||||
| import sys | ||||
|  | @ -118,6 +118,7 @@ class A: | |||
|         del a | ||||
|         self.assertNotEqual(gc.collect(), 0) | ||||
| 
 | ||||
|     @requires_type_collecting | ||||
|     def test_newinstance(self): | ||||
|         class A(object): | ||||
|             pass | ||||
|  | @ -678,6 +679,7 @@ def run_command(code): | |||
|         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 @@ def __del__(self): | |||
|         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: | ||||
|  |  | |||
|  | @ -3165,6 +3165,7 @@ def __del__(self): | |||
|             """.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 @@ def test_create_at_shutdown_without_encoding(self): | |||
|         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') | ||||
|  |  | |||
|  | @ -3389,6 +3389,7 @@ class MyLogger(logging.Logger): | |||
|         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: | ||||
|  |  | |||
|  | @ -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 @@ def f(): | |||
|         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 @@ def test_module_repr_source(self): | |||
|         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") | ||||
|  |  | |||
|  | @ -763,6 +763,9 @@ def test_leak(self): | |||
| 
 | ||||
|         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): | ||||
|  |  | |||
|  | @ -803,6 +803,7 @@ def test_getallocatedblocks(self): | |||
|         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 @@ def delx(self): del self.__x | |||
|         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 | ||||
|  |  | |||
|  | @ -3,7 +3,8 @@ | |||
| """ | ||||
| 
 | ||||
| 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 @@ def run(): | |||
|         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 | ||||
|  |  | |||
|  | @ -178,6 +178,7 @@ 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) | ||||
| 
 | ||||
|     @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 | ||||
|  |  | |||
|  | @ -1035,6 +1035,7 @@ def test_issue_8766(self): | |||
| 
 | ||||
| 
 | ||||
| class FinalizationTest(unittest.TestCase): | ||||
|     @support.requires_type_collecting | ||||
|     def test_finalization(self): | ||||
|         # Issue #19421: warnings.warn() should not crash | ||||
|         # during Python finalization | ||||
|  |  | |||
|  | @ -589,6 +589,7 @@ class D: | |||
|         del c1, c2, C, D | ||||
|         gc.collect() | ||||
| 
 | ||||
|     @support.requires_type_collecting | ||||
|     def test_callback_in_cycle_resurrection(self): | ||||
|         import gc | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka