(self, orig_ex, ex, req, sliced=False)
| 994 | m.tobytes() # Releasing mm didn't release m |
| 995 | |
| 996 | def verify_getbuf(self, orig_ex, ex, req, sliced=False): |
| 997 | def match(req, flag): |
| 998 | return ((req&flag) == flag) |
| 999 | |
| 1000 | if (# writable request to read-only exporter |
| 1001 | (ex.readonly and match(req, PyBUF_WRITABLE)) or |
| 1002 | # cannot match explicit contiguity request |
| 1003 | (match(req, PyBUF_C_CONTIGUOUS) and not ex.c_contiguous) or |
| 1004 | (match(req, PyBUF_F_CONTIGUOUS) and not ex.f_contiguous) or |
| 1005 | (match(req, PyBUF_ANY_CONTIGUOUS) and not ex.contiguous) or |
| 1006 | # buffer needs suboffsets |
| 1007 | (not match(req, PyBUF_INDIRECT) and ex.suboffsets) or |
| 1008 | # buffer without strides must be C-contiguous |
| 1009 | (not match(req, PyBUF_STRIDES) and not ex.c_contiguous) or |
| 1010 | # PyBUF_SIMPLE|PyBUF_FORMAT and PyBUF_WRITABLE|PyBUF_FORMAT |
| 1011 | (not match(req, PyBUF_ND) and match(req, PyBUF_FORMAT))): |
| 1012 | |
| 1013 | self.assertRaises(BufferError, ndarray, ex, getbuf=req) |
| 1014 | return |
| 1015 | |
| 1016 | if isinstance(ex, ndarray) or is_memoryview_format(ex.format): |
| 1017 | lst = ex.tolist() |
| 1018 | else: |
| 1019 | nd = ndarray(ex, getbuf=PyBUF_FULL_RO) |
| 1020 | lst = nd.tolist() |
| 1021 | |
| 1022 | # The consumer may have requested default values or a NULL format. |
| 1023 | ro = False if match(req, PyBUF_WRITABLE) else ex.readonly |
| 1024 | fmt = ex.format |
| 1025 | itemsize = ex.itemsize |
| 1026 | ndim = ex.ndim |
| 1027 | if not match(req, PyBUF_FORMAT): |
| 1028 | # itemsize refers to the original itemsize before the cast. |
| 1029 | # The equality product(shape) * itemsize = len still holds. |
| 1030 | # The equality calcsize(format) = itemsize does _not_ hold. |
| 1031 | fmt = '' |
| 1032 | lst = orig_ex.tobytes() # Issue 12834 |
| 1033 | if not match(req, PyBUF_ND): |
| 1034 | ndim = 1 |
| 1035 | shape = orig_ex.shape if match(req, PyBUF_ND) else () |
| 1036 | strides = orig_ex.strides if match(req, PyBUF_STRIDES) else () |
| 1037 | |
| 1038 | nd = ndarray(ex, getbuf=req) |
| 1039 | self.verify(nd, obj=ex, |
| 1040 | itemsize=itemsize, fmt=fmt, readonly=ro, |
| 1041 | ndim=ndim, shape=shape, strides=strides, |
| 1042 | lst=lst, sliced=sliced) |
| 1043 | |
| 1044 | @support.requires_resource('cpu') |
| 1045 | def test_ndarray_getbuf(self): |
no test coverage detected