@@ -579,15 +579,40 @@ def test_compare_equal(self):
579579 # A memoryview is equal to itself: there is no need to compare
580580 # individual values. This is not true for float values since they can
581581 # be NaN, and NaN is not equal to itself.
582+
583+ # Test integer formats
582584 for int_format in 'bBhHiIlLqQ' :
583585 with self .subTest (format = int_format ):
584586 a = array .array (int_format , [1 , 2 , 3 ])
585587 m = memoryview (a )
586588 self .assertTrue (m == m )
587589 self .assertFalse (m != m )
588590
591+ if int_format in 'bB' :
592+ m2 = m .cast ('@' + m .format )
593+ self .assertTrue (m2 == m2 )
594+ self .assertFalse (m2 != m2 )
595+
596+ # Test '?' format
597+ m = memoryview (b'\0 \1 \2 ' ).cast ('?' )
598+ self .assertTrue (m == m )
599+ self .assertFalse (m != m )
600+
601+ # Test 'P' format
602+ if struct .calcsize ('L' ) == struct .calcsize ('P' ):
603+ int_format = 'L'
604+ elif struct .calcsize ('Q' ) == struct .calcsize ('P' ):
605+ int_format = 'Q'
606+ else :
607+ raise ValueError ('unable to get void* format in struct' )
608+ a = array .array (int_format , [1 , 2 , 3 ])
609+ m = memoryview (a .tobytes ()).cast ('P' )
610+ self .assertTrue (m == m )
611+ self .assertFalse (m != m )
612+
613+ # Test float formats
589614 for float_format in 'fd' :
590- with self .subTest (format = int_format ):
615+ with self .subTest (format = float_format ):
591616 a = array .array (float_format , [1.0 , 2.0 , float ('nan' )])
592617 m = memoryview (a )
593618 # nan is not equal to nan
0 commit comments