From d0bafd90e0a8472e8b4de0ba17de636d34b195a0 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Sun, 26 Jun 2016 16:35:28 +0100 Subject: [PATCH] Add a test for buffer format of unbound struct --- example/example20.cpp | 7 +++++++ example/example20.py | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/example/example20.cpp b/example/example20.cpp index 77cda6b5c..662dc473a 100644 --- a/example/example20.cpp +++ b/example/example20.cpp @@ -44,6 +44,8 @@ std::ostream& operator<<(std::ostream& os, const NestedStruct& v) { return os << "n:a=" << v.a << ";b=" << v.b; } +struct UnboundStruct { }; + template py::array mkarray_via_buffer(size_t n) { return py::array(py::buffer_info(nullptr, sizeof(T), @@ -61,6 +63,10 @@ py::array_t create_recarray(size_t n) { return arr; } +std::string get_format_unbound() { + return py::format_descriptor::format(); +} + py::array_t create_nested(size_t n) { auto arr = mkarray_via_buffer(n); auto ptr = static_cast(arr.request().ptr); @@ -107,4 +113,5 @@ void init_ex20(py::module &m) { m.def("print_rec_packed", &print_recarray); m.def("print_rec_nested", &print_recarray); m.def("print_dtypes", &print_dtypes); + m.def("get_format_unbound", &get_format_unbound); } diff --git a/example/example20.py b/example/example20.py index c581cf3f7..e0a001804 100644 --- a/example/example20.py +++ b/example/example20.py @@ -1,16 +1,20 @@ #!/usr/bin/env python from __future__ import print_function +import unittest import numpy as np from example import ( create_rec_simple, create_rec_packed, create_rec_nested, print_format_descriptors, - print_rec_simple, print_rec_packed, print_rec_nested, print_dtypes + print_rec_simple, print_rec_packed, print_rec_nested, print_dtypes, get_format_unbound ) def check_eq(arr, data, dtype): np.testing.assert_equal(arr, np.array(data, dtype=dtype)) +unittest.TestCase().assertRaisesRegex( + RuntimeError, 'unsupported buffer format', get_format_unbound) + print_format_descriptors() print_dtypes()