Skip to content

Commit ef60884

Browse files
Additional test cases to improve code coverage.
1 parent 18b014a commit ef60884

8 files changed

Lines changed: 101 additions & 0 deletions

File tree

test/Connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,11 @@ def testThreading(self):
229229
for thread in threads:
230230
thread.join()
231231

232+
def testStringFormat(self):
233+
"test string format of connection"
234+
connection = cx_Oracle.connect(self.username, self.password,
235+
self.tnsentry)
236+
expectedValue = "<cx_Oracle.Connection to %s@%s>" % \
237+
(self.username, self.tnsentry)
238+
self.assertEqual(str(connection), expectedValue)
239+

test/Cursor.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,25 @@ def testSetInputSizesByPosition(self):
455455
end;""", [var, 'test_', 5, '_second_', 3, 7])
456456
self.assertEqual(var.getvalue(), u"test_5_second_37")
457457

458+
def testStringFormat(self):
459+
"""test string format of cursor"""
460+
formatString = "<cx_Oracle.Cursor on <cx_Oracle.Connection to %s@%s>>"
461+
expectedValue = formatString % (USERNAME, TNSENTRY)
462+
self.assertEqual(str(self.cursor), expectedValue)
463+
464+
def testCursorFetchRaw(self):
465+
"""test cursor.fetchraw()"""
466+
cursor = self.connection.cursor()
467+
cursor.arraysize = 25
468+
cursor.execute("select LongIntCol from TestNumbers order by IntCol")
469+
self.assertEqual(cursor.fetchraw(), 10)
470+
self.assertEqual(cursor.fetchvars[0].getvalue(), 38)
471+
472+
def testParse(self):
473+
"""test parsing statements"""
474+
sql = "select LongIntCol from TestNumbers where IntCol = :val"
475+
self.cursor.parse(sql)
476+
self.assertEqual(self.cursor.statement, sql)
477+
self.assertEqual(self.cursor.description,
478+
[ ('LONGINTCOL', cx_Oracle.NUMBER, 17, None, 16, 0, 0) ])
479+

test/NumberVar.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,10 @@ def testReturnFloatFromDivision(self):
330330
self.assertEqual(result, 1.0 / 7.0)
331331
self.assertTrue(isinstance(result, float), "float not returned")
332332

333+
def testStringFormat(self):
334+
"test that string format is returned properly"
335+
var = self.cursor.var(cx_Oracle.NUMBER)
336+
self.assertEqual(str(var), "<cx_Oracle.NUMBER with value None>")
337+
var.setvalue(0, 4)
338+
self.assertEqual(str(var), "<cx_Oracle.NUMBER with value 4.0>")
339+

test/ObjectVar.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,9 @@ def testSettingVarWrongObjectType(self):
263263
var = self.cursor.var(cx_Oracle.OBJECT, typename = "UDT_OBJECT")
264264
self.assertRaises(cx_Oracle.DatabaseError, var.setvalue, 0, wrongObj)
265265

266+
def testStringFormat(self):
267+
"test object string format"
268+
objType = self.connection.gettype("UDT_OBJECT")
269+
self.assertEqual(str(objType),
270+
"<cx_Oracle.ObjectType CX_ORACLE.UDT_OBJECT>")
271+

test/SessionPool.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ def testPool(self):
5353
self.assertEqual(pool.busy, 2, "busy not 2 after release")
5454
del connection_2
5555
self.assertEqual(pool.busy, 1, "busy not 1 after del")
56+
pool.getmode = cx_Oracle.SPOOL_ATTRVAL_NOWAIT
57+
self.assertEqual(pool.getmode, cx_Oracle.SPOOL_ATTRVAL_NOWAIT)
58+
pool.stmtcachesize = 50
59+
self.assertEqual(pool.stmtcachesize, 50)
60+
pool.timeout = 10
61+
self.assertEqual(pool.timeout, 10)
62+
if CLIENT_VERSION >= (12, 1):
63+
pool.max_lifetime_session = 10
64+
self.assertEqual(pool.max_lifetime_session, 10)
5665

5766
def testProxyAuth(self):
5867
"""test that proxy authentication is possible"""
@@ -135,3 +144,40 @@ def testThreadingWithErrors(self):
135144
for thread in threads:
136145
thread.join()
137146

147+
def testPurity(self):
148+
"""test session pool with various types of purity"""
149+
action = "TEST_ACTION"
150+
pool = cx_Oracle.SessionPool(USERNAME, PASSWORD, TNSENTRY, min = 1,
151+
max = 8, increment = 1, encoding = ENCODING,
152+
nencoding = NENCODING)
153+
154+
# get connection and set the action
155+
connection = pool.acquire()
156+
connection.action = action
157+
cursor = connection.cursor()
158+
cursor.execute("select 1 from dual")
159+
cursor.close()
160+
pool.release(connection)
161+
self.assertEqual(pool.opened, 1, "opened (1)")
162+
163+
# verify that the connection still has the action set on it
164+
connection = pool.acquire()
165+
cursor = connection.cursor()
166+
cursor.execute("select sys_context('userenv', 'action') from dual")
167+
result, = cursor.fetchone()
168+
self.assertEqual(result, action)
169+
cursor.close()
170+
pool.release(connection)
171+
self.assertEqual(pool.opened, 1, "opened (2)")
172+
173+
# get a new connection with new purity (should not have state)
174+
connection = pool.acquire(purity = cx_Oracle.ATTR_PURITY_NEW)
175+
cursor = connection.cursor()
176+
cursor.execute("select sys_context('userenv', 'action') from dual")
177+
result, = cursor.fetchone()
178+
self.assertEqual(result, None)
179+
cursor.close()
180+
self.assertEqual(pool.opened, 2, "opened (3)")
181+
pool.drop(connection)
182+
self.assertEqual(pool.opened, 1, "opened (4)")
183+

test/StringVar.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,9 @@ def testIssue50(self):
378378
[2, u'd5ff845a', u'94275767', u'bf161ff6', u'', u'', idVar])
379379
cursor.execute("drop table issue_50 purge")
380380

381+
def testSetRowidToString(self):
382+
"test assigning a string to rowid"
383+
var = self.cursor.var(cx_Oracle.ROWID)
384+
self.assertRaises(cx_Oracle.NotSupportedError, var.setvalue, 0,
385+
"ABDHRYTHFJGKDKKDH")
386+

test/Subscription.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ def testSubscription(self):
8989
self.assertEqual(data.rowOperations, rowOperations)
9090
self.assertEqual(data.rowids, rowids)
9191

92+
# test string format of subscription object is as expected
93+
fmt = "<cx_Oracle.Subscription on <cx_Oracle.Connection to %s@%s>>"
94+
expectedValue = fmt % (USERNAME, TNSENTRY)
95+
self.assertEqual(str(sub), expectedValue)
96+

test/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def tearDown(self):
9494
if inSetup:
9595
fileName = os.path.join("test", fileName)
9696
module = imp.new_module(name)
97+
setattr(module, "CLIENT_VERSION", cx_Oracle.clientversion())
9798
setattr(module, "USERNAME", TestEnv.MAIN_USER)
9899
setattr(module, "PASSWORD", TestEnv.MAIN_PASSWORD)
99100
setattr(module, "PROXY_USERNAME", TestEnv.PROXY_USER)

0 commit comments

Comments
 (0)