@@ -205,6 +205,13 @@ def test_notes_is_list_of_strings_if_it_exists(self):
205
205
eg .add_note (note )
206
206
self .assertEqual (eg .__notes__ , [note ])
207
207
208
+ def test_derive_doesn_copy_notes (self ):
209
+ eg = create_simple_eg ()
210
+ eg .add_note ("hello" )
211
+ assert eg .__notes__ == ["hello" ]
212
+ eg2 = eg .derive ([ValueError ()])
213
+ assert not hasattr (eg2 , "__notes__" )
214
+
208
215
209
216
class ExceptionGroupTestBase (unittest .TestCase ):
210
217
def assertMatchesTemplate (self , exc , exc_type , template ):
@@ -786,6 +793,7 @@ def derive(self, excs):
786
793
except ValueError as ve :
787
794
raise EG ("eg" , [ve , nested ], 42 )
788
795
except EG as e :
796
+ e .add_note ("hello" )
789
797
eg = e
790
798
791
799
self .assertMatchesTemplate (eg , EG , [ValueError (1 ), [TypeError (2 )]])
@@ -796,29 +804,35 @@ def derive(self, excs):
796
804
self .assertMatchesTemplate (rest , EG , [ValueError (1 ), [TypeError (2 )]])
797
805
self .assertEqual (rest .code , 42 )
798
806
self .assertEqual (rest .exceptions [1 ].code , 101 )
807
+ self .assertEqual (rest .__notes__ , ["hello" ])
799
808
800
809
# Match Everything
801
810
match , rest = self .split_exception_group (eg , (ValueError , TypeError ))
802
811
self .assertMatchesTemplate (match , EG , [ValueError (1 ), [TypeError (2 )]])
803
812
self .assertEqual (match .code , 42 )
804
813
self .assertEqual (match .exceptions [1 ].code , 101 )
814
+ self .assertEqual (match .__notes__ , ["hello" ])
805
815
self .assertIsNone (rest )
806
816
807
817
# Match ValueErrors
808
818
match , rest = self .split_exception_group (eg , ValueError )
809
819
self .assertMatchesTemplate (match , EG , [ValueError (1 )])
810
820
self .assertEqual (match .code , 42 )
821
+ self .assertEqual (match .__notes__ , ["hello" ])
811
822
self .assertMatchesTemplate (rest , EG , [[TypeError (2 )]])
812
823
self .assertEqual (rest .code , 42 )
813
824
self .assertEqual (rest .exceptions [0 ].code , 101 )
825
+ self .assertEqual (rest .__notes__ , ["hello" ])
814
826
815
827
# Match TypeErrors
816
828
match , rest = self .split_exception_group (eg , TypeError )
817
829
self .assertMatchesTemplate (match , EG , [[TypeError (2 )]])
818
830
self .assertEqual (match .code , 42 )
819
831
self .assertEqual (match .exceptions [0 ].code , 101 )
832
+ self .assertEqual (match .__notes__ , ["hello" ])
820
833
self .assertMatchesTemplate (rest , EG , [ValueError (1 )])
821
834
self .assertEqual (rest .code , 42 )
835
+ self .assertEqual (rest .__notes__ , ["hello" ])
822
836
823
837
824
838
def test_repr ():
0 commit comments