mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-19 17:32:37 +00:00
Restore original test_async, test_buffers from current smart_holder HEAD
This commit is contained in:
parent
509506955b
commit
9a8489031d
@ -9,52 +9,6 @@
|
|||||||
|
|
||||||
#include "pybind11_tests.h"
|
#include "pybind11_tests.h"
|
||||||
|
|
||||||
#define USE_MRC_AAA
|
|
||||||
#ifdef USE_MRC_AAA
|
|
||||||
namespace mrc_ns { // minimal real caster
|
|
||||||
|
|
||||||
template <typename ValType>
|
|
||||||
struct type_mrc {
|
|
||||||
int value = -9999;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename CType>
|
|
||||||
struct minimal_real_caster {
|
|
||||||
static constexpr auto name = py::detail::const_name<CType>();
|
|
||||||
static constexpr std::uint64_t universally_unique_identifier = 1000000;
|
|
||||||
|
|
||||||
static py::handle
|
|
||||||
cast(CType const &src, py::return_value_policy /*policy*/, py::handle /*parent*/) {
|
|
||||||
return py::int_(src.value + 1010).release();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Maximizing simplicity. This will go terribly wrong for other arg types.
|
|
||||||
template <typename>
|
|
||||||
using cast_op_type = const CType &;
|
|
||||||
|
|
||||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
||||||
operator CType const &() {
|
|
||||||
static CType obj;
|
|
||||||
obj.value = 11;
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool load(py::handle src, bool /*convert*/) {
|
|
||||||
// Only accepts str, but the value is ignored.
|
|
||||||
return py::isinstance<py::str>(src);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mrc_ns
|
|
||||||
|
|
||||||
namespace pybind11 {
|
|
||||||
namespace detail {
|
|
||||||
template <typename ValType>
|
|
||||||
struct type_caster<mrc_ns::type_mrc<ValType>> : mrc_ns::minimal_real_caster<mrc_ns::type_mrc<ValType>> {};
|
|
||||||
} // namespace detail
|
|
||||||
} // namespace pybind11
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TEST_SUBMODULE(async_module, m) {
|
TEST_SUBMODULE(async_module, m) {
|
||||||
struct DoesNotSupportAsync {};
|
struct DoesNotSupportAsync {};
|
||||||
py::class_<DoesNotSupportAsync>(m, "DoesNotSupportAsync").def(py::init<>());
|
py::class_<DoesNotSupportAsync>(m, "DoesNotSupportAsync").def(py::init<>());
|
||||||
@ -68,8 +22,4 @@ TEST_SUBMODULE(async_module, m) {
|
|||||||
f.attr("set_result")(5);
|
f.attr("set_result")(5);
|
||||||
return f.attr("__await__")();
|
return f.attr("__await__")();
|
||||||
});
|
});
|
||||||
#ifdef USE_MRC_AAA
|
|
||||||
m.def("type_mrc_to_python", []() { return mrc_ns::type_mrc<int>{101}; });
|
|
||||||
m.def("type_mrc_from_python", [](const mrc_ns::type_mrc<int> &obj) { return obj.value + 100; });
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@ -22,17 +22,3 @@ def test_await(event_loop):
|
|||||||
def test_await_missing(event_loop):
|
def test_await_missing(event_loop):
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync()))
|
event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync()))
|
||||||
|
|
||||||
|
|
||||||
def test_type_mrc_to_python():
|
|
||||||
if hasattr(m, "type_mrc_to_python"):
|
|
||||||
assert m.type_mrc_to_python() == 1111
|
|
||||||
else:
|
|
||||||
pytype.skip("type_mrc_to_python")
|
|
||||||
|
|
||||||
|
|
||||||
def test_type_mrc_from_python():
|
|
||||||
if hasattr(m, "type_mrc_from_python"):
|
|
||||||
assert m.type_mrc_from_python("ignored") == 111
|
|
||||||
else:
|
|
||||||
pytype.skip("type_mrc_from_python")
|
|
||||||
|
@ -12,52 +12,6 @@
|
|||||||
#include "constructor_stats.h"
|
#include "constructor_stats.h"
|
||||||
#include "pybind11_tests.h"
|
#include "pybind11_tests.h"
|
||||||
|
|
||||||
#define USE_MRC_BBB
|
|
||||||
#ifdef USE_MRC_BBB
|
|
||||||
namespace mrc_ns { // minimal real caster
|
|
||||||
|
|
||||||
template <typename ValType>
|
|
||||||
struct type_mrc {
|
|
||||||
ValType value = -9999;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename CType>
|
|
||||||
struct minimal_real_caster {
|
|
||||||
static constexpr auto name = py::detail::const_name<CType>();
|
|
||||||
static constexpr std::uint64_t universally_unique_identifier = 2000000;
|
|
||||||
|
|
||||||
static py::handle
|
|
||||||
cast(CType const &src, py::return_value_policy /*policy*/, py::handle /*parent*/) {
|
|
||||||
return py::int_(src.value + 2020).release();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Maximizing simplicity. This will go terribly wrong for other arg types.
|
|
||||||
template <typename>
|
|
||||||
using cast_op_type = const CType &;
|
|
||||||
|
|
||||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
||||||
operator CType const &() {
|
|
||||||
static CType obj;
|
|
||||||
obj.value = 22;
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool load(py::handle src, bool /*convert*/) {
|
|
||||||
// Only accepts str, but the value is ignored.
|
|
||||||
return py::isinstance<py::str>(src);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mrc_ns
|
|
||||||
|
|
||||||
namespace pybind11 {
|
|
||||||
namespace detail {
|
|
||||||
template <typename ValType>
|
|
||||||
struct type_caster<mrc_ns::type_mrc<ValType>> : mrc_ns::minimal_real_caster<mrc_ns::type_mrc<ValType>> {};
|
|
||||||
} // namespace detail
|
|
||||||
} // namespace pybind11
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TEST_SUBMODULE(buffers, m) {
|
TEST_SUBMODULE(buffers, m) {
|
||||||
// test_from_python / test_to_python:
|
// test_from_python / test_to_python:
|
||||||
class Matrix {
|
class Matrix {
|
||||||
@ -267,9 +221,4 @@ TEST_SUBMODULE(buffers, m) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
m.def("get_buffer_info", [](const py::buffer &buffer) { return buffer.request(); });
|
m.def("get_buffer_info", [](const py::buffer &buffer) { return buffer.request(); });
|
||||||
|
|
||||||
#ifdef USE_MRC_BBB
|
|
||||||
m.def("type_mrc_to_python", []() { return mrc_ns::type_mrc<int>{202}; });
|
|
||||||
m.def("type_mrc_from_python", [](const mrc_ns::type_mrc<int> &obj) { return obj.value + 200; });
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@ -161,17 +161,3 @@ def test_ctypes_from_buffer():
|
|||||||
assert cinfo.shape == pyinfo.shape
|
assert cinfo.shape == pyinfo.shape
|
||||||
assert cinfo.strides == pyinfo.strides
|
assert cinfo.strides == pyinfo.strides
|
||||||
assert not cinfo.readonly
|
assert not cinfo.readonly
|
||||||
|
|
||||||
|
|
||||||
def test_type_mrc_to_python():
|
|
||||||
if hasattr(m, "type_mrc_to_python"):
|
|
||||||
assert m.type_mrc_to_python() == 2222
|
|
||||||
else:
|
|
||||||
pytype.skip("type_mrc_to_python")
|
|
||||||
|
|
||||||
|
|
||||||
def test_type_mrc_from_python():
|
|
||||||
if hasattr(m, "type_mrc_from_python"):
|
|
||||||
assert m.type_mrc_from_python("ignored") == 222
|
|
||||||
else:
|
|
||||||
pytype.skip("type_mrc_from_python")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user