Commit 78f96967 authored by Baptiste Esteban's avatar Baptiste Esteban
Browse files

Check the input type correctly

parent 339d6e2f
Pipeline #30957 passed with stage
in 24 minutes and 42 seconds
......@@ -5,6 +5,8 @@
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <fmt/format.h>
namespace pln
/// \brief Convert a NumPy array to a ndbuffer_image
......@@ -33,6 +35,8 @@ namespace pybind11::detail
bool load(handle h, bool)
if (!pybind11::array::check_(h))
throw std::invalid_argument(fmt::format("Input value is not a valid array (Got `{}`)", static_cast<std::string>(pybind11::str(pybind11::type::handle_of(h)))));
pybind11::array arr = reinterpret_borrow<pybind11::array>(h);
value = pln::from_numpy(arr);
return true;
......@@ -131,6 +131,11 @@ class TestNumpyImage(unittest.TestCase):
with self.assertRaises(ValueError, msg="Invalid number of dimension from numpy array (Got 5 but should be < 5)"):
def test_invalid_input(self):
a = 10
with self.assertRaises(ValueError, msg="Input value is not a valid array (Got `<class 'int'>`)"):
if __name__ == "__main__":
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment