File: test_exceptions.py

package info (click to toggle)
py-postgresql 1.2.1%2Bgit20180803.ef7b9a9-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,620 kB
  • sloc: python: 18,317; ansic: 2,024; sql: 282; sh: 26; makefile: 22
file content (56 lines) | stat: -rw-r--r-- 1,495 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
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()