diff options
author | INADA Naoki <songofacandy@gmail.com> | 2017-01-06 08:44:43 (GMT) |
---|---|---|
committer | INADA Naoki <songofacandy@gmail.com> | 2017-01-06 08:44:43 (GMT) |
commit | 7ed28a8914eb0ab6caf3f45f911b1e36918af38d (patch) | |
tree | b09bce7066d181fe653cff57b95cb28eb71a2f2d /Lib/test/test_bytes.py | |
parent | af6fdf3241c5d2a7e3e370c9a92af1d21c2da5ee (diff) | |
parent | a634e23209e90fd516fae1b4a303d57fdb1b9917 (diff) | |
download | cpython-7ed28a8914eb0ab6caf3f45f911b1e36918af38d.zip cpython-7ed28a8914eb0ab6caf3f45f911b1e36918af38d.tar.gz cpython-7ed28a8914eb0ab6caf3f45f911b1e36918af38d.tar.bz2 |
Merge 3.6
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r-- | Lib/test/test_bytes.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 278cfcc..671c35e 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -4,6 +4,7 @@ XXX This is a mess. Common tests should be unified with string_tests.py (and the latter should be modernized). """ +import array import os import re import sys @@ -81,6 +82,18 @@ class BaseBytesTest: self.assertRaises(ValueError, self.type2test, [Indexable(-1)]) self.assertRaises(ValueError, self.type2test, [Indexable(256)]) + def test_from_buffer(self): + a = self.type2test(array.array('B', [1, 2, 3])) + self.assertEqual(a, b"\x01\x02\x03") + + # http://bugs.python.org/issue29159 + # Fallback when __index__ raises exception other than OverflowError + class B(bytes): + def __index__(self): + raise TypeError + + self.assertEqual(self.type2test(B(b"foobar")), b"foobar") + def test_from_ssize(self): self.assertEqual(self.type2test(0), b'') self.assertEqual(self.type2test(1), b'\x00') |