Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(206445)

Delta Between Two Patch Sets: Lib/test/test_buffer.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years, 3 months ago
Right Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_bisect.py ('k') | Lib/test/test_builtin.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # 1 #
2 # The ndarray object from _testbuffer.c is a complete implementation of 2 # The ndarray object from _testbuffer.c is a complete implementation of
3 # a PEP-3118 buffer provider. It is independent from NumPy's ndarray 3 # a PEP-3118 buffer provider. It is independent from NumPy's ndarray
4 # and the tests don't require NumPy. 4 # and the tests don't require NumPy.
5 # 5 #
6 # If NumPy is present, some tests check both ndarray implementations 6 # If NumPy is present, some tests check both ndarray implementations
7 # against each other. 7 # against each other.
8 # 8 #
9 # Most ndarray tests also check that memoryview(ndarray) behaves in 9 # Most ndarray tests also check that memoryview(ndarray) behaves in
10 # the same way as the original. Thus, a substantial part of the 10 # the same way as the original. Thus, a substantial part of the
(...skipping 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2425 2425
2426 # ndim > 64 2426 # ndim > 64
2427 nd = ndarray([1]*128, shape=[1]*128, format='L') 2427 nd = ndarray([1]*128, shape=[1]*128, format='L')
2428 self.assertRaises(ValueError, memoryview, nd) 2428 self.assertRaises(ValueError, memoryview, nd)
2429 self.assertRaises(ValueError, nd.memoryview_from_buffer) 2429 self.assertRaises(ValueError, nd.memoryview_from_buffer)
2430 self.assertRaises(ValueError, get_contiguous, nd, PyBUF_READ, 'C') 2430 self.assertRaises(ValueError, get_contiguous, nd, PyBUF_READ, 'C')
2431 self.assertRaises(ValueError, get_contiguous, nd, PyBUF_READ, 'F') 2431 self.assertRaises(ValueError, get_contiguous, nd, PyBUF_READ, 'F')
2432 self.assertRaises(ValueError, get_contiguous, nd[::-1], PyBUF_READ, 'C') 2432 self.assertRaises(ValueError, get_contiguous, nd[::-1], PyBUF_READ, 'C')
2433 2433
2434 def test_memoryview_cast_zero_shape(self): 2434 def test_memoryview_cast_zero_shape(self):
2435 # Casts are undefined if shape contains zeros. These arrays are 2435 # Casts are undefined if buffer is multidimensional and shape
2436 # regarded as C-contiguous by Numpy and PyBuffer_GetContiguous(), 2436 # contains zeros. These arrays are regarded as C-contiguous by
2437 # so they are not caught by the test for C-contiguity in memory_cast(). 2437 # Numpy and PyBuffer_GetContiguous(), so they are not caught by
2438 # the test for C-contiguity in memory_cast().
2438 items = [1,2,3] 2439 items = [1,2,3]
2439 for shape in ([0,3,3], [3,0,3], [0,3,3]): 2440 for shape in ([0,3,3], [3,0,3], [0,3,3]):
2440 ex = ndarray(items, shape=shape) 2441 ex = ndarray(items, shape=shape)
2441 self.assertTrue(ex.c_contiguous) 2442 self.assertTrue(ex.c_contiguous)
2442 msrc = memoryview(ex) 2443 msrc = memoryview(ex)
2443 self.assertRaises(TypeError, msrc.cast, 'c') 2444 self.assertRaises(TypeError, msrc.cast, 'c')
2445 # Monodimensional empty view can be cast (issue #19014).
2446 for fmt, _, _ in iter_format(1, 'memoryview'):
2447 msrc = memoryview(b'')
2448 m = msrc.cast(fmt)
2449 self.assertEqual(m.tobytes(), b'')
2450 self.assertEqual(m.tolist(), [])
2444 2451
2445 def test_memoryview_struct_module(self): 2452 def test_memoryview_struct_module(self):
2446 2453
2447 class INT(object): 2454 class INT(object):
2448 def __init__(self, val): 2455 def __init__(self, val):
2449 self.val = val 2456 self.val = val
2450 def __int__(self): 2457 def __int__(self):
2451 return self.val 2458 return self.val
2452 2459
2453 class IDX(object): 2460 class IDX(object):
(...skipping 1822 matching lines...) Expand 10 before | Expand all | Expand 10 after
4276 4283
4277 # getbufferproc does not adhere to the new documentation 4284 # getbufferproc does not adhere to the new documentation
4278 nd = ndarray([1,2,3], [3], flags=ND_GETBUF_FAIL|ND_GETBUF_UNDEFINED) 4285 nd = ndarray([1,2,3], [3], flags=ND_GETBUF_FAIL|ND_GETBUF_UNDEFINED)
4279 self.assertRaises(BufferError, memoryview, nd) 4286 self.assertRaises(BufferError, memoryview, nd)
4280 4287
4281 def test_issue_7385(self): 4288 def test_issue_7385(self):
4282 x = ndarray([1,2,3], shape=[3], flags=ND_GETBUF_FAIL) 4289 x = ndarray([1,2,3], shape=[3], flags=ND_GETBUF_FAIL)
4283 self.assertRaises(BufferError, memoryview, x) 4290 self.assertRaises(BufferError, memoryview, x)
4284 4291
4285 4292
4286 def test_main():
4287 support.run_unittest(TestBufferProtocol)
4288
4289
4290 if __name__ == "__main__": 4293 if __name__ == "__main__":
4291 test_main() 4294 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+