@@ -44,8 +44,8 @@ def test_exception_group_init_when_exceptions_messages_not_equal():
44
44
45
45
46
46
def test_exception_group_bool ():
47
- assert not ExceptionGroup ("E" , [], [])
48
- assert ExceptionGroup ("E" , [ValueError ()], ["" ])
47
+ assert bool ( ExceptionGroup ("E" , [], [])) is False
48
+ assert bool ( ExceptionGroup ("E" , [ValueError ()], ["" ])) is True
49
49
50
50
51
51
def test_exception_group_contains ():
@@ -62,6 +62,15 @@ def test_exception_group_find():
62
62
assert group .find (TypeError ) is None
63
63
64
64
65
+ def test_exception_group_find_callable_predicate ():
66
+ err = ValueError ()
67
+ group = ExceptionGroup ("E" , [err ], ["" ])
68
+ predicate1 = lambda e : e is err
69
+ assert group .find (predicate1 ) is err
70
+ predicate2 = lambda _ : False
71
+ assert group .find (predicate2 ) is None
72
+
73
+
65
74
def test_exception_group_find_with_source ():
66
75
err = ValueError ()
67
76
group = ExceptionGroup ("E" , [err ], ["x" ])
@@ -89,6 +98,45 @@ def test_exception_group_len():
89
98
assert len (ExceptionGroup ("E" , [ValueError ()], ["" ])) == 1
90
99
91
100
101
+ def test_exception_group_maybe_reraise_empty ():
102
+ group = ExceptionGroup ("E" , [], [])
103
+ group .maybe_reraise ()
104
+
105
+
106
+ def test_exception_group_maybe_reraise_unwrap ():
107
+ err = ValueError ()
108
+ group = ExceptionGroup ("E" , [err ], ["" ])
109
+ try :
110
+ group .maybe_reraise ()
111
+ except ValueError as caught_err :
112
+ assert caught_err is err
113
+ try :
114
+ group .maybe_reraise (unwrap = False )
115
+ except ExceptionGroup as caught_err :
116
+ assert caught_err is group
117
+
118
+
119
+ def test_exception_group_maybe_reraise_from_exception ():
120
+ err = ValueError ()
121
+ try :
122
+ raise_group ()
123
+ except ExceptionGroup as group1 :
124
+ group2 = ExceptionGroup ("E" , [err ], ["" ])
125
+ try :
126
+ group2 .maybe_reraise ()
127
+ except ValueError as caught_err :
128
+ assert caught_err .__cause__ is group1
129
+ try :
130
+ raise_group ()
131
+ except ExceptionGroup as group1 :
132
+ group2 = ExceptionGroup ("E" , [err ], ["" ])
133
+ err2 = TypeError ()
134
+ try :
135
+ group2 .maybe_reraise (from_exception = err2 )
136
+ except ValueError as caught_err :
137
+ assert caught_err .__cause__ is err2
138
+
139
+
92
140
def test_exception_group_str ():
93
141
memberA = ValueError ("memberA" )
94
142
memberB = ValueError ("memberB" )
0 commit comments