Example #1
0
 def test_return_not_ok(self):
     # The return_status function should convert a non-ok status to an exception.
     with self.assertRaises(status.StatusNotOk) as cm:
         status_example.return_status(status.StatusCode.CANCELLED, 'test')
     self.assertEqual(cm.exception.status.code(),
                      status.StatusCode.CANCELLED)
     self.assertEqual(cm.exception.status.message(), 'test')
Example #2
0
 def test_return_not_ok_catch_with_alias(self):
     # Catch as status_example.StatusNotOk, an alias of status.StatusNotOk.
     with self.assertRaises(status_example.StatusNotOk) as cm:
         status_example.return_status(status.StatusCode.CANCELLED, 'test')
     self.assertEqual(cm.exception.status.code(),
                      status.StatusCode.CANCELLED)
     self.assertEqual(cm.exception.status.message(), 'test')
Example #3
0
 def test_return_not_ok_catch_as_generic_exception(self):
     # Catch as a generic Exception, the base type of StatusNotOk.
     with self.assertRaises(Exception):
         status_example.return_status(status.StatusCode.CANCELLED, 'test')
Example #4
0
 def test_return_ok(self):
     # The return_status function should convert an ok status to None.
     self.assertIsNone(status_example.return_status(status.StatusCode.OK))