forked from oracle/python-cx_Oracle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathError.py
More file actions
49 lines (42 loc) · 1.93 KB
/
Error.py
File metadata and controls
49 lines (42 loc) · 1.93 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
#------------------------------------------------------------------------------
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
#
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
#
# Portions Copyright 2001-2007, Computronix (Canada) Ltd., Edmonton, Alberta,
# Canada. All rights reserved.
#------------------------------------------------------------------------------
"""Module for testing error objects."""
import TestEnv
import cx_Oracle
import pickle
class TestCase(TestEnv.BaseTestCase):
def testParseError(self):
"test parse error returns offset correctly"
with self.assertRaises(cx_Oracle.Error) as cm:
self.cursor.execute("begin t_Missing := 5; end;")
errorObj, = cm.exception.args
self.assertEqual(errorObj.offset, 6)
def testPickleError(self):
"test picking/unpickling an error object"
with self.assertRaises(cx_Oracle.Error) as cm:
self.cursor.execute("""
begin
raise_application_error(-20101, 'Test!');
end;""")
errorObj, = cm.exception.args
self.assertEqual(type(errorObj), cx_Oracle._Error)
self.assertTrue("Test!" in errorObj.message)
self.assertEqual(errorObj.code, 20101)
self.assertEqual(errorObj.offset, 0)
self.assertTrue(isinstance(errorObj.isrecoverable, bool))
pickledData = pickle.dumps(errorObj)
newErrorObj = pickle.loads(pickledData)
self.assertEqual(type(newErrorObj), cx_Oracle._Error)
self.assertTrue(newErrorObj.message == errorObj.message)
self.assertTrue(newErrorObj.code == errorObj.code)
self.assertTrue(newErrorObj.offset == errorObj.offset)
self.assertTrue(newErrorObj.context == errorObj.context)
self.assertTrue(newErrorObj.isrecoverable == errorObj.isrecoverable)
if __name__ == "__main__":
TestEnv.RunTestCases()