summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_buffer.py
diff options
context:
space:
mode:
authorStefan Krah <skrah@bytereef.org>2019-02-02 17:57:41 (GMT)
committerGitHub <noreply@github.com>2019-02-02 17:57:41 (GMT)
commitd08ea70464cb8a1f86134dcb4a5c2eac1a02bf1a (patch)
treeea83f888c38d1b67c1c7e8ac028236a3eeb7c90d /Lib/test/test_buffer.py
parent4860f01ac0f07cdc8fc0cc27c33f5a64e5cfec9f (diff)
downloadcpython-d08ea70464cb8a1f86134dcb4a5c2eac1a02bf1a.zip
cpython-d08ea70464cb8a1f86134dcb4a5c2eac1a02bf1a.tar.gz
cpython-d08ea70464cb8a1f86134dcb4a5c2eac1a02bf1a.tar.bz2
bpo-35845: Add order={'C', 'F', 'A'} parameter to memoryview.tobytes(). (#11730)
Diffstat (limited to 'Lib/test/test_buffer.py')
-rw-r--r--Lib/test/test_buffer.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
index 761ed0a..47413c0 100644
--- a/Lib/test/test_buffer.py
+++ b/Lib/test/test_buffer.py
@@ -893,6 +893,15 @@ class TestBufferProtocol(unittest.TestCase):
y = ndarray(initlst, shape=shape, flags=ro, format=fmt)
self.assertEqual(memoryview(y), memoryview(result))
+ contig_bytes = memoryview(result).tobytes()
+ self.assertEqual(contig_bytes, contig)
+
+ contig_bytes = memoryview(result).tobytes(order=None)
+ self.assertEqual(contig_bytes, contig)
+
+ contig_bytes = memoryview(result).tobytes(order='C')
+ self.assertEqual(contig_bytes, contig)
+
# To 'F'
contig = py_buffer_to_contiguous(result, 'F', PyBUF_FULL_RO)
self.assertEqual(len(contig), nmemb * itemsize)
@@ -905,6 +914,9 @@ class TestBufferProtocol(unittest.TestCase):
format=fmt)
self.assertEqual(memoryview(y), memoryview(result))
+ contig_bytes = memoryview(result).tobytes(order='F')
+ self.assertEqual(contig_bytes, contig)
+
# To 'A'
contig = py_buffer_to_contiguous(result, 'A', PyBUF_FULL_RO)
self.assertEqual(len(contig), nmemb * itemsize)
@@ -917,6 +929,9 @@ class TestBufferProtocol(unittest.TestCase):
y = ndarray(initlst, shape=shape, flags=f|ro, format=fmt)
self.assertEqual(memoryview(y), memoryview(result))
+ contig_bytes = memoryview(result).tobytes(order='A')
+ self.assertEqual(contig_bytes, contig)
+
if is_memoryview_format(fmt):
try:
m = memoryview(result)