-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtest_exceptions.py
More file actions
56 lines (50 loc) · 1.46 KB
/
test_exceptions.py
File metadata and controls
56 lines (50 loc) · 1.46 KB
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
47
48
49
50
51
52
53
54
55
56
##
# .test.test_exceptions
##
import unittest
import postgresql.exceptions as pg_exc
class test_exceptions(unittest.TestCase):
def test_pg_code_lookup(self):
# in 8.4, pg started using the SQL defined error code for limits
# Users *will* get whatever code PG sends, but it's important
# that they have some way to abstract it. many-to-one map ftw.
self.assertEqual(
pg_exc.ErrorLookup('22020'), pg_exc.LimitValueError
)
def test_error_lookup(self):
# An error code that doesn't exist yields pg_exc.Error
self.assertEqual(
pg_exc.ErrorLookup('00000'), pg_exc.Error
)
self.assertEqual(
pg_exc.ErrorLookup('XX000'), pg_exc.InternalError
)
# check class fallback
self.assertEqual(
pg_exc.ErrorLookup('XX444'), pg_exc.InternalError
)
# SEARV is a very large class, so there are many
# sub-"codeclass" exceptions used to group the many
# SEARV errors. Make sure looking up 42000 actually
# gives the SEARVError
self.assertEqual(
pg_exc.ErrorLookup('42000'), pg_exc.SEARVError
)
self.assertEqual(
pg_exc.ErrorLookup('08P01'), pg_exc.ProtocolError
)
def test_warning_lookup(self):
self.assertEqual(
pg_exc.WarningLookup('01000'), pg_exc.Warning
)
self.assertEqual(
pg_exc.WarningLookup('02000'), pg_exc.NoDataWarning
)
self.assertEqual(
pg_exc.WarningLookup('01P01'), pg_exc.DeprecationWarning
)
self.assertEqual(
pg_exc.WarningLookup('01888'), pg_exc.Warning
)
if __name__ == '__main__':
unittest.main()