mirror of
https://github.com/python/cpython.git
synced 2025-10-02 21:25:24 +00:00
gh-113937 Fix failures in type cache tests due to re-running (GH-113953)
This commit is contained in:
parent
c4992f4106
commit
e58334e4c9
1 changed files with 14 additions and 14 deletions
|
@ -67,7 +67,8 @@ class TypeCacheTests(unittest.TestCase):
|
||||||
|
|
||||||
type_assign_version(C)
|
type_assign_version(C)
|
||||||
orig_version = type_get_version(C)
|
orig_version = type_get_version(C)
|
||||||
self.assertNotEqual(orig_version, 0)
|
if orig_version == 0:
|
||||||
|
self.skipTest("Could not assign a valid type version")
|
||||||
|
|
||||||
type_modified(C)
|
type_modified(C)
|
||||||
type_assign_specific_version_unsafe(C, orig_version + 5)
|
type_assign_specific_version_unsafe(C, orig_version + 5)
|
||||||
|
@ -84,10 +85,11 @@ class TypeCacheWithSpecializationTests(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
_clear_type_cache()
|
_clear_type_cache()
|
||||||
|
|
||||||
def _assign_and_check_valid_version(self, user_type):
|
def _assign_valid_version_or_skip(self, type_):
|
||||||
type_modified(user_type)
|
type_modified(type_)
|
||||||
type_assign_version(user_type)
|
type_assign_version(type_)
|
||||||
self.assertNotEqual(type_get_version(user_type), 0)
|
if type_get_version(type_) == 0:
|
||||||
|
self.skipTest("Could not assign valid type version")
|
||||||
|
|
||||||
def _assign_and_check_version_0(self, user_type):
|
def _assign_and_check_version_0(self, user_type):
|
||||||
type_modified(user_type)
|
type_modified(user_type)
|
||||||
|
@ -98,8 +100,6 @@ class TypeCacheWithSpecializationTests(unittest.TestCase):
|
||||||
return set(instr.opname for instr in dis.Bytecode(func, adaptive=True))
|
return set(instr.opname for instr in dis.Bytecode(func, adaptive=True))
|
||||||
|
|
||||||
def _check_specialization(self, func, arg, opname, *, should_specialize):
|
def _check_specialization(self, func, arg, opname, *, should_specialize):
|
||||||
self.assertIn(opname, self._all_opnames(func))
|
|
||||||
|
|
||||||
for _ in range(100):
|
for _ in range(100):
|
||||||
func(arg)
|
func(arg)
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class TypeCacheWithSpecializationTests(unittest.TestCase):
|
||||||
def foo(self):
|
def foo(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self._assign_and_check_valid_version(A)
|
self._assign_valid_version_or_skip(A)
|
||||||
|
|
||||||
def load_foo_1(type_):
|
def load_foo_1(type_):
|
||||||
type_.foo
|
type_.foo
|
||||||
|
@ -129,8 +129,8 @@ class TypeCacheWithSpecializationTests(unittest.TestCase):
|
||||||
self._check_specialization(load_foo_2, A, "LOAD_ATTR", should_specialize=False)
|
self._check_specialization(load_foo_2, A, "LOAD_ATTR", should_specialize=False)
|
||||||
|
|
||||||
def test_class_load_attr_specialization_static_type(self):
|
def test_class_load_attr_specialization_static_type(self):
|
||||||
self._assign_and_check_valid_version(str)
|
self._assign_valid_version_or_skip(str)
|
||||||
self._assign_and_check_valid_version(bytes)
|
self._assign_valid_version_or_skip(bytes)
|
||||||
|
|
||||||
def get_capitalize_1(type_):
|
def get_capitalize_1(type_):
|
||||||
return type_.capitalize
|
return type_.capitalize
|
||||||
|
@ -164,7 +164,7 @@ class TypeCacheWithSpecializationTests(unittest.TestCase):
|
||||||
def x(self):
|
def x(self):
|
||||||
return 9
|
return 9
|
||||||
|
|
||||||
self._assign_and_check_valid_version(G)
|
self._assign_valid_version_or_skip(G)
|
||||||
|
|
||||||
def load_x_1(instance):
|
def load_x_1(instance):
|
||||||
instance.x
|
instance.x
|
||||||
|
@ -183,7 +183,7 @@ class TypeCacheWithSpecializationTests(unittest.TestCase):
|
||||||
class B:
|
class B:
|
||||||
__slots__ = ("bar",)
|
__slots__ = ("bar",)
|
||||||
|
|
||||||
self._assign_and_check_valid_version(B)
|
self._assign_valid_version_or_skip(B)
|
||||||
|
|
||||||
def store_bar_1(type_):
|
def store_bar_1(type_):
|
||||||
type_.bar = 10
|
type_.bar = 10
|
||||||
|
@ -203,7 +203,7 @@ class TypeCacheWithSpecializationTests(unittest.TestCase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self._assign_and_check_valid_version(F)
|
self._assign_valid_version_or_skip(F)
|
||||||
|
|
||||||
def call_class_1(type_):
|
def call_class_1(type_):
|
||||||
type_()
|
type_()
|
||||||
|
@ -222,7 +222,7 @@ class TypeCacheWithSpecializationTests(unittest.TestCase):
|
||||||
class H:
|
class H:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self._assign_and_check_valid_version(H)
|
self._assign_valid_version_or_skip(H)
|
||||||
|
|
||||||
def to_bool_1(instance):
|
def to_bool_1(instance):
|
||||||
not instance
|
not instance
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue