1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
# Copyright (C) 2016-present the asyncpg authors and contributors
# <see AUTHORS file>
#
# This module is part of asyncpg and is released under
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
import asyncio
import types
import unittest
from asyncpg import _testbase as tb
class BaseSimpleTestCase:
async def test_tests_zero_error(self):
await asyncio.sleep(0.01)
1 / 0
class TestTests(unittest.TestCase):
def test_tests_fail_1(self):
SimpleTestCase = types.new_class('SimpleTestCase',
(BaseSimpleTestCase, tb.TestCase))
suite = unittest.TestSuite()
suite.addTest(SimpleTestCase('test_tests_zero_error'))
result = unittest.TestResult()
suite.run(result)
self.assertIn('ZeroDivisionError', result.errors[0][1])
class TestHelpers(tb.TestCase):
async def test_tests_assertLoopErrorHandlerCalled_01(self):
with self.assertRaisesRegex(AssertionError, r'no message.*was logged'):
with self.assertLoopErrorHandlerCalled('aa'):
self.loop.call_exception_handler({'message': 'bb a bb'})
with self.assertLoopErrorHandlerCalled('aa'):
self.loop.call_exception_handler({'message': 'bbaabb'})
|