pybind11_tests.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <pybind11/eval.h>
4 #include <pybind11/pybind11.h>
5 
6 namespace py = pybind11;
7 using namespace pybind11::literals;
8 
10  using Initializer = void (*)(py::module_ &);
11 
12 public:
14  test_initializer(const char *submodule_name, Initializer init);
15 };
16 
17 #define TEST_SUBMODULE(name, variable) \
18  void test_submodule_##name(py::module_ &); \
19  test_initializer name(#name, test_submodule_##name); \
20  void test_submodule_##name(py::module_ &(variable))
21 
23 struct UnregisteredType {};
24 
26 class UserType {
27 public:
28  UserType() = default;
29  explicit UserType(int i) : i(i) {}
30 
31  int value() const { return i; }
32  void set(int set) { i = set; }
33 
34 private:
35  int i = -1;
36 };
37 
39 class IncType : public UserType {
40 public:
41  using UserType::UserType;
42  IncType() = default;
43  IncType(const IncType &other) : IncType(other.value() + 1) {}
44  IncType(IncType &&) = delete;
45  IncType &operator=(const IncType &) = delete;
46  IncType &operator=(IncType &&) = delete;
47 };
48 
50 union IntFloat {
51  int i;
52  float f;
53 };
54 
57 struct RValueCaster {};
60 template <>
62 public:
65  return py::str("rvalue").release();
66  }
68  return py::str("lvalue").release();
69  }
70 };
73 
74 template <typename F>
76  py::exec(R"(
77  message = "pybind11-bound class '.+' is using an old-style placement-new '(?:__init__|__setstate__)' which has been deprecated"
78 
79  import warnings
80  with warnings.catch_warnings():
81  warnings.filterwarnings("ignore", message=message, category=FutureWarning)
82  body()
83  )",
84  py::dict(py::arg("body") = py::cpp_function(body)));
85 }
Key F(std::uint64_t j)
UserType()=default
void ignoreOldStyleInitWarnings(F &&body)
IncType()=default
IncType(const IncType &other)
Dummy type which is not exported anywhere – something to trigger a conversion error.
void exec(const str &expr, object global=globals(), object local=object())
Definition: eval.h:88
void(*)(py::module_ &) Initializer
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
static handle cast(RValueCaster &&, return_value_policy, handle)
int value() const
UserType(int i)
constexpr descr< N - 1 > const_name(char const (&text)[N])
Definition: descr.h:60
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
static handle cast(const RValueCaster &, return_value_policy, handle)
#define PYBIND11_TYPE_CASTER(type, py_name)
Definition: cast.h:82
#define PYBIND11_NAMESPACE_END(name)
A simple union for basic testing.
#define PYBIND11_NAMESPACE_BEGIN(name)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:26