From c14170a7878e7ac2f88e11657d629026d1ca31f3 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 15 Feb 2022 11:51:17 -0800 Subject: [PATCH] Removing `// clang-format off` - `on` directives from test_pickling.cpp (#3738) --- tests/test_pickling.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/test_pickling.cpp b/tests/test_pickling.cpp index bf1ee4671..9787bd300 100644 --- a/tests/test_pickling.cpp +++ b/tests/test_pickling.cpp @@ -1,4 +1,3 @@ -// clang-format off /* tests/test_pickling.cpp -- pickle support @@ -11,8 +10,6 @@ #include "pybind11_tests.h" -// clang-format on - #include #include #include @@ -63,19 +60,18 @@ void wrap(py::module m) { } // namespace exercise_trampoline -// clang-format off - TEST_SUBMODULE(pickling, m) { // test_roundtrip class Pickleable { public: - explicit Pickleable(const std::string &value) : m_value(value) { } + explicit Pickleable(const std::string &value) : m_value(value) {} const std::string &value() const { return m_value; } void setExtra1(int extra1) { m_extra1 = extra1; } void setExtra2(int extra2) { m_extra2 = extra2; } int extra1() const { return m_extra1; } int extra2() const { return m_extra2; } + private: std::string m_value; int m_extra1 = 0; @@ -88,8 +84,7 @@ TEST_SUBMODULE(pickling, m) { }; py::class_ pyPickleable(m, "Pickleable"); - pyPickleable - .def(py::init()) + pyPickleable.def(py::init()) .def("value", &Pickleable::value) .def("extra1", &Pickleable::extra1) .def("extra2", &Pickleable::extra2) @@ -105,7 +100,7 @@ TEST_SUBMODULE(pickling, m) { pyPickleable.def("__setstate__", [](Pickleable &p, const py::tuple &t) { if (t.size() != 3) { throw std::runtime_error("Invalid state!"); -} + } /* Invoke the constructor (need to use in-place version) */ new (&p) Pickleable(t[0].cast()); @@ -124,7 +119,7 @@ TEST_SUBMODULE(pickling, m) { [](const py::tuple &t) { if (t.size() != 3) { throw std::runtime_error("Invalid state!"); -} + } auto p = PickleableNew(t[0].cast()); p.setExtra1(t[1].cast()); @@ -136,7 +131,7 @@ TEST_SUBMODULE(pickling, m) { // test_roundtrip_with_dict class PickleableWithDict { public: - explicit PickleableWithDict(const std::string &value) : value(value) { } + explicit PickleableWithDict(const std::string &value) : value(value) {} std::string value; int extra; @@ -147,7 +142,8 @@ TEST_SUBMODULE(pickling, m) { using PickleableWithDict::PickleableWithDict; }; - py::class_ pyPickleableWithDict(m, "PickleableWithDict", py::dynamic_attr()); + py::class_ pyPickleableWithDict( + m, "PickleableWithDict", py::dynamic_attr()); pyPickleableWithDict.def(py::init()) .def_readwrite("value", &PickleableWithDict::value) .def_readwrite("extra", &PickleableWithDict::extra) @@ -159,7 +155,7 @@ TEST_SUBMODULE(pickling, m) { pyPickleableWithDict.def("__setstate__", [](const py::object &self, const py::tuple &t) { if (t.size() != 3) { throw std::runtime_error("Invalid state!"); -} + } /* Cast and construct */ auto &p = self.cast(); new (&p) PickleableWithDict(t[0].cast()); @@ -176,12 +172,13 @@ TEST_SUBMODULE(pickling, m) { .def(py::init()) .def(py::pickle( [](const py::object &self) { - return py::make_tuple(self.attr("value"), self.attr("extra"), self.attr("__dict__")); + return py::make_tuple( + self.attr("value"), self.attr("extra"), self.attr("__dict__")); }, [](const py::tuple &t) { if (t.size() != 3) { throw std::runtime_error("Invalid state!"); -} + } auto cpp_state = PickleableWithDictNew(t[0].cast()); cpp_state.extra = t[1].cast();