summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-10-03 17:56:54 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-10-03 17:56:54 (GMT)
commit0e61ed8400cbd3ad4e845f23f8e36ce989271f1b (patch)
treeef007d2a623ebf55e2d390e0f16b4352d67db932 /Lib
parent026af2a597d94eb61310dd5360cf901529ef33a2 (diff)
parent60b183407cbcd19b211c2dd7ed9a59ff189844a8 (diff)
downloadcpython-0e61ed8400cbd3ad4e845f23f8e36ce989271f1b.zip
cpython-0e61ed8400cbd3ad4e845f23f8e36ce989271f1b.tar.gz
cpython-0e61ed8400cbd3ad4e845f23f8e36ce989271f1b.tar.bz2
Issue #19014: memoryview.cast() is now allowed on zero-length views.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_buffer.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
index a4fb770..1667847 100644
--- a/Lib/test/test_buffer.py
+++ b/Lib/test/test_buffer.py
@@ -2432,15 +2432,22 @@ class TestBufferProtocol(unittest.TestCase):
self.assertRaises(ValueError, get_contiguous, nd[::-1], PyBUF_READ, 'C')
def test_memoryview_cast_zero_shape(self):
- # Casts are undefined if shape contains zeros. These arrays are
- # regarded as C-contiguous by Numpy and PyBuffer_GetContiguous(),
- # so they are not caught by the test for C-contiguity in memory_cast().
+ # Casts are undefined if buffer is multidimensional and shape
+ # contains zeros. These arrays are regarded as C-contiguous by
+ # Numpy and PyBuffer_GetContiguous(), so they are not caught by
+ # the test for C-contiguity in memory_cast().
items = [1,2,3]
for shape in ([0,3,3], [3,0,3], [0,3,3]):
ex = ndarray(items, shape=shape)
self.assertTrue(ex.c_contiguous)
msrc = memoryview(ex)
self.assertRaises(TypeError, msrc.cast, 'c')
+ # Monodimensional empty view can be cast (issue #19014).
+ for fmt, _, _ in iter_format(1, 'memoryview'):
+ msrc = memoryview(b'')
+ m = msrc.cast(fmt)
+ self.assertEqual(m.tobytes(), b'')
+ self.assertEqual(m.tolist(), [])
def test_memoryview_struct_module(self):