mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #15944: memoryview: Allow arbitrary formats when casting to bytes.
Original patch by Martin Panter.
This commit is contained in:
parent
917c2c3654
commit
0c51595a78
5 changed files with 57 additions and 11 deletions
|
@ -492,5 +492,26 @@ class ArrayMemorySliceSliceTest(unittest.TestCase,
|
|||
pass
|
||||
|
||||
|
||||
class OtherTest(unittest.TestCase):
|
||||
def test_ctypes_cast(self):
|
||||
# Issue 15944: Allow all source formats when casting to bytes.
|
||||
ctypes = test.support.import_module("ctypes")
|
||||
p6 = bytes(ctypes.c_double(0.6))
|
||||
|
||||
d = ctypes.c_double()
|
||||
m = memoryview(d).cast("B")
|
||||
m[:2] = p6[:2]
|
||||
m[2:] = p6[2:]
|
||||
self.assertEqual(d.value, 0.6)
|
||||
|
||||
for format in "Bbc":
|
||||
with self.subTest(format):
|
||||
d = ctypes.c_double()
|
||||
m = memoryview(d).cast(format)
|
||||
m[:2] = memoryview(p6).cast(format)[:2]
|
||||
m[2:] = memoryview(p6).cast(format)[2:]
|
||||
self.assertEqual(d.value, 0.6)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue