| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | # Test the most dynamic corner cases of Python's runtime semantics. | |
| 2 | 2 | ||
| 3 | 3 | import builtins | |
| 4 | + import sys | ||
| 4 | 5 | import unittest | |
| 5 | 6 | ||
| 6 | 7 | from test.support import swap_item, swap_attr | |
@@ -146,5 +147,48 @@ def __missing__(self, key): | |||
| 146 | 147 | for _ in range(30): | |
| 147 | 148 | self.assertEqual(sum_1000(), expected) | |
| 148 | 149 | ||
| 150 | + | ||
| 151 | + class TestTracing(unittest.TestCase): | ||
| 152 | + | ||
| 153 | + def setUp(self): | ||
| 154 | + self.addCleanup(sys.settrace, sys.gettrace()) | ||
| 155 | + sys.settrace(None) | ||
| 156 | + | ||
| 157 | + def test_after_specialization(self): | ||
| 158 | + | ||
| 159 | + def trace(frame, event, arg): | ||
| 160 | + return trace | ||
| 161 | + | ||
| 162 | + turn_on_trace = False | ||
| 163 | + | ||
| 164 | + class C: | ||
| 165 | + def __init__(self, x): | ||
| 166 | + self.x = x | ||
| 167 | + def __del__(self): | ||
| 168 | + if turn_on_trace: | ||
| 169 | + sys.settrace(trace) | ||
| 170 | + | ||
| 171 | + def f(): | ||
| 172 | + # LOAD_GLOBAL[_BUILTIN] immediately follows the call to C.__del__ | ||
| 173 | + C(0).x, len | ||
| 174 | + | ||
| 175 | + def g(): | ||
| 176 | + # BINARY_SUSCR[_LIST_INT] immediately follows the call to C.__del__ | ||
| 177 | + [0][C(0).x] | ||
| 178 | + | ||
| 179 | + def h(): | ||
| 180 | + # BINARY_OP[_ADD_INT] immediately follows the call to C.__del__ | ||
| 181 | + 0 + C(0).x | ||
| 182 | + | ||
| 183 | + for func in (f, g, h): | ||
| 184 | + with self.subTest(func.__name__): | ||
| 185 | + for _ in range(58): | ||
| 186 | + func() | ||
| 187 | + turn_on_trace = True | ||
| 188 | + func() | ||
| 189 | + sys.settrace(None) | ||
| 190 | + turn_on_trace = False | ||
| 191 | + | ||
| 192 | + | ||
| 149 | 193 | if __name__ == "__main__": | |
| 150 | 194 | unittest.main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Ensure that tracing, ``sys.setrace()``, is turned on immediately. In | ||
| 2 | + pre-release versions of 3.11, some tracing events might have been lost when | ||
| 3 | + turning on tracing in a ``__del__`` method or interrupt. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments