Skip to content

Commit 78d6f10

Browse files
committed
Cleaning up test_classh_mock.cpp.
1 parent e6453dc commit 78d6f10

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

tests/test_classh_mock.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,42 @@ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
3030
// BOILERPLATE END
3131

3232
namespace {
33-
struct Foo0 {};
34-
struct Foo1 {};
35-
struct Foo2 {};
36-
struct Foo3 {};
37-
struct Foo4 {};
33+
struct FooUc {};
34+
struct FooUp {};
35+
struct FooSa {};
36+
struct FooSc {};
37+
struct FooSp {};
3838
} // namespace
3939

40-
PYBIND11_TYPE_CASTER_BASE_HOLDER(Foo1, std::shared_ptr<Foo1>)
41-
PYBIND11_SMART_HOLDER_TYPE_CASTERS(Foo2)
42-
PYBIND11_SMART_HOLDER_TYPE_CASTERS(Foo4)
40+
PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooUp)
41+
PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooSp)
42+
43+
PYBIND11_TYPE_CASTER_BASE_HOLDER(FooSa, std::shared_ptr<FooSa>)
4344

4445
TEST_SUBMODULE(classh_mock, m) {
4546
// Please see README_smart_holder.rst, in particular section
4647
// Classic / Conservative / Progressive cross-module compatibility
4748

48-
// Uses std::unique_ptr<Foo0> as holder in Conservative mode, py::smart_holder in Progressive
49-
// mode (if available).
50-
py::class_<Foo0>(m, "Foo0").def(py::init<>());
51-
52-
// Always uses std::shared_ptr<Foo1> as holder.
53-
py::class_<Foo1, std::shared_ptr<Foo1>>(m, "Foo1").def(py::init<>());
49+
// Uses std::unique_ptr<FooUc> as holder in Classic or Conservative mode, py::smart_holder in
50+
// Progressive mode.
51+
py::class_<FooUc>(m, "FooUc").def(py::init<>());
5452

55-
// Uses std::shared_ptr<Foo2> as holder in Classic mode, py::smart_holder in Conservative or
53+
// Uses std::unique_ptr<FooUp> as holder in Classic mode, py::smart_holder in Conservative or
5654
// Progressive mode.
57-
py::class_<Foo2, PYBIND11_SH_AVL(Foo2)>(m, "Foo2").def(py::init<>());
58-
// ------------- std::shared_ptr<Foo2> -- same length by design, to not disturb the indentation
59-
// of existing code.
55+
py::classh<FooUp>(m, "FooUp").def(py::init<>());
6056

61-
// Uses std::shared_ptr<Foo3> as holder in Classic or Conservative mode, py::smart_holder in
57+
// Always uses std::shared_ptr<FooSa> as holder.
58+
py::class_<FooSa, std::shared_ptr<FooSa>>(m, "FooSa").def(py::init<>());
59+
60+
// Uses std::shared_ptr<FooSc> as holder in Classic or Conservative mode, py::smart_holder in
6261
// Progressive mode.
63-
py::class_<Foo3, PYBIND11_SH_DEF(Foo3)>(m, "Foo3").def(py::init<>());
64-
// ------------- std::shared_ptr<Foo3> -- same length by design, to not disturb the indentation
65-
// of existing code.
62+
py::class_<FooSc, PYBIND11_SH_DEF(FooSc)>(m, "FooSc").def(py::init<>());
63+
// -------------- std::shared_ptr<FooSc> -- same length by design, to not disturb the
64+
// indentation of existing code.
6665

67-
// Uses py::smart_holder if available, or std::unique_ptr<Foo3> if only pybind11 Classic is
68-
// available.
69-
py::classh<Foo4>(m, "Foo4").def(py::init<>());
66+
// Uses std::shared_ptr<FooSp> as holder in Classic mode, py::smart_holder in Conservative or
67+
// Progressive mode.
68+
py::class_<FooSp, PYBIND11_SH_AVL(FooSp)>(m, "FooSp").def(py::init<>());
69+
// -------------- std::shared_ptr<FooSp> -- same length by design, to not disturb the
70+
// indentation of existing code.
7071
}

tests/test_classh_mock.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
def test_foobar():
77
# Not really testing anything in particular. The main purpose of this test is to ensure the
88
# suggested BOILERPLATE code block in test_classh_mock.cpp is correct.
9-
assert m.Foo0()
10-
assert m.Foo1()
11-
assert m.Foo2()
12-
assert m.Foo3()
13-
assert m.Foo4()
9+
assert m.FooUc()
10+
assert m.FooUp()
11+
assert m.FooSa()
12+
assert m.FooSc()
13+
assert m.FooSp()

0 commit comments

Comments
 (0)