File: test_test.py

package info (click to toggle)
asyncpg 0.30.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,956 kB
  • sloc: python: 14,680; ansic: 1,060; makefile: 227
file content (46 lines) | stat: -rw-r--r-- 1,289 bytes parent folder | download | duplicates (3)
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'})