|
47 | 47 |
|
48 | 48 | class BaseTest(unittest.TestCase): |
49 | 49 | """Test basics.""" |
| 50 | + generic_types = [type, tuple, list, dict, set, frozenset, enumerate, |
| 51 | + defaultdict, deque, |
| 52 | + SequenceMatcher, |
| 53 | + dircmp, |
| 54 | + FileInput, |
| 55 | + OrderedDict, Counter, UserDict, UserList, |
| 56 | + Pattern, Match, |
| 57 | + partial, partialmethod, cached_property, |
| 58 | + AbstractContextManager, AbstractAsyncContextManager, |
| 59 | + Awaitable, Coroutine, |
| 60 | + AsyncIterable, AsyncIterator, |
| 61 | + AsyncGenerator, Generator, |
| 62 | + Iterable, Iterator, |
| 63 | + Reversible, |
| 64 | + Container, Collection, |
| 65 | + Callable, |
| 66 | + Mailbox, _PartialFile, |
| 67 | + ContextVar, Token, |
| 68 | + Field, |
| 69 | + Set, MutableSet, |
| 70 | + Mapping, MutableMapping, MappingView, |
| 71 | + KeysView, ItemsView, ValuesView, |
| 72 | + Sequence, MutableSequence, |
| 73 | + MappingProxyType, AsyncGeneratorType, |
| 74 | + DirEntry, |
| 75 | + chain, |
| 76 | + TemporaryDirectory, SpooledTemporaryFile, |
| 77 | + Queue, SimpleQueue, |
| 78 | + _AssertRaisesContext, |
| 79 | + SplitResult, ParseResult, |
| 80 | + ValueProxy, ApplyResult, |
| 81 | + WeakSet, ReferenceType, ref, |
| 82 | + ShareableList, MPSimpleQueue, |
| 83 | + Future, _WorkItem, |
| 84 | + Morsel] |
| 85 | + if ctypes is not None: |
| 86 | + generic_types.extend((ctypes.Array, ctypes.LibraryLoader)) |
50 | 87 |
|
51 | 88 | def test_subscriptable(self): |
52 | | - types = [type, tuple, list, dict, set, frozenset, enumerate, |
53 | | - defaultdict, deque, |
54 | | - SequenceMatcher, |
55 | | - dircmp, |
56 | | - FileInput, |
57 | | - OrderedDict, Counter, UserDict, UserList, |
58 | | - Pattern, Match, |
59 | | - partial, partialmethod, cached_property, |
60 | | - AbstractContextManager, AbstractAsyncContextManager, |
61 | | - Awaitable, Coroutine, |
62 | | - AsyncIterable, AsyncIterator, |
63 | | - AsyncGenerator, Generator, |
64 | | - Iterable, Iterator, |
65 | | - Reversible, |
66 | | - Container, Collection, |
67 | | - Callable, |
68 | | - Mailbox, _PartialFile, |
69 | | - ContextVar, Token, |
70 | | - Field, |
71 | | - Set, MutableSet, |
72 | | - Mapping, MutableMapping, MappingView, |
73 | | - KeysView, ItemsView, ValuesView, |
74 | | - Sequence, MutableSequence, |
75 | | - MappingProxyType, AsyncGeneratorType, |
76 | | - DirEntry, |
77 | | - chain, |
78 | | - TemporaryDirectory, SpooledTemporaryFile, |
79 | | - Queue, SimpleQueue, |
80 | | - _AssertRaisesContext, |
81 | | - SplitResult, ParseResult, |
82 | | - ValueProxy, ApplyResult, |
83 | | - WeakSet, ReferenceType, ref, |
84 | | - ShareableList, MPSimpleQueue, |
85 | | - Future, _WorkItem, |
86 | | - Morsel] |
87 | | - if ctypes is not None: |
88 | | - types.extend((ctypes.Array, ctypes.LibraryLoader)) |
89 | | - for t in types: |
| 89 | + for t in self.generic_types: |
90 | 90 | if t is None: |
91 | 91 | continue |
92 | 92 | tname = t.__name__ |
@@ -293,5 +293,15 @@ def test_dir(self): |
293 | 293 | for generic_alias_property in ("__origin__", "__args__", "__parameters__"): |
294 | 294 | self.assertIn(generic_alias_property, dir_of_gen_alias) |
295 | 295 |
|
| 296 | + def test_weakref(self): |
| 297 | + for t in self.generic_types: |
| 298 | + if t is None: |
| 299 | + continue |
| 300 | + tname = t.__name__ |
| 301 | + with self.subTest(f"Testing {tname}"): |
| 302 | + alias = t[int] |
| 303 | + self.assertEqual(ref(alias)(), alias) |
| 304 | + |
| 305 | + |
296 | 306 | if __name__ == "__main__": |
297 | 307 | unittest.main() |
0 commit comments