mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +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:
@@ -10,13 +10,14 @@
|
||||
#include "pybind11_tests.h"
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
void kw_func(int x, int y) { std::cout << "kw_func(x=" << x << ", y=" << y << ")" << std::endl; }
|
||||
std::string kw_func(int x, int y) { return "x=" + std::to_string(x) + ", y=" + std::to_string(y); }
|
||||
|
||||
void kw_func4(const std::vector<int> &entries) {
|
||||
std::cout << "kw_func4: ";
|
||||
std::string kw_func4(const std::vector<int> &entries) {
|
||||
std::string ret = "{";
|
||||
for (int i : entries)
|
||||
std::cout << i << " ";
|
||||
std::cout << endl;
|
||||
ret += std::to_string(i) + " ";
|
||||
ret.back() = '}';
|
||||
return ret;
|
||||
}
|
||||
|
||||
py::object call_kw_func(py::function f) {
|
||||
|
||||
Reference in New Issue
Block a user