@@ -591,27 +591,27 @@ def test_Struct_reinitialization(self):
591591 # Struct instance. This test can be used to detect the leak
592592 # when running with regrtest -L.
593593 s = struct .Struct ('>h' )
594- with self .assertWarns (DeprecationWarning ):
594+ msg = 'Re-initialization .* will not work'
595+ with self .assertWarnsRegex (FutureWarning , msg ):
595596 s .__init__ ('>hh' )
596597 self .assertEqual (s .format , '>hh' )
597598 packed = b'\x00 \x01 \x00 \x02 '
598599 self .assertEqual (s .pack (1 , 2 ), packed )
599600 self .assertEqual (s .unpack (packed ), (1 , 2 ))
600601
601- with self .assertWarns (DeprecationWarning ):
602- s .__init__ ('>hh' )
602+ s .__init__ ('>hh' ) # same format
603603 self .assertEqual (s .format , '>hh' )
604604 self .assertEqual (s .pack (1 , 2 ), packed )
605605 self .assertEqual (s .unpack (packed ), (1 , 2 ))
606606
607- with self .assertWarns ( DeprecationWarning ):
607+ with self .assertWarnsRegex ( FutureWarning , msg ):
608608 with self .assertRaises (UnicodeEncodeError ):
609609 s .__init__ ('\udc00 ' )
610610 self .assertEqual (s .format , '>hh' )
611611 self .assertEqual (s .pack (1 , 2 ), packed )
612612 self .assertEqual (s .unpack (packed ), (1 , 2 ))
613613
614- with self .assertWarns ( DeprecationWarning ):
614+ with self .assertWarnsRegex ( FutureWarning , msg ):
615615 with self .assertRaises (struct .error ):
616616 s .__init__ ('$' )
617617 self .assertEqual (s .format , '>hh' )
@@ -873,10 +873,10 @@ def __init__(self, *args, **kwargs):
873873 my_struct = MyStruct (format = '$' )
874874 self .assertEqual (my_struct .pack (12345 ), b'\x30 \x39 ' )
875875 with self .assertWarnsRegex (DeprecationWarning , warnmsg + ".*can't encode" ):
876- my_struct = MyStruct ('\u20ac ' )
876+ my_struct = MyStruct ('\udc00 ' )
877877 self .assertEqual (my_struct .pack (12345 ), b'\x30 \x39 ' )
878878 with self .assertWarnsRegex (DeprecationWarning , warnmsg + ".*can't encode" ):
879- my_struct = MyStruct (format = '\u20ac ' )
879+ my_struct = MyStruct (format = '\udc00 ' )
880880 self .assertEqual (my_struct .pack (12345 ), b'\x30 \x39 ' )
881881
882882 def test_custom_struct_new (self ):
@@ -885,7 +885,7 @@ class MyStruct(struct.Struct):
885885 def __new__ (cls , * args , ** kwargs ):
886886 return super ().__new__ (cls , '>h' )
887887
888- for format in '>h' , '<h' , 42 , '$' , '\u20ac ' :
888+ for format in '>h' , '<h' , 42 , '$' , '\u20ac ' , ' \udc00 ' , b' \xa4 ' :
889889 with self .subTest (format = format ):
890890 my_struct = MyStruct (format )
891891 self .assertEqual (my_struct .format , '>h' )
@@ -929,10 +929,10 @@ def __init__(self, newargs, initargs):
929929 with self .assertRaises (struct .error ):
930930 MyStruct (('>h' ,), ('$' ,))
931931 with self .assertRaises (UnicodeEncodeError ):
932- MyStruct (('\u20ac ' ,), ('>h' ,))
932+ MyStruct (('\udc00 ' ,), ('>h' ,))
933933 with self .assertWarns (FutureWarning ):
934934 with self .assertRaises (UnicodeEncodeError ):
935- MyStruct (('>h' ,), ('\u20ac ' ,))
935+ MyStruct (('>h' ,), ('\udc00 ' ,))
936936 with self .assertWarns (FutureWarning ):
937937 my_struct = MyStruct (('>h' ,), ('<h' ,))
938938 self .assertEqual (my_struct .format , '<h' )
@@ -955,7 +955,7 @@ class MyStruct(struct.Struct):
955955 with self .assertRaises (struct .error ):
956956 MyStruct ('$' )
957957 with self .assertRaises (UnicodeEncodeError ):
958- MyStruct ('\u20ac ' )
958+ MyStruct ('\udc00 ' )
959959 with self .assertRaises (TypeError ):
960960 MyStruct ('>h' , 42 )
961961 with self .assertRaises (TypeError ):
0 commit comments