Author: Matti Picus <matti.pi...@gmail.com> Branch: py3.6 Changeset: r97178:e0689d0f47c6 Date: 2019-08-15 00:58 +0300 http://bitbucket.org/pypy/pypy/changeset/e0689d0f47c6/
Log: test, fix subtle logic bug for memoryview.cast (when view.format is not 'B') diff --git a/lib-python/3/test/test_ssl.py b/lib-python/3/test/test_ssl.py --- a/lib-python/3/test/test_ssl.py +++ b/lib-python/3/test/test_ssl.py @@ -2844,10 +2844,6 @@ else: s.close() - def test_socketserver_urlib_uses_bisect(self): - b = urllib.request.bisect - raise ValueError('urllib.request.bisect is %s' % str(b)) - def test_socketserver(self): """Using socketserver to create and manage SSL connections.""" server = make_https_server(self, certfile=CERTFILE) diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py --- a/pypy/objspace/std/memoryobject.py +++ b/pypy/objspace/std/memoryobject.py @@ -482,8 +482,8 @@ " with an optional '@'") origfmt = view.getformat() - if self.get_native_fmtchar(origfmt) < 0 or \ - (not is_byte_format(fmt) and not is_byte_format(origfmt)): + if (self.get_native_fmtchar(origfmt) < 0 or \ + (not is_byte_format(origfmt))) and (not is_byte_format(fmt)): raise oefmt(space.w_TypeError, "memoryview: cannot cast between" " two non-byte formats") diff --git a/pypy/objspace/std/test/test_memoryobject.py b/pypy/objspace/std/test/test_memoryobject.py --- a/pypy/objspace/std/test/test_memoryobject.py +++ b/pypy/objspace/std/test/test_memoryobject.py @@ -487,6 +487,32 @@ assert list(reversed(view)) == revlist assert list(reversed(view)) == view[::-1].tolist() + +class AppTestMemoryViewMockBuffer(object): + spaceconfig = dict(usemodules=['__pypy__']) + + def test_cast_with_byteorder(self): + import sys + if '__pypy__' not in sys.modules: + skip('PyPy-only test') + + # create a memoryview with format '<B' (like ctypes does) + from __pypy__ import bufferable, newmemoryview + class B(bufferable.bufferable): + def __init__(self): + self.data = bytearray(b'abc') + + def __buffer__(self, flags): + return newmemoryview(memoryview(self.data), 1, '<B') + + + obj = B() + buf = memoryview(obj) + assert buf.format == '<B' + # ensure we can cast this even though the format starts with '<' + assert buf.cast('B')[0] == ord('a') + + class AppTestMemoryViewReversed(object): spaceconfig = dict(usemodules=['array']) def test_reversed_non_bytes(self): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit