Skip to content

Commit c44449d

Browse files
Further test improvements.
1 parent 25e3890 commit c44449d

39 files changed

+1578
-1579
lines changed

tests/test_1000_module.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -27,7 +27,6 @@
2727
"""
2828

2929
import datetime
30-
import time
3130

3231
import oracledb
3332
import test_env
@@ -38,8 +37,8 @@ class TestCase(test_env.BaseTestCase):
3837
def test_1000_date_from_ticks(self):
3938
"1000 - test DateFromTicks()"
4039
today = datetime.datetime.today()
41-
timestamp = time.mktime(today.timetuple())
42-
date = oracledb.DateFromTicks(timestamp)
40+
timestamp = today.timestamp()
41+
date = oracledb.DateFromTicks(int(timestamp))
4342
self.assertEqual(date, today.date())
4443

4544
def test_1001_future_obj(self):
@@ -50,7 +49,7 @@ def test_1001_future_obj(self):
5049

5150
def test_1002_timestamp_from_ticks(self):
5251
"1002 - test TimestampFromTicks()"
53-
timestamp = time.mktime(datetime.datetime.today().timetuple())
52+
timestamp = datetime.datetime.today().timestamp()
5453
today = datetime.datetime.fromtimestamp(timestamp)
5554
date = oracledb.TimestampFromTicks(timestamp)
5655
self.assertEqual(date, today)

tests/test_1100_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@ def test_1123_closed_connection_attributes(self):
328328

329329
def test_1124_ping(self):
330330
"1124 - test connection ping makes a round trip"
331-
self.connection = test_env.get_connection()
331+
self.conn = test_env.get_connection()
332332
self.setup_round_trip_checker()
333-
self.connection.ping()
333+
self.conn.ping()
334334
self.assertRoundTrips(1)
335335

336336
@unittest.skipIf(test_env.get_is_thin(),

tests/test_1300_cursor_var.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class TestCase(test_env.BaseTestCase):
3333

3434
def test_1300_bind_cursor(self):
3535
"1300 - test binding in a cursor"
36-
cursor = self.connection.cursor()
37-
self.assertEqual(cursor.description, None)
36+
cursor = self.conn.cursor()
37+
self.assertIsNone(cursor.description)
3838
self.cursor.execute("""
3939
begin
4040
open :cursor for select 'X' StringValue from dual;
@@ -50,8 +50,8 @@ def test_1300_bind_cursor(self):
5050

5151
def test_1301_bind_cursor_in_package(self):
5252
"1301 - test binding in a cursor from a package"
53-
cursor = self.connection.cursor()
54-
self.assertEqual(cursor.description, None)
53+
cursor = self.conn.cursor()
54+
self.assertIsNone(cursor.description)
5555
self.cursor.callproc("pkg_TestRefCursors.TestOutCursor", (2, cursor))
5656
varchar_ratio, nvarchar_ratio = test_env.get_charset_ratios()
5757
expected_value = [
@@ -64,7 +64,7 @@ def test_1301_bind_cursor_in_package(self):
6464

6565
def test_1302_bind_self(self):
6666
"1302 - test that binding the cursor itself is not supported"
67-
cursor = self.connection.cursor()
67+
cursor = self.conn.cursor()
6868
sql = """
6969
begin
7070
open :pcursor for
@@ -75,7 +75,7 @@ def test_1302_bind_self(self):
7575

7676
def test_1303_execute_after_close(self):
7777
"1303 - test returning a ref cursor after closing it"
78-
out_cursor = self.connection.cursor()
78+
out_cursor = self.conn.cursor()
7979
sql = """
8080
begin
8181
open :pcursor for
@@ -86,7 +86,7 @@ def test_1303_execute_after_close(self):
8686
self.cursor.execute(sql, pcursor=out_cursor)
8787
rows = out_cursor.fetchall()
8888
out_cursor.close()
89-
out_cursor = self.connection.cursor()
89+
out_cursor = self.conn.cursor()
9090
self.cursor.execute(sql, pcursor=out_cursor)
9191
rows2 = out_cursor.fetchall()
9292
self.assertEqual(rows, rows2)
@@ -110,94 +110,93 @@ def test_1304_fetch_cursor(self):
110110

111111
def test_1305_ref_cursor_binds(self):
112112
"1305 - test that ref cursor binds cannot use optimised path"
113-
ref_cursor = self.connection.cursor()
113+
ref_cursor = self.conn.cursor()
114114
sql = """
115115
begin
116116
open :rcursor for
117117
select IntCol, StringCol
118118
from TestStrings where IntCol
119119
between :start_value and :end_value;
120120
end;"""
121-
self.cursor.execute(sql, rcursor=ref_cursor, start_value=2,
122-
end_value=4)
123121
expected_value = [
124122
(2, 'String 2'),
125123
(3, 'String 3'),
126124
(4, 'String 4')
127125
]
128-
rows = ref_cursor.fetchall()
126+
self.cursor.execute(sql, rcursor=ref_cursor, start_value=2,
127+
end_value=4)
128+
self.assertEqual(ref_cursor.fetchall(), expected_value)
129129
ref_cursor.close()
130-
self.assertEqual(rows, expected_value)
131-
ref_cursor = self.connection.cursor()
132-
self.cursor.execute(sql, rcursor=ref_cursor, start_value=5,
133-
end_value=6)
130+
134131
expected_value = [
135132
(5, 'String 5'),
136133
(6, 'String 6')
137134
]
138-
rows = ref_cursor.fetchall()
139-
self.assertEqual(rows, expected_value)
135+
ref_cursor = self.conn.cursor()
136+
self.cursor.execute(sql, rcursor=ref_cursor, start_value=5,
137+
end_value=6)
138+
self.assertEqual(ref_cursor.fetchall(), expected_value)
140139

141140
def test_1306_refcursor_round_trips(self):
142141
"1306 - test round trips using a REF cursor"
143142
self.setup_round_trip_checker()
144143

145144
# simple DDL only requires a single round trip
146-
with self.connection.cursor() as cursor:
145+
with self.conn.cursor() as cursor:
147146
cursor.execute("truncate table TestTempTable")
148147
self.assertRoundTrips(1)
149148

150149
# array execution only requires a single round trip
151150
num_rows = 590
152-
with self.connection.cursor() as cursor:
151+
with self.conn.cursor() as cursor:
153152
sql = "insert into TestTempTable (IntCol) values (:1)"
154153
data = [(n + 1,) for n in range(num_rows)]
155154
cursor.executemany(sql, data)
156155
self.assertRoundTrips(1)
157156

158157
# create REF cursor and execute stored procedure
159158
# (array size set before procedure is called)
160-
with self.connection.cursor() as cursor:
161-
refcursor = self.connection.cursor()
159+
with self.conn.cursor() as cursor:
160+
refcursor = self.conn.cursor()
162161
refcursor.arraysize = 150
163162
cursor.callproc("myrefcursorproc", [refcursor])
164163
refcursor.fetchall()
165164
self.assertRoundTrips(5)
166165

167166
# create REF cursor and execute stored procedure
168167
# (array size set after procedure is called)
169-
with self.connection.cursor() as cursor:
170-
refcursor = self.connection.cursor()
168+
with self.conn.cursor() as cursor:
169+
refcursor = self.conn.cursor()
171170
cursor.callproc("myrefcursorproc", [refcursor])
172171
refcursor.arraysize = 145
173172
refcursor.fetchall()
174173
self.assertRoundTrips(6)
175174

176175
def test_1307_refcursor_execute_different_sql(self):
177176
"1307 - test executing different SQL after getting a REF cursor"
178-
with self.connection.cursor() as cursor:
179-
refcursor = self.connection.cursor()
177+
with self.conn.cursor() as cursor:
178+
refcursor = self.conn.cursor()
180179
cursor.callproc("myrefcursorproc", [refcursor])
181180
var = cursor.var(int)
182181
refcursor.execute("begin :1 := 15; end;", [var])
183182
self.assertEqual(var.getvalue(), 15)
184183

185184
def test_1308_function_with_ref_cursor_return(self):
186185
"1308 - test calling a function that returns a REF cursor"
187-
with self.connection.cursor() as cursor:
186+
with self.conn.cursor() as cursor:
188187
ref_cursor = cursor.callfunc("pkg_TestRefCursors.TestReturnCursor",
189188
oracledb.DB_TYPE_CURSOR, [2])
190-
rows = ref_cursor.fetchall()
191-
self.assertEqual(rows, [(1, 'String 1'), (2, 'String 2')])
189+
self.assertEqual(ref_cursor.fetchall(),
190+
[(1, 'String 1'), (2, 'String 2')])
192191

193192
def test_1309_output_type_handler_with_ref_cursor(self):
194193
"1309 - test using an output type handler with a REF cursor"
195194
def type_handler(cursor, metadata):
196195
return cursor.var(str, arraysize=cursor.arraysize)
197-
self.connection.outputtypehandler = type_handler
196+
self.conn.outputtypehandler = type_handler
198197
var = self.cursor.var(oracledb.DB_TYPE_CURSOR)
199198
string_val = "Test String - 1309"
200-
with self.connection.cursor() as cursor:
199+
with self.conn.cursor() as cursor:
201200
cursor.callproc("pkg_TestRefCursors.TestLobCursor",
202201
[string_val, var])
203202
ref_cursor = var.getvalue()
@@ -314,7 +313,7 @@ def test_1313_fetch_nested_cursors_with_more_cols_than_parent(self):
314313
def test_1314_reuse_closed_ref_cursor_with_different_sql(self):
315314
"1314 - test reusing a closed ref cursor for executing different sql"
316315
sql = "select 13141, 'String 13141' from dual"
317-
ref_cursor = self.connection.cursor()
316+
ref_cursor = self.conn.cursor()
318317
ref_cursor.prefetchrows = 0
319318
ref_cursor.execute(sql)
320319
plsql = "begin pkg_TestRefCursors.TestCloseCursor(:rcursor); end;"
@@ -326,7 +325,7 @@ def test_1314_reuse_closed_ref_cursor_with_different_sql(self):
326325
def test_1315_reuse_closed_ref_cursor_with_same_sql(self):
327326
"1315 - test reusing a closed ref cursor for executing same sql"
328327
sql = "select 1315, 'String 1315' from dual"
329-
ref_cursor = self.connection.cursor()
328+
ref_cursor = self.conn.cursor()
330329
ref_cursor.prefetchrows = 0
331330
ref_cursor.execute(sql)
332331
plsql = "begin pkg_TestRefCursors.TestCloseCursor(:rcursor); end;"

0 commit comments

Comments
 (0)