forked from MagicStack/asyncpg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_exceptions.py
34 lines (26 loc) · 1.2 KB
/
test_exceptions.py
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
# Copyright (C) 2016-present the ayncpg 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 asyncpg
from asyncpg import _testbase as tb
class TestExceptions(tb.ConnectedTestCase):
def test_exceptions_exported(self):
for err in ('PostgresError', 'SubstringError', 'InterfaceError'):
self.assertTrue(hasattr(asyncpg, err))
self.assertIn(err, asyncpg.__all__)
for err in ('PostgresMessage',):
self.assertFalse(hasattr(asyncpg, err))
self.assertNotIn(err, asyncpg.__all__)
self.assertIsNone(asyncpg.PostgresError.schema_name)
async def test_exceptions_unpacking(self):
with self.assertRaises(asyncpg.UndefinedTableError):
try:
await self.con.execute('SELECT * FROM _nonexistent_')
except asyncpg.UndefinedTableError as e:
self.assertEqual(e.sqlstate, '42P01')
self.assertEqual(e.position, '15')
self.assertEqual(e.query, 'SELECT * FROM _nonexistent_')
self.assertIsNotNone(e.severity)
raise