示例#1
0
    def test_assert_exception_is_not_raised_raises_exception(self):
        """Tests that assert_exception_is_not_raised raises exception."""
        if tf.executing_eagerly():
            # In eager mode placeholders are assigned zeros by default, which fails
            # for various tests. Therefore this function can only be tested in graph
            # mode.
            return
        tc = test_case.TestCase(methodName="assert_exception_is_not_raised")

        with self.assertRaises(AssertionError):
            tc.assert_exception_is_not_raised(self._dummy_failing_function,
                                              shapes=((1, ), ))
示例#2
0
  def test_assert_tf_lite_convertible_exception_not_raised(self, test_inputs):
    """Tests that assert_tf_lite_convertible succeeds with a simple function."""
    tc = test_case.TestCase(methodName="assert_tf_lite_convertible")

    # We can't use self.assert_exception_is_not_raised here because we need to
    # use `shapes` as both a named argument and a kwarg.
    try:
      tc.assert_tf_lite_convertible(
          func=self._dummy_tf_lite_compatible_function,
          shapes=((1,),),
          test_inputs=test_inputs)
    except Exception as e:  # pylint: disable=broad-except
      self.fail("Exception raised: %s" % str(e))
示例#3
0
    def test_assert_tf_lite_convertible_exception_raised(self, test_inputs):
        """Tests that assert_tf_lite_convertible succeeds with a simple function."""
        # TODO(b/131912561): TFLite conversion throws SIGABRT instead of Exception.
        return
        # pylint: disable=unreachable
        # This code should be able to catch exceptions correctly once TFLite bug
        # is fixed.
        tc = test_case.TestCase(methodName="assert_tf_lite_convertible")

        with self.assertRaises(Exception):
            tc.assert_tf_lite_convertible(
                func=self._dummy_tf_lite_incompatible_function,
                shapes=((1, ), ),
                test_inputs=test_inputs)