Commit 5f2e3baf by Ralf W. Grosse-Kunstleve Committed by Copybara-Service

Add Add .code_int() to register_status_bindings.cc

PiperOrigin-RevId: 438396511
parent 0807a71b
...@@ -138,6 +138,9 @@ void RegisterStatusBindings(module m) { ...@@ -138,6 +138,9 @@ void RegisterStatusBindings(module m) {
.def(init<absl::StatusCode, std::string>()) .def(init<absl::StatusCode, std::string>())
.def("ok", &absl::Status::ok) .def("ok", &absl::Status::ok)
.def("code", &absl::Status::code) .def("code", &absl::Status::code)
.def("code_int", [](const absl::Status& self) {
return static_cast<int>(self.code());
})
.def("message", &absl::Status::message) .def("message", &absl::Status::message)
.def( .def(
"update", "update",
......
...@@ -65,15 +65,17 @@ class StatusTest(absltest.TestCase): ...@@ -65,15 +65,17 @@ class StatusTest(absltest.TestCase):
# The make_status function has been set up to return a status object # The make_status function has been set up to return a status object
# instead of raising an exception (this is done in status_example.cc). # instead of raising an exception (this is done in status_example.cc).
test_status = status_example.make_status(status.StatusCode.OK) test_status = status_example.make_status(status.StatusCode.OK)
self.assertEqual(test_status.code(), status.StatusCode.OK)
self.assertTrue(test_status.ok()) self.assertTrue(test_status.ok())
self.assertEqual(test_status.code(), status.StatusCode.OK)
self.assertEqual(test_status.code_int(), 0)
def test_make_not_ok(self): def test_make_not_ok(self):
# The make_status function should always return a status object, even if # The make_status function should always return a status object, even if
# it is not ok (ie, it should *not* convert it to an exception). # it is not ok (ie, it should *not* convert it to an exception).
test_status = status_example.make_status(status.StatusCode.CANCELLED) test_status = status_example.make_status(status.StatusCode.CANCELLED)
self.assertEqual(test_status.code(), status.StatusCode.CANCELLED)
self.assertFalse(test_status.ok()) self.assertFalse(test_status.ok())
self.assertEqual(test_status.code(), status.StatusCode.CANCELLED)
self.assertEqual(test_status.code_int(), 1)
def test_make_not_ok_manual_cast(self): def test_make_not_ok_manual_cast(self):
test_status = status_example.make_status_manual_cast( test_status = status_example.make_status_manual_cast(
......
Markdown is supported
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