Skip to content

Commit 0bd8c25

Browse files
committed
Update test_collections.py to 3.12.2
1 parent bcb3591 commit 0bd8c25

1 file changed

Lines changed: 35 additions & 6 deletions

File tree

‎Lib/test/test_collections.py‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from collections.abc import Set, MutableSet
2626
from collections.abc import Mapping, MutableMapping, KeysView, ItemsView, ValuesView
2727
from collections.abc import Sequence, MutableSequence
28-
from collections.abc import ByteString
28+
from collections.abc import ByteString, Buffer
2929

3030

3131
class TestUserObjects(unittest.TestCase):
@@ -71,6 +71,14 @@ def test_dict_copy(self):
7171
obj[123] = "abc"
7272
self._copy_test(obj)
7373

74+
def test_dict_missing(self):
75+
class A(UserDict):
76+
def __missing__(self, key):
77+
return 456
78+
self.assertEqual(A()[123], 456)
79+
# get() ignores __missing__ on dict
80+
self.assertIs(A().get(123), None)
81+
7482

7583
################################################################################
7684
### ChainMap (helper class for configparser and the string module)
@@ -539,7 +547,7 @@ def test_odd_sizes(self):
539547
self.assertEqual(Dot(1)._replace(d=999), (999,))
540548
self.assertEqual(Dot(1)._fields, ('d',))
541549

542-
n = 5000
550+
n = support.EXCEEDS_RECURSION_LIMIT
543551
names = list(set(''.join([choice(string.ascii_letters)
544552
for j in range(10)]) for i in range(n)))
545553
n = len(names)
@@ -1629,7 +1637,7 @@ def test_Set_from_iterable(self):
16291637
class SetUsingInstanceFromIterable(MutableSet):
16301638
def __init__(self, values, created_by):
16311639
if not created_by:
1632-
raise ValueError(f'created_by must be specified')
1640+
raise ValueError('created_by must be specified')
16331641
self.created_by = created_by
16341642
self._values = set(values)
16351643

@@ -1949,13 +1957,34 @@ def assert_index_same(seq1, seq2, index_args):
19491957

19501958
def test_ByteString(self):
19511959
for sample in [bytes, bytearray]:
1952-
self.assertIsInstance(sample(), ByteString)
1960+
with self.assertWarns(DeprecationWarning):
1961+
self.assertIsInstance(sample(), ByteString)
19531962
self.assertTrue(issubclass(sample, ByteString))
19541963
for sample in [str, list, tuple]:
1955-
self.assertNotIsInstance(sample(), ByteString)
1964+
with self.assertWarns(DeprecationWarning):
1965+
self.assertNotIsInstance(sample(), ByteString)
19561966
self.assertFalse(issubclass(sample, ByteString))
1957-
self.assertNotIsInstance(memoryview(b""), ByteString)
1967+
with self.assertWarns(DeprecationWarning):
1968+
self.assertNotIsInstance(memoryview(b""), ByteString)
19581969
self.assertFalse(issubclass(memoryview, ByteString))
1970+
with self.assertWarns(DeprecationWarning):
1971+
self.validate_abstract_methods(ByteString, '__getitem__', '__len__')
1972+
1973+
with self.assertWarns(DeprecationWarning):
1974+
class X(ByteString): pass
1975+
1976+
with self.assertWarns(DeprecationWarning):
1977+
# No metaclass conflict
1978+
class Z(ByteString, Awaitable): pass
1979+
1980+
def test_Buffer(self):
1981+
for sample in [bytes, bytearray, memoryview]:
1982+
self.assertIsInstance(sample(b"x"), Buffer)
1983+
self.assertTrue(issubclass(sample, Buffer))
1984+
for sample in [str, list, tuple]:
1985+
self.assertNotIsInstance(sample(), Buffer)
1986+
self.assertFalse(issubclass(sample, Buffer))
1987+
self.validate_abstract_methods(Buffer, '__buffer__')
19591988

19601989
# TODO: RUSTPYTHON
19611990
@unittest.expectedFailure

0 commit comments

Comments
 (0)