1. 31 Aug, 2021 1 commit
    • Tailing Yuan's avatar
      fix: memory leak in cpp_function (#3228) (#3229) · d6474ed7
      Tailing Yuan authored
      
      
      * fix: memory leak in cpp_function (#3228)
      
      * add a test case to check objects are deconstructed in cpp_function
      
      * update the test case about cpp_function
      
      * fix the test case about cpp_function: remove "noexcept"
      
      * Actually calling func. CHECK(stat.alive() == 2); Manually verified that the new tests fails without the change in pybind11.h
      
      * Moving new test to test_callbacks.cpp,py, with small enhancements.
      
      * Removing new test from test_interpreter.cpp (after it was moved to test_callbacks.cpp,py). This restores test_interpreter.cpp to the current state on master.
      
      * Using py::detail::silence_unused_warnings(py_func); to make the intent clear.
      Co-authored-by: default avatarRalf W. Grosse-Kunstleve <rwgk@google.com>
      d6474ed7
  2. 13 Aug, 2021 1 commit
    • Aaron Gokaslan's avatar
      maint(precommit): Apply isort (#3195) · 9df2f1ff
      Aaron Gokaslan authored
      * Apply isort
      
      * Tweak isort config
      
      * Add env.py as a known_first_party
      
      * Add one missing known first party
      
      * Make config compat with older isort versions
      
      * Add another comment
      
      * Revert pyproject setting
      9df2f1ff
  3. 27 Jul, 2021 1 commit
  4. 13 Jul, 2021 1 commit
  5. 13 Apr, 2021 1 commit
  6. 03 Apr, 2021 1 commit
  7. 16 Oct, 2020 1 commit
  8. 20 Jul, 2020 1 commit
  9. 11 Jun, 2019 1 commit
  10. 05 Aug, 2017 1 commit
    • Jason Rhinelander's avatar
      Update all remaining tests to new test styles · 391c7544
      Jason Rhinelander authored
      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.
      391c7544
  11. 29 Apr, 2017 1 commit
    • Jason Rhinelander's avatar
      functional: support bound methods · a01b6b80
      Jason Rhinelander authored
      If a bound std::function is invoked with a bound method, the implicit
      bound self is lost because we use `detail::get_function` to unbox the
      function.  This commit amends the code to use py::function and only
      unboxes in the special is-really-a-c-function case.  This makes bound
      methods stay bound rather than unbinding them by forcing extraction of
      the c function.
      a01b6b80
  12. 22 Feb, 2017 1 commit
    • Lunderberg's avatar
      Fixed compilation error when binding function accepting some forms of std::function (#689) · c7fcde7c
      Lunderberg authored
      * Fixed compilation error when defining function accepting some forms of std::function.
      
      The compilation error happens only when the functional.h header is
      present, and the build is done in debug mode, with NDEBUG being
      undefined.  In addition, the std::function must accept an abstract
      base class by reference.
      
      The compilation error occurred in cast.h, when trying to construct a
      std::tuple<AbstractBase>, rather than a std::tuple<AbstractBase&>.
      This was caused by functional.h using std::move rather than
      std::forward, changing the signature of the function being used.
      
      This commit contains the fix, along with a test that exhibits the
      issue when compiled in debug mode without the fix applied.
      
      * Moved new std::function tests into test_callbacks, added callback_with_movable test.
      c7fcde7c
  13. 19 Sep, 2016 1 commit
  14. 06 Sep, 2016 1 commit
    • Dean Moldovan's avatar
      Support keyword arguments and generalized unpacking in C++ · c743e1b1
      Dean Moldovan authored
      A Python function can be called with the syntax:
      ```python
      foo(a1, a2, *args, ka=1, kb=2, **kwargs)
      ```
      This commit adds support for the equivalent syntax in C++:
      ```c++
      foo(a1, a2, *args, "ka"_a=1, "kb"_a=2, **kwargs)
      ```
      
      In addition, generalized unpacking is implemented, as per PEP 448,
      which allows calls with multiple * and ** unpacking:
      ```python
      bar(*args1, 99, *args2, 101, **kwargs1, kz=200, **kwargs2)
      ```
      and
      ```c++
      bar(*args1, 99, *args2, 101, **kwargs1, "kz"_a=200, **kwargs2)
      ```
      c743e1b1
  15. 19 Aug, 2016 3 commits
    • Dean Moldovan's avatar
      382db5b2
    • Dean Moldovan's avatar
      Simplify tests by replacing output capture with asserts where possible · 665e8804
      Dean Moldovan authored
      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"`
      665e8804
    • Dean Moldovan's avatar
      Port tests to pytest · a0c1ccf0
      Dean Moldovan authored
      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.
      a0c1ccf0