@@ -1077,6 +1077,32 @@ def test_iter_nextitem(self):
10771077 with self .assertRaisesRegex (TypeError , regex ):
10781078 PyIter_NextItem (10 )
10791079
1080+ def test_object_setattr_null_exc (self ):
1081+ class Obj :
1082+ pass
1083+ obj = Obj ()
1084+ obj .attr = 123
1085+
1086+ exc = ValueError ("error" )
1087+ with self .assertRaises (SystemError ) as cm :
1088+ _testcapi .object_setattr_null_exc (obj , 'attr' , exc )
1089+ self .assertIs (cm .exception .__context__ , exc )
1090+ self .assertIsNone (cm .exception .__cause__ )
1091+ self .assertHasAttr (obj , 'attr' )
1092+
1093+ with self .assertRaises (SystemError ) as cm :
1094+ _testcapi .object_setattrstring_null_exc (obj , 'attr' , exc )
1095+ self .assertIs (cm .exception .__context__ , exc )
1096+ self .assertIsNone (cm .exception .__cause__ )
1097+ self .assertHasAttr (obj , 'attr' )
1098+
1099+ with self .assertRaises (SystemError ) as cm :
1100+ # undecodable name
1101+ _testcapi .object_setattrstring_null_exc (obj , b'\xff ' , exc )
1102+ self .assertIs (cm .exception .__context__ , exc )
1103+ self .assertIsNone (cm .exception .__cause__ )
1104+ self .assertHasAttr (obj , 'attr' )
1105+
10801106
10811107if __name__ == "__main__" :
10821108 unittest .main ()
0 commit comments