def test_info_injection_no_args(self): def error_fn(): raise ValueError('Original message') with self.assertRaises(ValueError) as e: traceback_utils.inject_argument_info_in_traceback(error_fn)() self.assertEqual(str(e.exception).count('Call arguments received'), 0)
def test_info_injection_unbindable(self): def error_fn(arg_1, keyword_arg_1=1): return arg_1 + keyword_arg_1 with self.assertRaises(TypeError) as e: traceback_utils.inject_argument_info_in_traceback(error_fn)() self.assertIn('missing 1 required positional argument', str(e.exception))
def test_info_injection_tf_op_error(self): def error_fn(arg_1, keyword_arg_1=1): return arg_1 + keyword_arg_1 + tf.zeros((2, 3)) with self.assertRaises(tf.errors.InvalidArgumentError) as e: traceback_utils.inject_argument_info_in_traceback(error_fn)( tf.zeros((3, 3))) self.assertIn('Incompatible shapes', str(e.exception)) self.assertIn('Call arguments received', str(e.exception))
def test_info_injection_nested(self): def inner_fn(arg_1): raise ValueError('Original message') def outer_fn(arg_1): return inner_fn(arg_1) with self.assertRaises(ValueError) as e: traceback_utils.inject_argument_info_in_traceback(outer_fn)(1) self.assertEqual(str(e.exception).count('Call arguments received'), 1)
def test_info_injection_basics(self): def error_fn(arg_1, arg_2, keyword_arg_1=None, keyword_arg_2=None): raise ValueError('Original message') with self.assertRaises(ValueError) as e: traceback_utils.inject_argument_info_in_traceback( error_fn, 'ObjName')(1, 2, keyword_arg_1=3, keyword_arg_2=4) self.assertIn('Original message', str(e.exception)) self.assertIn('Exception encountered when calling ObjName', str(e.exception)) self.assertIn('Call arguments received', str(e.exception)) self.assertIn('arg_1=1', str(e.exception)) self.assertIn('arg_2=2', str(e.exception)) self.assertIn('keyword_arg_1=3', str(e.exception)) self.assertIn('keyword_arg_2=4', str(e.exception)) with self.assertRaises(ValueError) as e: traceback_utils.inject_argument_info_in_traceback(error_fn)( 1, 2, keyword_arg_1=3, keyword_arg_2=4) self.assertIn('Exception encountered when calling error_fn', str(e.exception))
def test_info_injection_basics(self): def error_fn(arg_1, arg_2, keyword_arg_1=None, keyword_arg_2=None): raise ValueError("Original message") with self.assertRaises(ValueError) as e: traceback_utils.inject_argument_info_in_traceback( error_fn, "ObjName")(1, 2, keyword_arg_1=3, keyword_arg_2=4) self.assertIn("Original message", str(e.exception)) self.assertIn("Exception encountered when calling ObjName", str(e.exception)) self.assertIn("Call arguments received", str(e.exception)) self.assertIn("arg_1=1", str(e.exception)) self.assertIn("arg_2=2", str(e.exception)) self.assertIn("keyword_arg_1=3", str(e.exception)) self.assertIn("keyword_arg_2=4", str(e.exception)) with self.assertRaises(ValueError) as e: traceback_utils.inject_argument_info_in_traceback(error_fn)( 1, 2, keyword_arg_1=3, keyword_arg_2=4) self.assertIn("Exception encountered when calling error_fn", str(e.exception))