|
25 | 25 | from collections.abc import Set, MutableSet |
26 | 26 | from collections.abc import Mapping, MutableMapping, KeysView, ItemsView, ValuesView |
27 | 27 | from collections.abc import Sequence, MutableSequence |
28 | | -from collections.abc import ByteString |
| 28 | +from collections.abc import ByteString, Buffer |
29 | 29 |
|
30 | 30 |
|
31 | 31 | class TestUserObjects(unittest.TestCase): |
@@ -71,6 +71,14 @@ def test_dict_copy(self): |
71 | 71 | obj[123] = "abc" |
72 | 72 | self._copy_test(obj) |
73 | 73 |
|
| 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 | + |
74 | 82 |
|
75 | 83 | ################################################################################ |
76 | 84 | ### ChainMap (helper class for configparser and the string module) |
@@ -539,7 +547,7 @@ def test_odd_sizes(self): |
539 | 547 | self.assertEqual(Dot(1)._replace(d=999), (999,)) |
540 | 548 | self.assertEqual(Dot(1)._fields, ('d',)) |
541 | 549 |
|
542 | | - n = 5000 |
| 550 | + n = support.EXCEEDS_RECURSION_LIMIT |
543 | 551 | names = list(set(''.join([choice(string.ascii_letters) |
544 | 552 | for j in range(10)]) for i in range(n))) |
545 | 553 | n = len(names) |
@@ -1629,7 +1637,7 @@ def test_Set_from_iterable(self): |
1629 | 1637 | class SetUsingInstanceFromIterable(MutableSet): |
1630 | 1638 | def __init__(self, values, created_by): |
1631 | 1639 | if not created_by: |
1632 | | - raise ValueError(f'created_by must be specified') |
| 1640 | + raise ValueError('created_by must be specified') |
1633 | 1641 | self.created_by = created_by |
1634 | 1642 | self._values = set(values) |
1635 | 1643 |
|
@@ -1949,13 +1957,34 @@ def assert_index_same(seq1, seq2, index_args): |
1949 | 1957 |
|
1950 | 1958 | def test_ByteString(self): |
1951 | 1959 | for sample in [bytes, bytearray]: |
1952 | | - self.assertIsInstance(sample(), ByteString) |
| 1960 | + with self.assertWarns(DeprecationWarning): |
| 1961 | + self.assertIsInstance(sample(), ByteString) |
1953 | 1962 | self.assertTrue(issubclass(sample, ByteString)) |
1954 | 1963 | for sample in [str, list, tuple]: |
1955 | | - self.assertNotIsInstance(sample(), ByteString) |
| 1964 | + with self.assertWarns(DeprecationWarning): |
| 1965 | + self.assertNotIsInstance(sample(), ByteString) |
1956 | 1966 | self.assertFalse(issubclass(sample, ByteString)) |
1957 | | - self.assertNotIsInstance(memoryview(b""), ByteString) |
| 1967 | + with self.assertWarns(DeprecationWarning): |
| 1968 | + self.assertNotIsInstance(memoryview(b""), ByteString) |
1958 | 1969 | 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__') |
1959 | 1988 |
|
1960 | 1989 | # TODO: RUSTPYTHON |
1961 | 1990 | @unittest.expectedFailure |
|
0 commit comments