def test_assert_python_untriggered(self): side_effect_trace = [] def expression_with_side_effects(): side_effect_trace.append(object()) return 'test message' exceptions.assert_stmt(True, expression_with_side_effects) self.assertListEqual(side_effect_trace, [])
def test_assert_python_untriggered(self): side_effect_trace = [] def expression_with_side_effects(): side_effect_trace.append(object()) return 'test message' exceptions.assert_stmt(True, expression_with_side_effects) self.assertListEqual(side_effect_trace, [])
def test_assert_python_triggered(self): if not __debug__: # Python assertions only be tested when in debug mode. return side_effect_trace = [] tracer = object() def expression_with_side_effects(): side_effect_trace.append(tracer) return 'test message' with self.assertRaisesRegex(AssertionError, 'test message'): exceptions.assert_stmt(False, expression_with_side_effects) self.assertListEqual(side_effect_trace, [tracer])
def test_assert_python_triggered(self): if not __debug__: # Python assertions only be tested when in debug mode. return side_effect_trace = [] tracer = object() def expression_with_side_effects(): side_effect_trace.append(tracer) return 'test message' with self.assertRaisesRegexp(AssertionError, 'test message'): exceptions.assert_stmt(False, expression_with_side_effects) self.assertListEqual(side_effect_trace, [tracer])
def test_assert_tf_triggered(self): with self.cached_session() as sess: t = exceptions.assert_stmt( constant_op.constant(False), lambda: constant_op.constant('test message')) with self.assertRaisesRegex(errors_impl.InvalidArgumentError, 'test message'): self.evaluate(t)
def test_assert_tf_triggered(self): with self.cached_session() as sess: t = exceptions.assert_stmt( constant_op.constant(False), lambda: constant_op.constant('test message')) with self.assertRaisesRegexp(errors_impl.InvalidArgumentError, 'test message'): self.evaluate(t)
def test_assert_tf_multiple_printed_values(self): two_tensors = [ constant_op.constant('test message'), constant_op.constant('another message') ] with self.cached_session() as sess: t = exceptions.assert_stmt(constant_op.constant(False), lambda: two_tensors) with self.assertRaisesRegex(errors_impl.InvalidArgumentError, 'test message.*another message'): self.evaluate(t)
def test_assert_tf_multiple_printed_values(self): two_tensors = [ constant_op.constant('test message'), constant_op.constant('another message') ] with self.cached_session() as sess: t = exceptions.assert_stmt( constant_op.constant(False), lambda: two_tensors) with self.assertRaisesRegexp(errors_impl.InvalidArgumentError, 'test message.*another message'): self.evaluate(t)
def test_assert_tf_untriggered(self): with self.cached_session() as sess: t = exceptions.assert_stmt(constant_op.constant(True), lambda: constant_op.constant('ignored')) self.evaluate(t)
def test_assert_tf_untriggered(self): with self.cached_session() as sess: t = exceptions.assert_stmt( constant_op.constant(True), lambda: constant_op.constant('ignored')) self.evaluate(t)