mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 06:49:25 +00:00
Simplify tests by replacing output capture with asserts where possible
The C++ part of the test code is modified to achieve this. As a result,
this kind of test:
```python
with capture:
kw_func1(5, y=10)
assert capture == "kw_func(x=5, y=10)"
```
can be replaced with a simple:
`assert kw_func1(5, y=10) == "x=5, y=10"`
This commit is contained in:
@@ -59,18 +59,12 @@ def test_vectorize(capture):
|
||||
|
||||
|
||||
@pytest.requires_numpy
|
||||
def test_type_selection(capture):
|
||||
def test_type_selection():
|
||||
from pybind11_tests import selective_func
|
||||
|
||||
with capture:
|
||||
selective_func(np.array([1], dtype=np.int32))
|
||||
selective_func(np.array([1.0], dtype=np.float32))
|
||||
selective_func(np.array([1.0j], dtype=np.complex64))
|
||||
assert capture == """
|
||||
Int branch taken.
|
||||
Float branch taken.
|
||||
Complex float branch taken.
|
||||
"""
|
||||
assert selective_func(np.array([1], dtype=np.int32)) == "Int branch taken."
|
||||
assert selective_func(np.array([1.0], dtype=np.float32)) == "Float branch taken."
|
||||
assert selective_func(np.array([1.0j], dtype=np.complex64)) == "Complex float branch taken."
|
||||
|
||||
|
||||
@pytest.requires_numpy
|
||||
|
||||
Reference in New Issue
Block a user