1. 08 Oct, 2021 1 commit
  2. 01 Oct, 2021 1 commit
    • Bruce Merry's avatar
      feat: add `.keys` and `.values` to bind_map (#3310) · b3573ac9
      Bruce Merry authored
      
      
      * Add `.keys` and `.values` to bind_map
      
      Both of these implement views (rather than just iterators), and `.items`
      is also upgraded to a view. In practical terms, this allows a view to be
      iterated multiple times and have its size taken, neither of which works
      with an iterator.
      
      The views implement `__len__`, `__iter__`, and the keys view implements
      `__contains__`. Testing membership also works in item and value views
      because Python falls back to iteration. This won't be optimal
      for item values since it's linear rather than O(log n) or O(1), but I
      didn't fancy trying to get all the corner cases to match Python
      behaviour (tuple of wrong types, wrong length tuple, not a tuple etc).
      
      Missing relative to Python dictionary views is `__reversed__` (only
      added to Python in 3.8). Implementing that could break code that binds
      custom map classes which don't provide `rbegin`/`rend` (at least without
      doing clever things with SFINAE), so I've not tried.
      
      The size increase on my system is 131072 bytes, which is rather large
      (5%) but also suspiciously round (2^17) and makes me suspect some
      quantisation effect.
      
      * bind_map: support any object in __contains__
      
      Add extra overload of `__contains__` (for both the map itself and
      KeysView) which takes an arbitrary object and returns false.
      
      * Take py::object by const reference in __contains__
      
      To keep clang-tidy happy.
      
      * Removing stray `py::` (detected via interactive testing in Google environment).
      Co-authored-by: default avatarRalf W. Grosse-Kunstleve <rwgk@google.com>
      b3573ac9
  3. 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
  4. 16 Oct, 2020 1 commit
  5. 16 Aug, 2020 1 commit
    • Henry Schreiner's avatar
      tests: cleanup and ci hardening (#2397) · 4d9024ec
      Henry Schreiner authored
      * 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
      4d9024ec
  6. 14 Aug, 2020 1 commit
  7. 13 Aug, 2020 1 commit
    • marc-chiesa's avatar
      Modified Vector STL bind initialization from a buffer type with optimization... · 830adda8
      marc-chiesa authored
      Modified Vector STL bind initialization from a buffer type with optimization for simple arrays (#2298)
      
      * Modified Vector STL bind initialization from a buffer type with optimization for simple arrays
      
      * Add subtests to demonstrate processing Python buffer protocol objects with step > 1
      
      * Fixed memoryview step test to only run on Python 3+
      
      * Modified Vector constructor from buffer to return by value for readability
      830adda8
  8. 20 Jul, 2020 1 commit
  9. 31 May, 2020 1 commit
  10. 17 Jan, 2020 1 commit
  11. 31 Oct, 2019 1 commit
    • Sebastian Gsänger's avatar
      test pair-copyability on C++17 upwards (#1886) · a83d69e7
      Sebastian Gsänger authored
      * test pair-copyability on C++17 upwards
      
      The stdlib falsely detects containers like M=std::map<T, U>
      as copyable, even when one of T and U is not copyable.
      Therefore we cannot rely on the stdlib dismissing std::pair<T, M>
      by itself, even on C++17.
      
      * fix is_copy_assignable
      
      bind_map used std::is_copy_assignable which suffers from the same problems
      as std::is_copy_constructible, therefore the same fix has been applied.
      
      * created tests for copyability
      a83d69e7
  12. 15 Aug, 2019 1 commit
  13. 11 Jun, 2019 1 commit
  14. 11 Jan, 2018 1 commit
  15. 10 Sep, 2017 1 commit
  16. 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
  17. 25 May, 2017 1 commit
  18. 18 Apr, 2017 1 commit
    • Jason Rhinelander's avatar
      Keep skipping buffer tests on pypy · 90bac963
      Jason Rhinelander authored
      Adding numpy to the pypy test exposed a segfault caused by the buffer
      tests in test_stl_binders.py: the first such test was explicitly skipped
      on pypy, but the second (test_vector_buffer_numpy) which also seems to
      cause an occasional segfault was just marked as requiring numpy.
      
      Explicitly skip it on pypy as well (until a workaround, fix, or pypy fix
      are found).
      90bac963
  19. 14 Mar, 2017 2 commits
  20. 20 Nov, 2016 1 commit
  21. 15 Nov, 2016 1 commit
    • Jason Rhinelander's avatar
      Fix stl_bind to support movable, non-copyable value types (#490) · 617fbcfc
      Jason Rhinelander authored
      This commit includes the following changes:
      
      * Don't provide make_copy_constructor for non-copyable container
      
      make_copy_constructor currently fails for various stl containers (e.g.
      std::vector, std::unordered_map, std::deque, etc.) when the container's
      value type (e.g. the "T" or the std::pair<K,T> for a map) is
      non-copyable.  This adds an override that, for types that look like
      containers, also requires that the value_type be copyable.
      
      * stl_bind.h: make bind_{vector,map} work for non-copy-constructible types
      
      Most stl_bind modifiers require copying, so if the type isn't copy
      constructible, we provide a read-only interface instead.
      
      In practice, this means that if the type is non-copyable, it will be,
      for all intents and purposes, read-only from the Python side (but
      currently it simply fails to compile with such a container).
      
      It is still possible for the caller to provide an interface manually
      (by defining methods on the returned class_ object), but this isn't
      something stl_bind can handle because the C++ code to construct values
      is going to be highly dependent on the container value_type.
      
      * stl_bind: copy only for arithmetic value types
      
      For non-primitive types, we may well be copying some complex type, when
      returning by reference is more appropriate.  This commit returns by
      internal reference for all but basic arithmetic types.
      
      * Return by reference whenever possible
      
      Only if we definitely can't--i.e. std::vector<bool>--because v[i]
      returns something that isn't a T& do we copy; for everything else, we
      return by reference.
      
      For the map case, we can always return by reference (at least for the
      default stl map/unordered_map).
      617fbcfc
  22. 05 Sep, 2016 1 commit
  23. 19 Aug, 2016 1 commit
    • 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