MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_cross_module_exceptions

Function test_cross_module_exceptions

tests/test_exceptions.py:47–74  ·  view source on GitHub ↗
(msg)

Source from the content-addressed store, hash-verified

45
46
47def test_cross_module_exceptions(msg):
48 with pytest.raises(RuntimeError) as excinfo:
49 cm.raise_runtime_error()
50 assert str(excinfo.value) == "My runtime error"
51
52 with pytest.raises(ValueError) as excinfo:
53 cm.raise_value_error()
54 assert str(excinfo.value) == "My value error"
55
56 with pytest.raises(ValueError) as excinfo:
57 cm.throw_pybind_value_error()
58 assert str(excinfo.value) == "pybind11 value error"
59
60 with pytest.raises(TypeError) as excinfo:
61 cm.throw_pybind_type_error()
62 assert str(excinfo.value) == "pybind11 type error"
63
64 with pytest.raises(StopIteration) as excinfo:
65 cm.throw_stop_iteration()
66
67 with pytest.raises(cm.LocalSimpleException) as excinfo:
68 cm.throw_local_simple_error()
69 assert msg(excinfo.value) == "external mod"
70
71 with pytest.raises(KeyError) as excinfo:
72 cm.throw_local_error()
73 # KeyError is a repr of the key, so it has an extra set of quotes
74 assert str(excinfo.value) == "'just local'"
75
76
77# TODO: FIXME

Callers

nothing calls this directly

Calls 2

strClass · 0.85
msgFunction · 0.85

Tested by

no test coverage detected