summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-21 22:26:24 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-21 22:26:24 (GMT)
commitd05eb0043e597cf2d5c429d0e554fd39364e36b0 (patch)
tree4c66c5a5b87ab7bdda470f5593ec38cb0a390661 /Lib/test
parent831c476169bc2430c8676bd6e3617fdc4f8933d3 (diff)
downloadcpython-d05eb0043e597cf2d5c429d0e554fd39364e36b0.zip
cpython-d05eb0043e597cf2d5c429d0e554fd39364e36b0.tar.gz
cpython-d05eb0043e597cf2d5c429d0e554fd39364e36b0.tar.bz2
Add ABC ByteString which unifies bytes and bytearray (but not memoryview).
There's no ABC for "PEP 3118 style buffer API objects" because there's no way to recognize these in Python (apart from trying to use memoryview() on them). Note that array.array really should be registered as a MutableSequence but that would require importing it whenever collections is imported.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 3ccc06c..62da9c5 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -8,6 +8,7 @@ from collections import Sized, Container, Callable
from collections import Set, MutableSet
from collections import Mapping, MutableMapping
from collections import Sequence, MutableSequence
+from collections import ByteString
class TestNamedTuple(unittest.TestCase):
@@ -260,11 +261,21 @@ class TestCollectionABCs(unittest.TestCase):
self.failUnless(issubclass(sample, Sequence))
self.failUnless(issubclass(str, Sequence))
+ def test_ByteString(self):
+ for sample in [bytes, bytearray]:
+ self.failUnless(isinstance(sample(), ByteString))
+ self.failUnless(issubclass(sample, ByteString))
+ for sample in [str, list, tuple]:
+ self.failIf(isinstance(sample(), ByteString))
+ self.failIf(issubclass(sample, ByteString))
+ self.failIf(isinstance(memoryview(b""), ByteString))
+ self.failIf(issubclass(memoryview, ByteString))
+
def test_MutableSequence(self):
- for sample in [tuple, str]:
+ for sample in [tuple, str, bytes]:
self.failIf(isinstance(sample(), MutableSequence))
self.failIf(issubclass(sample, MutableSequence))
- for sample in [list, bytes]:
+ for sample in [list, bytearray]:
self.failUnless(isinstance(sample(), MutableSequence))
self.failUnless(issubclass(sample, MutableSequence))
self.failIf(issubclass(str, MutableSequence))