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

Side by Side Diff: Lib/test/test_memoryview.py

Issue 15944: memoryviews and ctypes
Patch Set: Created 4 years, 9 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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_buffer.py ('k') | Objects/memoryobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Unit tests for the memoryview 1 """Unit tests for the memoryview
2 2
3 Some tests are in test_bytes. Many tests that require _testbuffer.ndarray 3 Some tests are in test_bytes. Many tests that require _testbuffer.ndarray
4 are in test_buffer. 4 are in test_buffer.
5 """ 5 """
6 6
7 import unittest 7 import unittest
8 import test.support 8 import test.support
9 import sys 9 import sys
10 import gc 10 import gc
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 BaseMemorySliceTests, BaseArrayMemoryTests): 483 BaseMemorySliceTests, BaseArrayMemoryTests):
484 pass 484 pass
485 485
486 class BytesMemorySliceSliceTest(unittest.TestCase, 486 class BytesMemorySliceSliceTest(unittest.TestCase,
487 BaseMemorySliceSliceTests, BaseBytesMemoryTests): 487 BaseMemorySliceSliceTests, BaseBytesMemoryTests):
488 pass 488 pass
489 489
490 class ArrayMemorySliceSliceTest(unittest.TestCase, 490 class ArrayMemorySliceSliceTest(unittest.TestCase,
491 BaseMemorySliceSliceTests, BaseArrayMemoryTests): 491 BaseMemorySliceSliceTests, BaseArrayMemoryTests):
492 pass 492 pass
493
494
495 class OtherTest(unittest.TestCase):
496 def test_ctypes_cast(self):
497 # Issue 15944: Some "ctypes" were not usable
498 ctypes = test.support.import_module("ctypes")
499 p6 = bytes(ctypes.c_double(0.6))
500
501 d = ctypes.c_double()
502 m = memoryview(d).cast("B")
503 m[:2] = p6[:2]
504 m[2:] = p6[2:]
505 self.assertEqual(d.value, 0.6)
506
507 for format in "Bbc":
508 with self.subTest(format):
509 d = ctypes.c_double()
510 m = memoryview(d).cast(format)
511 m[:2] = memoryview(p6).cast(format)[:2]
512 m[2:] = memoryview(p6).cast(format)[2:]
513 self.assertEqual(d.value, 0.6)
493 514
494 515
495 if __name__ == "__main__": 516 if __name__ == "__main__":
496 unittest.main() 517 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_buffer.py ('k') | Objects/memoryobject.c » ('j') | no next file with comments »

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