|
26 | 26 | from collections.abc import Set, MutableSet
|
27 | 27 | from collections.abc import Mapping, MutableMapping, KeysView, ItemsView, ValuesView
|
28 | 28 | from collections.abc import Sequence, MutableSequence
|
29 |
| -from collections.abc import Buffer |
| 29 | +from collections.abc import ByteString, Buffer |
30 | 30 |
|
31 | 31 |
|
32 | 32 | class TestUserObjects(unittest.TestCase):
|
@@ -1934,6 +1934,28 @@ def assert_index_same(seq1, seq2, index_args):
|
1934 | 1934 | assert_index_same(
|
1935 | 1935 | nativeseq, seqseq, (letter, start, stop))
|
1936 | 1936 |
|
| 1937 | + def test_ByteString(self): |
| 1938 | + for sample in [bytes, bytearray]: |
| 1939 | + with self.assertWarns(DeprecationWarning): |
| 1940 | + self.assertIsInstance(sample(), ByteString) |
| 1941 | + self.assertTrue(issubclass(sample, ByteString)) |
| 1942 | + for sample in [str, list, tuple]: |
| 1943 | + with self.assertWarns(DeprecationWarning): |
| 1944 | + self.assertNotIsInstance(sample(), ByteString) |
| 1945 | + self.assertFalse(issubclass(sample, ByteString)) |
| 1946 | + with self.assertWarns(DeprecationWarning): |
| 1947 | + self.assertNotIsInstance(memoryview(b""), ByteString) |
| 1948 | + self.assertFalse(issubclass(memoryview, ByteString)) |
| 1949 | + with self.assertWarns(DeprecationWarning): |
| 1950 | + self.validate_abstract_methods(ByteString, '__getitem__', '__len__') |
| 1951 | + |
| 1952 | + with self.assertWarns(DeprecationWarning): |
| 1953 | + class X(ByteString): pass |
| 1954 | + |
| 1955 | + with self.assertWarns(DeprecationWarning): |
| 1956 | + # No metaclass conflict |
| 1957 | + class Z(ByteString, Awaitable): pass |
| 1958 | + |
1937 | 1959 | def test_Buffer(self):
|
1938 | 1960 | for sample in [bytes, bytearray, memoryview]:
|
1939 | 1961 | self.assertIsInstance(sample(b"x"), Buffer)
|
|
0 commit comments