assertNotIn(a, b):断言 a不在 b中。 assertRaises(Exception, callable, *args, **kwargs):断言 callable调用时抛出指定的异常。 使用不同的断言方法classTestMathFunctions(unittest.TestCase): deftest_assert_methods(self): self.assertEqual(add(1,2),3) self.assertNotEqual(add(2,2),5) self.asser...
self_adjoint_eig(scalar) vector = tf.constant([1., 2.]) with self.assertRaises(ValueError): tf.self_adjoint_eig(vector) Example #8Source File: fisher_factors.py From kfac with Apache License 2.0 5 votes def get_eigendecomp(self): """Creates or retrieves eigendecomposition of self._...
returnrepr self value try raise MyError exceptMyError printMy exception occurred value valueMy exception occurred value raiseMyError oops Traceback most recent call last File stdin line mainMyError oops 在这个例子中 Exception默认的 init 被覆盖。当创建一个模块有可能抛出多种不同的异常时 一种通常的...