Skip to content
This repository was archived by the owner on Nov 2, 2022. It is now read-only.

Commit 3a514f4

Browse files
author
Robert Schindler
committed
Add some tests for the except API
1 parent 74c0687 commit 3a514f4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

exceptiongroup/_tests/test_exceptiongroup.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,52 @@ def test_exception_group_init_when_exceptions_messages_not_equal():
4343
)
4444

4545

46+
def test_exception_group_bool():
47+
assert not ExceptionGroup("E", [], [])
48+
assert ExceptionGroup("E", [ValueError()], [""])
49+
50+
51+
def test_exception_group_contains():
52+
err = ValueError()
53+
group = ExceptionGroup("E", [err], [""])
54+
assert err in group
55+
assert ValueError() not in group
56+
57+
58+
def test_exception_group_find():
59+
err = ValueError()
60+
group = ExceptionGroup("E", [err], [""])
61+
assert group.find(ValueError) is err
62+
assert group.find(TypeError) is None
63+
64+
65+
def test_exception_group_find_with_source():
66+
err = ValueError()
67+
group = ExceptionGroup("E", [err], ["x"])
68+
assert group.find(ValueError, with_source=True) == (err, "x")
69+
assert group.find(TypeError, with_source=True) is None
70+
71+
72+
def test_exception_group_findall():
73+
err1 = ValueError()
74+
err2 = TypeError()
75+
group = ExceptionGroup("E", [err1, err2], ["", ""])
76+
assert tuple(group.findall(ValueError)) == (err1,)
77+
assert tuple(group.findall((ValueError, TypeError))) == (err1, err2)
78+
79+
80+
def test_exception_group_iter():
81+
err1 = ValueError()
82+
err2 = ValueError()
83+
group = ExceptionGroup("E", [err1, err2], ["", ""])
84+
assert tuple(group) == ((err1, ""), (err2, ""))
85+
86+
87+
def test_exception_group_len():
88+
assert len(ExceptionGroup("E", [], [])) == 0
89+
assert len(ExceptionGroup("E", [ValueError()], [""])) == 1
90+
91+
4692
def test_exception_group_str():
4793
memberA = ValueError("memberA")
4894
memberB = ValueError("memberB")

0 commit comments

Comments
 (0)