Skip to content

Commit

Permalink
Add test for issue nv-morpheus#450
Browse files Browse the repository at this point in the history
  • Loading branch information
dagardner-nv committed Mar 11, 2024
1 parent 2dbd985 commit ad3d627
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions python/mrc/_pymrc/tests/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <climits>
#include <map>
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -143,6 +144,25 @@ TEST_F(TestUtils, CastFromPyObject)
}
}

TEST_F(TestUtils, CastFromPyObjectSerializeErrors)
{
// Test to verify that cast_from_pyobject throws a python TypeError when encountering something that is not json
// serializable issue #450
{
// Exceptions are not serializable. Keep in mind we aren't throwins a `std::runtime_error`, we are just trying
// to serialize it
py::object o = py::cast(std::runtime_error("test error"));
EXPECT_THROW(pymrc::cast_from_pyobject(o), py::type_error);
}

{
// decimal.Decimal is not serializable
py::object Decimal = py::module_::import("decimal").attr("Decimal");
py::object o = Decimal("1.0");
EXPECT_THROW(pymrc::cast_from_pyobject(o), py::type_error);
}
}

TEST_F(TestUtils, PyObjectWrapper)
{
py::list test_list;
Expand Down

0 comments on commit ad3d627

Please sign in to comment.