Skip to content

Commit 6ddb904

Browse files
Make test suite more robust.
1 parent 8394bd4 commit 6ddb904

12 files changed

+50
-41
lines changed

doc/src/release_notes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Thin Mode Changes
1616
#) Fixed bug when SQL is executed after first being parsed with Oracle
1717
Database 23c.
1818

19+
Common Changes
20+
++++++++++++++
21+
22+
#) Improved test suite.
23+
1924

2025
oracledb 1.3.0 (March 2023)
2126
---------------------------

tests/sql/create_schema.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'
3434
/
3535
alter session set nls_numeric_characters='.,'
3636
/
37+
alter session set time_zone='+00:00'
38+
/
3739

3840
create user &main_user identified by &main_password
3941
/

tests/test_1100_connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ def test_1104_autocommit(self):
138138

139139
def test_1105_bad_connect_string(self):
140140
"1105 - connection to database with bad connect string"
141-
errors = "^DPY-4000:|^DPY-4001:|^DPY-4026:|^DPY-4027:|^ORA-12154:"
142-
self.assertRaisesRegex(oracledb.DatabaseError, errors,
141+
self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-4001:|ORA-12547:",
143142
oracledb.connect, test_env.get_main_user())
144143
self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-4000:|^DPY-4001:",
145144
oracledb.connect, test_env.get_main_user() + \

tests/test_1300_cursor_var.py

Lines changed: 4 additions & 3 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
@@ -207,8 +207,9 @@ def test_1310_unassigned_ref_cursor(self):
207207
end;""",
208208
cursor=ref_cursor_var)
209209
ref_cursor = ref_cursor_var.getvalue()
210-
self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-4025:",
211-
ref_cursor.fetchall)
210+
if ref_cursor is not None:
211+
self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-4025:",
212+
ref_cursor.fetchall)
212213

213214
def test_1311_fetch_cursor_uses_custom_class(self):
214215
"1311 - test fetching a cursor with a custom class"

tests/test_1700_error.py

Lines changed: 7 additions & 6 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
@@ -64,16 +64,17 @@ def test_1701_pickle_error(self):
6464

6565
def test_1702_error_full_code(self):
6666
"1702 - test generation of full_code for ORA, DPI and DPY errors"
67+
cursor = self.connection.cursor()
6768
with self.assertRaises(oracledb.Error) as cm:
68-
self.cursor.execute(None)
69+
cursor.execute(None)
6970
error_obj, = cm.exception.args
7071
self.assertEqual(error_obj.full_code, "DPY-2001")
7172
if not self.connection.thin:
7273
with self.assertRaises(oracledb.Error) as cm:
73-
self.cursor.execute("truncate table TestTempTable")
74-
int_var = self.cursor.var(int)
75-
str_var = self.cursor.var(str, 2)
76-
self.cursor.execute("""
74+
cursor.execute("truncate table TestTempTable")
75+
int_var = cursor.var(int)
76+
str_var = cursor.var(str, 2)
77+
cursor.execute("""
7778
insert into TestTempTable (IntCol, StringCol1)
7879
values (1, 'Longer than two chars')
7980
returning IntCol, StringCol1

tests/test_2300_object_var.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def test_2303_empty_collection_as_list(self):
110110

111111
def test_2304_fetch_data(self):
112112
"2304 - test fetching objects"
113-
self.cursor.execute("alter session set time_zone = 'UTC'")
114113
self.cursor.execute("""
115114
select IntCol, ObjectCol, ArrayCol
116115
from TestObjects
@@ -256,7 +255,6 @@ def test_2306_object_type(self):
256255

257256
def test_2307_round_trip_object(self):
258257
"2307 - test inserting and then querying object with all data types"
259-
self.cursor.execute("alter session set time_zone = 'UTC'")
260258
self.cursor.execute("truncate table TestClobs")
261259
self.cursor.execute("truncate table TestNClobs")
262260
self.cursor.execute("truncate table TestBlobs")

tests/test_2700_aq.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ def test_2722_no_json_payload(self):
522522

523523
def test_2723_enqtime(self):
524524
"2723 - test message props enqtime"
525-
self.cursor.execute("alter session set time_zone = '0:00'")
526525
queue = self.get_and_clear_queue(self.book_queue_name,
527526
self.book_type_name)
528527
book = queue.payload_type.newobject()

tests/test_3200_features_12_1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,9 @@ def test_3220_implicit_results(self):
399399

400400
def test_3221_implicit_results_no_statement(self):
401401
"3221 - test getimplicitresults() without executing a statement"
402+
cursor = self.connection.cursor()
402403
self.assertRaisesRegex(oracledb.InterfaceError, "^DPY-1004:",
403-
self.cursor.getimplicitresults)
404+
cursor.getimplicitresults)
404405

405406
def test_3222_insert_with_batch_error(self):
406407
"3222 - test executing insert with multiple distinct batch errors"

tests/test_3900_cursor_execute.py

Lines changed: 3 additions & 2 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
@@ -38,8 +38,9 @@ def test_3900_execute_no_args(self):
3838

3939
def test_3901_execute_no_statement_with_args(self):
4040
"3901 - test executing a None statement with bind variables"
41+
cursor = self.connection.cursor()
4142
self.assertRaisesRegex(oracledb.ProgrammingError, "^DPY-2001:",
42-
self.cursor.execute, None, x=5)
43+
cursor.execute, None, x=5)
4344

4445
def test_3902_execute_empty_keyword_args(self):
4546
"3902 - test executing a statement with args and empty keyword args"

tests/test_4300_cursor_other.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ class TestCase(test_env.BaseTestCase):
3636

3737
def test_4300_prepare(self):
3838
"4300 - test preparing a statement and executing it multiple times"
39-
self.assertEqual(self.cursor.statement, None)
39+
cursor = self.connection.cursor()
40+
self.assertEqual(cursor.statement, None)
4041
statement = "begin :value := :value + 5; end;"
41-
self.cursor.prepare(statement)
42-
var = self.cursor.var(oracledb.NUMBER)
43-
self.assertEqual(self.cursor.statement, statement)
42+
cursor.prepare(statement)
43+
var = cursor.var(oracledb.NUMBER)
44+
self.assertEqual(cursor.statement, statement)
4445
var.setvalue(0, 2)
45-
self.cursor.execute(None, value = var)
46+
cursor.execute(None, value = var)
4647
self.assertEqual(var.getvalue(), 7)
47-
self.cursor.execute(None, value = var)
48+
cursor.execute(None, value = var)
4849
self.assertEqual(var.getvalue(), 12)
49-
self.cursor.execute("begin :value2 := 3; end;", value2 = var)
50+
cursor.execute("begin :value2 := 3; end;", value2 = var)
5051
self.assertEqual(var.getvalue(), 3)
5152

5253
def test_4301_exception_on_close(self):
@@ -81,24 +82,25 @@ def test_4303_iterators_interrupted(self):
8182

8283
def test_4304_bind_names(self):
8384
"4304 - test that bindnames() works correctly."
85+
cursor = self.connection.cursor()
8486
self.assertRaisesRegex(oracledb.ProgrammingError, "^DPY-2002:",
85-
self.cursor.bindnames)
86-
self.cursor.prepare("begin null; end;")
87-
self.assertEqual(self.cursor.bindnames(), [])
88-
self.cursor.prepare("begin :retval := :inval + 5; end;")
89-
self.assertEqual(self.cursor.bindnames(), ["RETVAL", "INVAL"])
90-
self.cursor.prepare("begin :retval := :a * :a + :b * :b; end;")
91-
self.assertEqual(self.cursor.bindnames(), ["RETVAL", "A", "B"])
92-
self.cursor.prepare("begin :a := :b + :c + :d + :e + :f + :g + " + \
93-
":h + :i + :j + :k + :l; end;")
87+
cursor.bindnames)
88+
cursor.prepare("begin null; end;")
89+
self.assertEqual(cursor.bindnames(), [])
90+
cursor.prepare("begin :retval := :inval + 5; end;")
91+
self.assertEqual(cursor.bindnames(), ["RETVAL", "INVAL"])
92+
cursor.prepare("begin :retval := :a * :a + :b * :b; end;")
93+
self.assertEqual(cursor.bindnames(), ["RETVAL", "A", "B"])
94+
cursor.prepare("begin :a := :b + :c + :d + :e + :f + :g + " + \
95+
":h + :i + :j + :k + :l; end;")
9496
names = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"]
95-
self.assertEqual(self.cursor.bindnames(), names)
96-
self.cursor.prepare("select :a * :a + :b * :b from dual")
97-
self.assertEqual(self.cursor.bindnames(), ["A", "B"])
98-
self.cursor.prepare("select :value1 + :VaLue_2 from dual")
99-
self.assertEqual(self.cursor.bindnames(), ["VALUE1", "VALUE_2"])
100-
self.cursor.prepare("select :élevé, :fenêtre from dual")
101-
self.assertEqual(self.cursor.bindnames(), ["ÉLEVÉ", "FENÊTRE"])
97+
self.assertEqual(cursor.bindnames(), names)
98+
cursor.prepare("select :a * :a + :b * :b from dual")
99+
self.assertEqual(cursor.bindnames(), ["A", "B"])
100+
cursor.prepare("select :value1 + :VaLue_2 from dual")
101+
self.assertEqual(cursor.bindnames(), ["VALUE1", "VALUE_2"])
102+
cursor.prepare("select :élevé, :fenêtre from dual")
103+
self.assertEqual(cursor.bindnames(), ["ÉLEVÉ", "FENÊTRE"])
102104

103105
def test_4305_set_input_sizes_negative(self):
104106
"4305 - test cursor.setinputsizes() with invalid parameters"

0 commit comments

Comments
 (0)