From 6285177afe80a65a3ef10762b4290cd53ad38ddc Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sat, 27 Feb 2021 08:59:43 -0800 Subject: [PATCH] Undoing accidental commit (this was meant to go to a new branch). Revert "WIP: test setup complete, AddInCppUniquePtr failing (reproduces PyCLIF smart_ptrs_test failure)." This reverts commit 20107030abc4cbd45d1afc1037a74df61d8bcab4. --- tests/test_class_sh_with_alias.cpp | 61 ------------------------------ tests/test_class_sh_with_alias.py | 31 --------------- 2 files changed, 92 deletions(-) delete mode 100644 tests/test_class_sh_with_alias.cpp delete mode 100644 tests/test_class_sh_with_alias.py diff --git a/tests/test_class_sh_with_alias.cpp b/tests/test_class_sh_with_alias.cpp deleted file mode 100644 index e62f8e763..000000000 --- a/tests/test_class_sh_with_alias.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "pybind11_tests.h" - -#include - -#include - -namespace pybind11_tests { -namespace test_class_sh_with_alias { - -struct Abase { - int val = 0; - virtual ~Abase() = default; - Abase(int val_) : val{val_} {} - int Get() const { return val * 10 + 3; } - virtual int Add(int other_val) const = 0; - - // Some compilers complain about implicitly defined versions of some of the following: - Abase(const Abase &) = default; - Abase(Abase &&) = default; - Abase &operator=(const Abase &) = default; - Abase &operator=(Abase &&) = default; -}; - -struct AbaseAlias : Abase { - using Abase::Abase; - - int Add(int other_val) const override { - PYBIND11_OVERRIDE_PURE(int, /* Return type */ - Abase, /* Parent class */ - Add, /* Name of function in C++ (must match Python name) */ - other_val); - } -}; - -int AddInCppRawPtr(const Abase *obj, int other_val) { return obj->Add(other_val) * 10 + 7; } - -int AddInCppSharedPtr(std::shared_ptr obj, int other_val) { - return obj->Add(other_val) * 100 + 11; -} - -int AddInCppUniquePtr(std::unique_ptr obj, int other_val) { - return obj->Add(other_val) * 100 + 13; -} - -} // namespace test_class_sh_with_alias -} // namespace pybind11_tests - -PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::test_class_sh_with_alias::Abase) - -TEST_SUBMODULE(class_sh_with_alias, m) { - using namespace pybind11_tests::test_class_sh_with_alias; - - py::classh(m, "Abase") - .def(py::init(), py::arg("val")) - .def("Get", &Abase::Get) - .def("Add", &Abase::Add, py::arg("other_val")); - - m.def("AddInCppRawPtr", AddInCppRawPtr, py::arg("obj"), py::arg("other_val")); - m.def("AddInCppSharedPtr", AddInCppSharedPtr, py::arg("obj"), py::arg("other_val")); - m.def("AddInCppUniquePtr", AddInCppUniquePtr, py::arg("obj"), py::arg("other_val")); -} diff --git a/tests/test_class_sh_with_alias.py b/tests/test_class_sh_with_alias.py deleted file mode 100644 index a8b10b849..000000000 --- a/tests/test_class_sh_with_alias.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- - -from pybind11_tests import class_sh_with_alias as m - - -class PyDrvd(m.Abase): - def __init__(self, val): - super(PyDrvd, self).__init__(val) - - def Add(self, other_val): - return self.Get() * 100 + other_val - - -def test_drvd_add(): - drvd = PyDrvd(74) - assert drvd.Add(38) == (74 * 10 + 3) * 100 + 38 - - -def test_add_in_cpp_raw_ptr(): - drvd = PyDrvd(52) - assert m.AddInCppRawPtr(drvd, 27) == ((52 * 10 + 3) * 100 + 27) * 10 + 7 - - -def test_add_in_cpp_shared_ptr(): - drvd = PyDrvd(36) - assert m.AddInCppSharedPtr(drvd, 56) == ((36 * 10 + 3) * 100 + 56) * 100 + 11 - - -def test_add_in_cpp_unique_ptr(): - drvd = PyDrvd(38) - assert m.AddInCppUniquePtr(drvd, 29) == ((38 * 10 + 3) * 100 + 29) * 100 + 13