|
1 | 1 | # Python test set -- part 6, built-in types |
2 | 2 |
|
3 | | -from test.support import run_with_locale, is_apple_mobile, cpython_only, MISSING_C_DOCSTRINGS |
| 3 | +from test.support import ( |
| 4 | + run_with_locale, is_apple_mobile, cpython_only, |
| 5 | + iter_builtin_types, iter_slot_wrappers, |
| 6 | + MISSING_C_DOCSTRINGS, |
| 7 | +) |
4 | 8 | from test.test_import import no_rerun |
5 | 9 | import collections.abc |
6 | 10 | from collections import namedtuple, UserDict |
@@ -30,26 +34,6 @@ def clear_typing_caches(): |
30 | 34 | f() |
31 | 35 |
|
32 | 36 |
|
33 | | -def iter_builtin_types(): |
34 | | - for obj in __builtins__.values(): |
35 | | - if not isinstance(obj, type): |
36 | | - continue |
37 | | - cls = obj |
38 | | - if cls.__module__ != 'builtins': |
39 | | - continue |
40 | | - yield cls |
41 | | - |
42 | | - |
43 | | -@cpython_only |
44 | | -def iter_own_slot_wrappers(cls): |
45 | | - for name, value in vars(cls).items(): |
46 | | - if not name.startswith('__') or not name.endswith('__'): |
47 | | - continue |
48 | | - if 'slot wrapper' not in str(value): |
49 | | - continue |
50 | | - yield name |
51 | | - |
52 | | - |
53 | 37 | class TypesTests(unittest.TestCase): |
54 | 38 |
|
55 | 39 | def test_truth_values(self): |
@@ -2380,32 +2364,32 @@ def setUpClass(cls): |
2380 | 2364 |
|
2381 | 2365 | @cpython_only |
2382 | 2366 | @no_rerun('channels (and queues) might have a refleak; see gh-122199') |
2383 | | - def test_slot_wrappers(self): |
| 2367 | + def test_static_types_inherited_slots(self): |
2384 | 2368 | rch, sch = interpreters.channels.create() |
2385 | 2369 |
|
2386 | 2370 | slots = [] |
2387 | 2371 | script = '' |
2388 | 2372 | for cls in iter_builtin_types(): |
2389 | | - for slot in iter_own_slot_wrappers(cls): |
2390 | | - slots.append((cls, slot)) |
| 2373 | + for slot, own in iter_slot_wrappers(cls): |
| 2374 | + slots.append((cls, slot, own)) |
2391 | 2375 | script += textwrap.dedent(f""" |
2392 | 2376 | text = repr({cls.__name__}.{slot}) |
2393 | 2377 | sch.send_nowait(({cls.__name__!r}, {slot!r}, text)) |
2394 | 2378 | """) |
2395 | 2379 |
|
2396 | 2380 | exec(script) |
2397 | 2381 | all_expected = [] |
2398 | | - for cls, slot in slots: |
| 2382 | + for cls, slot, _ in slots: |
2399 | 2383 | result = rch.recv() |
2400 | | - assert result == (cls.__name__, slot, result[2]), (cls, slot, result) |
| 2384 | + assert result == (cls.__name__, slot, result[-1]), (cls, slot, result) |
2401 | 2385 | all_expected.append(result) |
2402 | 2386 |
|
2403 | 2387 | interp = interpreters.create() |
2404 | 2388 | interp.exec('from test.support import interpreters') |
2405 | 2389 | interp.prepare_main(sch=sch) |
2406 | 2390 | interp.exec(script) |
2407 | 2391 |
|
2408 | | - for i, _ in enumerate(slots): |
| 2392 | + for i, (cls, slot, _) in enumerate(slots): |
2409 | 2393 | with self.subTest(cls=cls, slot=slot): |
2410 | 2394 | expected = all_expected[i] |
2411 | 2395 | result = rch.recv() |
|
0 commit comments