Skip to content

Commit

Permalink
Enable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Nov 21, 2024
1 parent 8ebd73d commit 8651ebe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
17 changes: 10 additions & 7 deletions Lib/test/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import unittest

import test.support
from test.support import requires_specialization, script_helper
from test.support import requires_specialization_ft, script_helper
from test.support.import_helper import import_module

_testcapi = test.support.import_helper.import_module("_testcapi")
Expand Down Expand Up @@ -850,6 +850,13 @@ def __init__(self, events):
def __call__(self, code, offset, val):
self.events.append(("return", code.co_name, val))

# CALL_ALLOC_AND_ENTER_INIT will only cache __init__ methods that are
# deferred. We only defer functions defined at the top-level.
class ValueErrorRaiser:
def __init__(self):
raise ValueError()


class ExceptionMonitoringTest(CheckEvents):

exception_recorders = (
Expand Down Expand Up @@ -1045,16 +1052,12 @@ def func():
)
self.assertEqual(events[0], ("throw", IndexError))

@requires_specialization
@requires_specialization_ft
def test_no_unwind_for_shim_frame(self):

class B:
def __init__(self):
raise ValueError()

def f():
try:
return B()
return ValueErrorRaiser()
except ValueError:
pass

Expand Down
13 changes: 8 additions & 5 deletions Lib/test/test_opcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ def f():
self.assertFalse(f())


# CALL_ALLOC_AND_ENTER_INIT will only cache __init__ methods that are
# deferred. We only defer functions defined at the top-level.
class MyClass:
def __init__(self):
pass


class TestCallCache(TestBase):
def test_too_many_defaults_0(self):
def f():
Expand Down Expand Up @@ -522,12 +529,8 @@ def f(x, y):
f()

@disabling_optimizer
@requires_specialization
@requires_specialization_ft
def test_assign_init_code(self):
class MyClass:
def __init__(self):
pass

def instantiate():
return MyClass()

Expand Down
9 changes: 7 additions & 2 deletions Lib/test/test_type_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
import dis
from test import support
from test.support import import_helper, requires_specialization
from test.support import import_helper, requires_specialization, requires_specialization_ft
try:
from sys import _clear_type_cache
except ImportError:
Expand Down Expand Up @@ -110,7 +110,6 @@ class HolderSub(Holder):
HolderSub.value

@support.cpython_only
@requires_specialization
class TypeCacheWithSpecializationTests(unittest.TestCase):
def tearDown(self):
_clear_type_cache()
Expand Down Expand Up @@ -140,6 +139,7 @@ def _check_specialization(self, func, arg, opname, *, should_specialize):
else:
self.assertIn(opname, self._all_opnames(func))

@requires_specialization
def test_class_load_attr_specialization_user_type(self):
class A:
def foo(self):
Expand All @@ -160,6 +160,7 @@ def load_foo_2(type_):

self._check_specialization(load_foo_2, A, "LOAD_ATTR", should_specialize=False)

@requires_specialization
def test_class_load_attr_specialization_static_type(self):
self.assertNotEqual(type_get_version(str), 0)
self.assertNotEqual(type_get_version(bytes), 0)
Expand All @@ -171,6 +172,7 @@ def get_capitalize_1(type_):
self.assertEqual(get_capitalize_1(str)('hello'), 'Hello')
self.assertEqual(get_capitalize_1(bytes)(b'hello'), b'Hello')

@requires_specialization
def test_property_load_attr_specialization_user_type(self):
class G:
@property
Expand All @@ -192,6 +194,7 @@ def load_x_2(instance):

self._check_specialization(load_x_2, G(), "LOAD_ATTR", should_specialize=False)

@requires_specialization
def test_store_attr_specialization_user_type(self):
class B:
__slots__ = ("bar",)
Expand All @@ -211,6 +214,7 @@ def store_bar_2(type_):

self._check_specialization(store_bar_2, B(), "STORE_ATTR", should_specialize=False)

@requires_specialization_ft
def test_class_call_specialization_user_type(self):
class F:
def __init__(self):
Expand All @@ -231,6 +235,7 @@ def call_class_2(type_):

self._check_specialization(call_class_2, F, "CALL", should_specialize=False)

@requires_specialization
def test_to_bool_specialization_user_type(self):
class H:
pass
Expand Down

0 comments on commit 8651ebe

Please sign in to comment.