diff options
author | Xiang Zhang <angwerzx@126.com> | 2017-03-14 07:07:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-14 07:07:15 (GMT) |
commit | 7e2a54cdd977078b40b82182e46b201f8163f659 (patch) | |
tree | 2a5116ab3cd37f53f7bf5b1ba9b569fb7e887e54 /Lib/test/test_format.py | |
parent | 9e52c907b5511393ab7e44321e9521fe0967e34d (diff) | |
download | cpython-7e2a54cdd977078b40b82182e46b201f8163f659.zip cpython-7e2a54cdd977078b40b82182e46b201f8163f659.tar.gz cpython-7e2a54cdd977078b40b82182e46b201f8163f659.tar.bz2 |
bpo-28856: Let %b format for bytes support objects that follow the buffer protocol (GH-546)
Diffstat (limited to 'Lib/test/test_format.py')
-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 b283501..83804cb 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -332,10 +332,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") @@ -372,9 +374,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: |