"vscode:/vscode.git/clone" did not exist on "2e1565e414bbc34e72a67bfdbf44c2706546d355"
Commit 2ea4b8e8 authored by Wenzel Jakob's avatar Wenzel Jakob Committed by GitHub
Browse files

Merge pull request #381 from jagerman/tests-self-registering

Make test initialization self-registering
parents 06d8de11 52f4be89
......@@ -24,7 +24,7 @@ private:
int m_extra2 = 0;
};
void init_ex_pickling(py::module &m) {
test_initializer pickling([](py::module &m) {
py::class_<Pickleable>(m, "Pickleable")
.def(py::init<std::string>())
.def("value", &Pickleable::value)
......@@ -48,4 +48,4 @@ void init_ex_pickling(py::module &m) {
p.setExtra1(t[1].cast<int>());
p.setExtra2(t[2].cast<int>());
});
}
});
......@@ -167,7 +167,7 @@ public:
int ExamplePythonTypes::value = 0;
const int ExamplePythonTypes::value2 = 5;
void init_ex_python_types(py::module &m) {
test_initializer python_types([](py::module &m) {
/* No constructor is explicitly defined below. An exception is raised when
trying to construct it directly from Python */
py::class_<ExamplePythonTypes>(m, "ExamplePythonTypes", "Example 2 documentation")
......@@ -197,4 +197,4 @@ void init_ex_python_types(py::module &m) {
.def_readwrite_static("value", &ExamplePythonTypes::value, "Static value member")
.def_readonly_static("value2", &ExamplePythonTypes::value2, "Static value member (readonly)")
;
}
});
......@@ -168,7 +168,7 @@ bool operator==(const NonZeroIterator<std::pair<A, B>>& it, const NonZeroSentine
return !(*it).first || !(*it).second;
}
void init_ex_sequences_and_iterators(py::module &m) {
test_initializer sequences_and_iterators([](py::module &m) {
py::class_<Sequence> seq(m, "Sequence");
......@@ -271,4 +271,4 @@ void init_ex_sequences_and_iterators(py::module &m) {
On the actual Sequence object, the iterator would be constructed as follows:
.def("__iter__", [](py::object s) { return PySequenceIterator(s.cast<const Sequence &>(), s); })
#endif
}
});
......@@ -105,7 +105,7 @@ void print_myobject3_2(std::shared_ptr<MyObject3> obj) { std::cout << obj->toStr
void print_myobject3_3(const std::shared_ptr<MyObject3> &obj) { std::cout << obj->toString() << std::endl; }
void print_myobject3_4(const std::shared_ptr<MyObject3> *obj) { std::cout << (*obj)->toString() << std::endl; }
void init_ex_smart_ptr(py::module &m) {
test_initializer smart_ptr([](py::module &m) {
py::class_<Object, ref<Object>> obj(m, "Object");
obj.def("getRefCount", &Object::getRefCount);
......@@ -147,4 +147,4 @@ void init_ex_smart_ptr(py::module &m) {
// Expose constructor stats for the ref type
m.def("cstats_ref", &ConstructorStats::get<ref_tag>);
}
});
......@@ -24,7 +24,7 @@ std::ostream & operator<<(std::ostream &s, El const&v) {
return s;
}
void init_ex_stl_binder_vector(py::module &m) {
test_initializer stl_binder_vector([](py::module &m) {
py::class_<El>(m, "El")
.def(py::init<int>());
......@@ -34,4 +34,4 @@ void init_ex_stl_binder_vector(py::module &m) {
py::bind_vector<El>(m, "VectorEl");
py::bind_vector<std::vector<El>>(m, "VectorVectorEl");
}
});
......@@ -283,7 +283,7 @@ void initialize_inherited_virtuals(py::module &m) {
};
void init_ex_virtual_functions(py::module &m) {
test_initializer virtual_functions([](py::module &m) {
/* Important: indicate the trampoline class PyExampleVirt using the third
argument to py::class_. The second argument with the unique pointer
is simply the default holder type used by pybind11. */
......@@ -315,4 +315,4 @@ void init_ex_virtual_functions(py::module &m) {
m.def("cstats_debug", &ConstructorStats::get<ExampleVirt>);
initialize_inherited_virtuals(m);
}
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment