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:
Dean Moldovan
2016-08-12 22:28:31 +02:00
parent a0c1ccf0a9
commit 665e8804f3
18 changed files with 258 additions and 405 deletions

View File

@@ -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) {