diff options
author | Xiang Zhang <angwerzx@126.com> | 2017-03-14 07:27:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-14 07:27:01 (GMT) |
commit | faa2cc63e45bc7d7ffab84bebe5a9f4fe065bd96 (patch) | |
tree | 4f1e0ff182e1dae2da17be56c69e21f730863f52 /Lib/test | |
parent | 388e2568fc919a177df2d2949b575c553aea84ac (diff) | |
download | cpython-faa2cc63e45bc7d7ffab84bebe5a9f4fe065bd96.zip cpython-faa2cc63e45bc7d7ffab84bebe5a9f4fe065bd96.tar.gz cpython-faa2cc63e45bc7d7ffab84bebe5a9f4fe065bd96.tar.bz2 |
bpo-28856: Let %b format for bytes support objects that follow the buffer protocol (GH-664)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_format.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index 83eb29f..b6ba2e5 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -315,10 +315,12 @@ class FormatTest(unittest.TestCase): testcommon(b"%b", b"abc", b"abc") testcommon(b"%b", bytearray(b"def"), b"def") testcommon(b"%b", fb, b"123") + testcommon(b"%b", memoryview(b"abc"), b"abc") # # %s is an alias for %b -- should only be used for Py2/3 code testcommon(b"%s", b"abc", b"abc") testcommon(b"%s", bytearray(b"def"), b"def") testcommon(b"%s", fb, b"123") + testcommon(b"%s", memoryview(b"abc"), b"abc") # %a will give the equivalent of # repr(some_obj).encode('ascii', 'backslashreplace') testcommon(b"%a", 3.14, b"3.14") @@ -377,9 +379,11 @@ class FormatTest(unittest.TestCase): test_exc(b"%c", 3.14, TypeError, "%c requires an integer in range(256) or a single byte") test_exc(b"%b", "Xc", TypeError, - "%b requires bytes, or an object that implements __bytes__, not 'str'") + "%b requires a bytes-like object, " + "or an object that implements __bytes__, not 'str'") test_exc(b"%s", "Wd", TypeError, - "%b requires bytes, or an object that implements __bytes__, not 'str'") + "%b requires a bytes-like object, " + "or an object that implements __bytes__, not 'str'") if maxsize == 2**31-1: # crashes 2.2.1 and earlier: |