我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用exceptions.AssertionError()。
def test_assertRegex(): class TestAssertRegex(unittest.TestCase): def test(self): with self.assertRaises(AssertionError): six.assertRegex(self, 'test', r'^a') six.assertRegex(self, 'test', r'^t') TestAssertRegex('test').test()
def successful(self): """ Return whether the call completed without raising an exception. Will raise AssertionError if the result is not ready. """ if not self.ready(): raise exceptions.AssertionError("Function is not ready") res = self._q.get() self._q.put(res) if isinstance(res, Exception): return False return True
def __init__(self, object, method, message='', **kwds): super(AssertionError,self).__init__(kwds) self.object,self.message = object,message self.method = method
def test_assertCountEqual(): class TestAssertCountEqual(unittest.TestCase): def test(self): with self.assertRaises(AssertionError): six.assertCountEqual(self, (1, 2), [3, 4, 5]) six.assertCountEqual(self, (1, 2), [2, 1]) TestAssertCountEqual('test').test()
def test_assertRaisesRegex(): class TestAssertRaisesRegex(unittest.TestCase): def test(self): with six.assertRaisesRegex(self, AssertionError, '^Foo'): raise AssertionError('Foo') with self.assertRaises(AssertionError): with six.assertRaisesRegex(self, AssertionError, r'^Foo'): raise AssertionError('Bar') TestAssertRaisesRegex('test').test()