Skip to content

Commit 3272520

Browse files
committed
Add tests on "c", "n" and "N" formats
1 parent 134f0de commit 3272520

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lib/test/test_memoryview.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,24 @@ def check_equal(view, is_equal):
601601
m2 = m.cast('@' + m.format)
602602
check_equal(m2, True)
603603

604+
# Test 'c' format
605+
a = array.array('B', [1, 2, 3])
606+
m = memoryview(a.tobytes()).cast('c')
607+
check_equal(m, True)
608+
609+
# Test 'n' and 'N' formats
610+
if struct.calcsize('L') == struct.calcsize('N'):
611+
int_format = 'L'
612+
elif struct.calcsize('Q') == struct.calcsize('N'):
613+
int_format = 'Q'
614+
else:
615+
raise ValueError('unable to get size_t format in struct')
616+
a = array.array(int_format, [1, 2, 3])
617+
m = memoryview(a.tobytes()).cast('N')
618+
check_equal(m, True)
619+
m = memoryview(a.tobytes()).cast('n')
620+
check_equal(m, True)
621+
604622
# Test '?' format
605623
m = memoryview(b'\0\1\2').cast('?')
606624
check_equal(m, True)

0 commit comments

Comments
 (0)