aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_kwargs_and_defaults.py
Commit message (Collapse)AuthorAgeFilesLines
* style: use Black everywhere (#2594)Henry Schreiner2020-10-161-25/+70
| | | | | * style: use Black everywhere * style: minor touchup from review
* feat: py::pos_only (#2459)Henry Schreiner2020-09-041-18/+66
| | | | | | | | | * feat: py::pos_only * fix: review points from @YannickJadoul * fix: review points from @bstaletic * refactor: kwonly -> kw_only
* tests: cleanup and ci hardening (#2397)Henry Schreiner2020-08-161-2/+4
| | | | | | | | | | | | | | | | | | | | | | | * tests: refactor and cleanup * refactor: more consistent * tests: vendor six * tests: more xfails, nicer system * tests: simplify to info * tests: suggestions from @YannickJadoul and @bstaletic * tests: restore some pypy tests that now pass * tests: rename info to env * tests: strict False/True * tests: drop explicit strict=True again * tests: reduce minimum PyTest to 3.1
* tests: Consolidate version (2 vs. 3) and platform (CPython vs. PyPy) checks ↵Eric Cousineau2020-08-141-6/+1
| | | | | | | (#2376) Fix logic in test_bytes_to_string Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
* Avoid attr("__repr__") in initialize_generic (#2317)Boris Staletic2020-07-241-0/+2
| | | | | | | If the default argument value is a class, and not an instance of a class, `a.value.attr("__repr__")` raises a `ValueError`. Switching to `repr(a.value)` makes this use case work. Fixes #2028
* test: support pypy2 7.3Henry Schreiner2020-07-231-0/+7
|
* ci: GHA basic format & pre-commit (#2309)Henry Schreiner2020-07-201-0/+1
|
* rename args_kw_only to kwonlySebastian Koslowski2020-04-261-1/+1
|
* Support keyword-only argumentsJason Rhinelander2020-04-261-0/+38
| | | | | | | | | | | | | | | | | This adds support for a `py::args_kw_only()` annotation that can be specified between `py::arg` annotations to indicate that any following arguments are keyword-only. This allows you to write: m.def("f", [](int a, int b) { /* ... */ }, py::arg("a"), py::args_kw_only(), py::arg("b")); and have it work like Python 3's: def f(a, *, b): # ... with respect to how `a` and `b` arguments are accepted (that is, `a` can be positional or by keyword; `b` can only be specified by keyword).
* Add spaces around "=" in signature repr.Antony Lee2017-12-271-7/+7
| | | | | | | | | | | | | | | | | PEP8 indicates (correctly, IMO) that when an annotation is present, the signature should include spaces around the equal sign, i.e. def f(x: int = 1): ... instead of def f(x: int=1): ... (in the latter case the equal appears to bind to the type, not to the argument). pybind11 signatures always includes a type annotation so we can always add the spaces.
* Added py::args ref counting testsJason Rhinelander2017-12-231-0/+40
|
* Update all remaining tests to new test stylesJason Rhinelander2017-08-051-36/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This udpates all the remaining tests to the new test suite code and comment styles started in #898. For the most part, the test coverage here is unchanged, with a few minor exceptions as noted below. - test_constants_and_functions: this adds more overload tests with overloads with different number of arguments for more comprehensive overload_cast testing. The test style conversion broke the overload tests under MSVC 2015, prompting the additional tests while looking for a workaround. - test_eigen: this dropped the unused functions `get_cm_corners` and `get_cm_corners_const`--these same tests were duplicates of the same things provided (and used) via ReturnTester methods. - test_opaque_types: this test had a hidden dependence on ExampleMandA which is now fixed by using the global UserType which suffices for the relevant test. - test_methods_and_attributes: this required some additions to UserType to make it usable as a replacement for the test's previous SimpleType: UserType gained a value mutator, and the `value` property is not mutable (it was previously readonly). Some overload tests were also added to better test overload_cast (as described above). - test_numpy_array: removed the untemplated mutate_data/mutate_data_t: the templated versions with an empty parameter pack expand to the same thing. - test_stl: this was already mostly in the new style; this just tweaks things a bit, localizing a class, and adding some missing `// test_whatever` comments. - test_virtual_functions: like `test_stl`, this was mostly in the new test style already, but needed some `// test_whatever` comments. This commit also moves the inherited virtual example code to the end of the file, after the main set of tests (since it is less important than the other tests, and rather length); it also got renamed to `test_inherited_virtuals` (from `test_inheriting_repeat`) because it tests both inherited virtual approaches, not just the repeat approach.
* Minor pytest maintenance (#702)Dean Moldovan2017-03-101-4/+2
| | | | | | | | | | | | | * Add `pytest.ini` config file and set default options there instead of in `CMakeLists.txt` (command line arguments). * Change all output capture from `capfd` (filedescriptors) to `capsys` (Python's `sys.stdout` and `sys.stderr`). This avoids capturing low-level C errors, e.g. from the debug build of Python. * Set pytest minimum version to 3.0 to make it easier to use new features. Removed conditional use of `excinfo.match()`. * Clean up some leftover function-level `@pytest.requires_numpy`.
* Skip .match on older pytest (pre-3.0)Jason Rhinelander2017-02-261-2/+4
| | | | Fixes test failure on Fedora 25.
* Workaround style check false positiveJason Rhinelander2017-02-241-1/+1
|
* Show kwargs in failed method invocationJason Rhinelander2017-02-241-13/+15
| | | | | | | | With the previous commit, output can be very confusing because you only see positional arguments in the "invoked with" line, but you can have a failure from kwargs as well (in particular, when a value is invalidly specified via both via positional and kwargs). This commits adds kwargs to the output, and updates the associated tests to match.
* Add support for positional args with args/kwargsJason Rhinelander2017-01-311-0/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit rewrites the function dispatcher code to support mixing regular arguments with py::args/py::kwargs arguments. It also simplifies the argument loader noticeably as it no longer has to worry about args/kwargs: all of that is now sorted out in the dispatcher, which now simply appends a tuple/dict if the function takes py::args/py::kwargs, then passes all the arguments in a vector. When the argument loader hit a py::args or py::kwargs, it doesn't do anything special: it just calls the appropriate type_caster just like it does for any other argument (thus removing the previous special cases for args/kwargs). Switching to passing arguments in a single std::vector instead of a pair of tuples also makes things simpler, both in the dispatch and the argument_loader: since this argument list is strictly pybind-internal (i.e. it never goes to Python) we have no particular reason to use a Python tuple here. Some (intentional) restrictions: - you may not bind a function that has args/kwargs somewhere other than the end (this somewhat matches Python, and keeps the dispatch code a little cleaner by being able to not worry about where to inject the args/kwargs in the argument list). - If you specify an argument both positionally and via a keyword argument, you get a TypeError alerting you to this (as you do in Python).
* nicer error message for invalid function argumentsWenzel Jakob2016-09-191-2/+3
|
* Remove superseded handle::operator() overloadsDean Moldovan2016-09-061-5/+2
| | | | | | The variadic handle::operator() offers the same functionality as well as mixed positional, keyword, * and ** arguments. The tests are also superseded by the ones in `test_callbacks`.
* Simplify more tests by replacing capture with assertDean Moldovan2016-08-191-18/+10
|
* Simplify tests by replacing output capture with asserts where possibleDean Moldovan2016-08-191-50/+24
| | | | | | | | | | | | | | | 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"`
* Port tests to pytestDean Moldovan2016-08-191-0/+93
Use simple asserts and pytest's powerful introspection to make testing simpler. This merges the old .py/.ref file pairs into simple .py files where the expected values are right next to the code being tested. This commit does not touch the C++ part of the code and replicates the Python tests exactly like the old .ref-file-based approach.