From abd3429ce9ae884974c11d2dc79a190f0ca8f742 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Tue, 1 Nov 2016 13:29:32 +0000 Subject: [PATCH] Add a test for numpy dtypes with custom names --- tests/test_numpy_dtypes.cpp | 10 +++++++++- tests/test_numpy_dtypes.py | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_numpy_dtypes.cpp b/tests/test_numpy_dtypes.cpp index 40aca0c3c..8f680c071 100644 --- a/tests/test_numpy_dtypes.cpp +++ b/tests/test_numpy_dtypes.cpp @@ -67,6 +67,11 @@ struct StringStruct { std::array b; }; +PYBIND11_PACKED(struct StructWithUglyNames { + int8_t __x__; + uint64_t __y__; +}); + enum class E1 : int64_t { A = -1, B = 1 }; enum E2 : uint8_t { X = 1, Y = 2 }; @@ -197,7 +202,8 @@ py::list print_dtypes() { py::dtype::of().str(), py::dtype::of().str(), py::dtype::of().str(), - py::dtype::of().str() + py::dtype::of().str(), + py::dtype::of().str() }; auto l = py::list(); for (const auto &s : dtypes) { @@ -312,6 +318,8 @@ test_initializer numpy_dtypes([](py::module &m) { // ... or after py::class_(m, "PackedStruct"); + PYBIND11_NUMPY_DTYPE_EX(StructWithUglyNames, __x__, "x", __y__, "y"); + m.def("create_rec_simple", &create_recarray); m.def("create_rec_packed", &create_recarray); m.def("create_rec_nested", &create_nested); diff --git a/tests/test_numpy_dtypes.py b/tests/test_numpy_dtypes.py index 47d7c3bd7..b4e6d71f2 100644 --- a/tests/test_numpy_dtypes.py +++ b/tests/test_numpy_dtypes.py @@ -42,7 +42,8 @@ def test_dtype(): "{'names':['x','y','z'], 'formats':['?','