Skip to content

Commit 3574d72

Browse files
Test improvements.
1 parent ddac90b commit 3574d72

File tree

7 files changed

+38
-33
lines changed

7 files changed

+38
-33
lines changed

tests/test_1600_dml_returning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def test_1617_dml_returning_with_input_bind_vars(self):
440440

441441
def test_1618_dml_returning_with_lob_and_outconverter(self):
442442
"1618 - test DML returning with LOBs and an output converter"
443-
self.cursor.execute("truncate table TestCLOBs")
443+
self.cursor.execute("delete from TestCLOBs")
444444
out_var = self.cursor.var(
445445
oracledb.DB_TYPE_CLOB, outconverter=lambda value: value.read()
446446
)
@@ -459,7 +459,7 @@ def test_1618_dml_returning_with_lob_and_outconverter(self):
459459

460460
def test_1619_dml_returning_with_clob_converted_to_long(self):
461461
"1619 - test DML returning with CLOB converted to LONG"
462-
self.cursor.execute("truncate table TestCLOBs")
462+
self.cursor.execute("delete from TestCLOBs")
463463
out_var = self.cursor.var(oracledb.DB_TYPE_LONG)
464464
lob_value = "A short CLOB - 1619"
465465
self.cursor.execute(

tests/test_1900_lob_var.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def __get_temp_lobs(self, sid):
5151
def __perform_test(self, lob_type, input_type):
5252
long_string = ""
5353
db_type = getattr(oracledb, f"DB_TYPE_{lob_type}")
54-
self.cursor.execute(f"truncate table Test{lob_type}s")
54+
self.cursor.execute(f"delete from Test{lob_type}s")
55+
self.conn.commit()
5556
for i in range(11):
5657
if i > 0:
5758
char = chr(ord("A") + i - 1)
@@ -90,7 +91,8 @@ def __test_bind_ordering(self, lob_type):
9091
extra_col_1 = extra_col_1.encode()
9192
extra_col_2 = extra_col_2.encode()
9293
self.conn.stmtcachesize = 0
93-
self.cursor.execute(f"truncate table Test{lob_type}s")
94+
self.cursor.execute(f"delete from Test{lob_type}s")
95+
self.conn.commit()
9496
data = (1, main_col, 8, extra_col_1, 15, extra_col_2)
9597
self.cursor.execute(
9698
f"""
@@ -106,7 +108,8 @@ def __test_bind_ordering(self, lob_type):
106108
self.assertEqual(self.cursor.fetchone(), data)
107109

108110
def __test_fetch_lobs_direct(self, lob_type):
109-
self.cursor.execute(f"truncate table Test{lob_type}s")
111+
self.cursor.execute(f"delete from Test{lob_type}s")
112+
self.conn.commit()
110113
data = []
111114
long_string = ""
112115
for i in range(1, 11):
@@ -135,7 +138,8 @@ def __test_fetch_lobs_direct(self, lob_type):
135138
self.assertEqual(self.cursor.fetchall(), data)
136139

137140
def __test_lob_operations(self, lob_type):
138-
self.cursor.execute(f"truncate table Test{lob_type}s")
141+
self.cursor.execute(f"delete from Test{lob_type}s")
142+
self.conn.commit()
139143
self.cursor.setinputsizes(long_string=getattr(oracledb, lob_type))
140144
long_string = "X" * 75000
141145
write_value = "TEST"
@@ -214,7 +218,8 @@ def __test_pickle(self, lob_type):
214218
self.assertEqual(unpickled_value, value)
215219

216220
def __test_temporary_lob(self, lob_type):
217-
self.cursor.execute(f"truncate table Test{lob_type}s")
221+
self.cursor.execute(f"delete from Test{lob_type}s")
222+
self.conn.commit()
218223
value = "A test string value"
219224
if lob_type == "BLOB":
220225
value = value.encode("ascii")
@@ -267,14 +272,15 @@ def __validate_query(self, rows, lob_type):
267272

268273
def test_1900_bind_lob_value(self):
269274
"1900 - test binding a LOB value directly"
270-
self.cursor.execute("truncate table TestCLOBs")
275+
self.cursor.execute("delete from TestCLOBs")
271276
self.cursor.execute(
272277
"""
273278
insert into TestCLOBs
274279
(IntCol, ClobCol)
275280
values (1, 'Short value')
276281
"""
277282
)
283+
self.conn.commit()
278284
self.cursor.execute("select ClobCol from TestCLOBs")
279285
(lob,) = self.cursor.fetchone()
280286
self.cursor.execute(
@@ -343,9 +349,7 @@ def test_1911_create_temp_nclob(self):
343349
def test_1912_multiple_fetch(self):
344350
"1912 - test retrieving data from a CLOB after multiple fetches"
345351
self.cursor.arraysize = 1
346-
self.cursor.execute("select * from TestCLOBS")
347-
rows = self.cursor.fetchall()
348-
self.__validate_query(rows, "CLOB")
352+
self.__perform_test("CLOB", oracledb.DB_TYPE_CLOB)
349353

350354
def test_1913_nclob_cursor_description(self):
351355
"1913 - test cursor description is accurate for NCLOBs"
@@ -363,7 +367,7 @@ def test_1914_nclob_direct(self):
363367
def test_1915_nclob_non_ascii_chars(self):
364368
"1915 - test binding and fetching NCLOB data (with non-ASCII chars)"
365369
value = "\u03b4\u4e2a"
366-
self.cursor.execute("truncate table TestNCLOBs")
370+
self.cursor.execute("delete from TestNCLOBs")
367371
self.cursor.setinputsizes(val=oracledb.DB_TYPE_NVARCHAR)
368372
self.cursor.execute(
369373
"""
@@ -372,6 +376,7 @@ def test_1915_nclob_non_ascii_chars(self):
372376
""",
373377
val=value,
374378
)
379+
self.conn.commit()
375380
self.cursor.execute("select NCLOBCol from TestNCLOBs")
376381
(nclob,) = self.cursor.fetchone()
377382
self.cursor.setinputsizes(val=oracledb.DB_TYPE_NVARCHAR)
@@ -429,7 +434,7 @@ def test_1920_supplemental_characters(self):
429434
"𠽌 𠾴 𠾼 𠿪 𡁜 𡁯 𡁵 𡁶 𡁻 𡃁 𡃉 𡇙 𢃇 𢞵 𢫕 𢭃 𢯊 𢱑 𢱕 𢳂 𢴈 "
430435
"𢵌 𢵧 𢺳 𣲷 𤓓 𤶸 𤷪 𥄫 𦉘 𦟌 𦧲 𦧺 𧨾 𨅝 𨈇 𨋢 𨳊 𨳍 𨳒 𩶘"
431436
)
432-
self.cursor.execute("truncate table TestCLOBs")
437+
self.cursor.execute("delete from TestCLOBs")
433438
lob = self.conn.createlob(oracledb.DB_TYPE_CLOB)
434439
lob.write(supplemental_chars)
435440
self.cursor.execute(

tests/test_2300_object_var.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ def test_2306_object_type(self):
289289

290290
def test_2307_round_trip_object(self):
291291
"2307 - test inserting and then querying object with all data types"
292-
self.cursor.execute("truncate table TestClobs")
293-
self.cursor.execute("truncate table TestNClobs")
294-
self.cursor.execute("truncate table TestBlobs")
292+
self.cursor.execute("delete from TestClobs")
293+
self.cursor.execute("delete from TestNClobs")
294+
self.cursor.execute("delete from TestBlobs")
295295
self.cursor.execute(
296296
"""
297297
insert into TestClobs (IntCol, ClobCol)

tests/test_3500_json.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class TestCase(test_env.BaseTestCase):
7070
]
7171

7272
def __bind_scalar_as_json(self, data):
73-
self.cursor.execute("truncate table TestJson")
73+
self.cursor.execute("delete from TestJson")
7474
out_var = self.cursor.var(oracledb.DB_TYPE_JSON, arraysize=len(data))
7575
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON, out_var)
7676
bind_data = list(enumerate(data))
@@ -86,7 +86,7 @@ def __bind_scalar_as_json(self, data):
8686

8787
def test_3500_insert_and_fetch_single_json(self):
8888
"3500 - insert and fetch single row with JSON"
89-
self.cursor.execute("truncate table TestJson")
89+
self.cursor.execute("delete from TestJson")
9090
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON)
9191
self.cursor.execute(
9292
"insert into TestJson values (:1, :2)", [1, self.json_data]
@@ -98,7 +98,7 @@ def test_3500_insert_and_fetch_single_json(self):
9898
def test_3501_execute_with_dml_returning(self):
9999
"3501 - inserting single rows with JSON and DML returning"
100100
json_val = self.json_data[11]
101-
self.cursor.execute("truncate table TestJson")
101+
self.cursor.execute("delete from TestJson")
102102
json_out = self.cursor.var(oracledb.DB_TYPE_JSON)
103103
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON, json_out)
104104
self.cursor.execute(
@@ -113,7 +113,7 @@ def test_3501_execute_with_dml_returning(self):
113113

114114
def test_3502_insert_and_fetch_multiple_json(self):
115115
"3502 - insert and fetch multiple rows with JSON"
116-
self.cursor.execute("truncate table TestJson")
116+
self.cursor.execute("delete from TestJson")
117117
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON)
118118
data = list(enumerate(self.json_data))
119119
self.cursor.executemany("insert into TestJson values(:1, :2)", data)
@@ -122,7 +122,7 @@ def test_3502_insert_and_fetch_multiple_json(self):
122122

123123
def test_3503_executemany_with_dml_returning(self):
124124
"3503 - inserting multiple rows with JSON and DML returning"
125-
self.cursor.execute("truncate table TestJson")
125+
self.cursor.execute("delete from TestJson")
126126
int_values = [i for i in range(len(self.json_data))]
127127
out_int_var = self.cursor.var(int, arraysize=len(int_values))
128128
out_json_var = self.cursor.var(
@@ -189,7 +189,7 @@ def test_3507_bind_number(self):
189189

190190
def test_3508_unsupported_python_type_bind(self):
191191
"3508 - test binding unsupported python type with JSON"
192-
self.cursor.execute("truncate table TestJson")
192+
self.cursor.execute("delete from TestJson")
193193
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON)
194194
insert_sql = "insert into TestJson values (:1, :2)"
195195
self.assertRaisesRegex(
@@ -268,7 +268,7 @@ def test_3510_fetch_all_supported_types(self):
268268

269269
def test_3511_update_json(self):
270270
"3511 - test inserting and updating JSON"
271-
self.cursor.execute("truncate table TestJSON")
271+
self.cursor.execute("delete from TestJSON")
272272
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON)
273273
self.cursor.executemany(
274274
"insert into TestJSON values (:1, :2)",
@@ -287,7 +287,7 @@ def test_3511_update_json(self):
287287

288288
def test_3512_json_query(self):
289289
"3512 - test fetching json with json_query"
290-
self.cursor.execute("truncate table TestJson")
290+
self.cursor.execute("delete from TestJson")
291291
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON)
292292
self.cursor.executemany(
293293
"insert into TestJSON values (:1, :2)",
@@ -307,7 +307,7 @@ def test_3512_json_query(self):
307307

308308
def test_3513_json_exists(self):
309309
"3513 - test fetching json with json_exists"
310-
self.cursor.execute("truncate table TestJson")
310+
self.cursor.execute("delete from TestJson")
311311
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON)
312312
self.cursor.executemany(
313313
"insert into TestJSON values (:1, :2)",
@@ -327,7 +327,7 @@ def test_3513_json_exists(self):
327327

328328
def test_3514_select_json(self):
329329
"3514 - test selecting json data"
330-
self.cursor.execute("truncate table TestJson")
330+
self.cursor.execute("delete from TestJson")
331331
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON)
332332
self.cursor.executemany(
333333
"insert into TestJSON values (:1, :2)",
@@ -350,7 +350,7 @@ def test_3514_select_json(self):
350350

351351
def test_3515_json_serialize(self):
352352
"3515 - test fetching json with json_serialize"
353-
self.cursor.execute("truncate table TestJson")
353+
self.cursor.execute("delete from TestJson")
354354
data = [{"a": 12.5}, {"b": True}, {"c": None}]
355355
expected_data = ['{"a":12.5}', '{"b":true}', '{"c":null}']
356356
self.cursor.setinputsizes(None, oracledb.DB_TYPE_JSON)

tests/test_3600_outputtypehandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def type_handler(cursor, metadata):
5959
in_value = f"Some {lob_type} data"
6060
if lob_type == "BLOB":
6161
in_value = in_value.encode()
62-
self.cursor.execute(f"truncate table Test{lob_type}s")
62+
self.cursor.execute(f"delete from Test{lob_type}s")
6363
self.cursor.execute(
6464
f"""
6565
insert into Test{lob_type}s (IntCol, {lob_type}Col)

tests/test_3800_typehandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def output_type_handler(cursor, metadata):
255255
outconverter=lambda v: json.loads(v.read()),
256256
)
257257

258-
self.cursor.execute("truncate table TestJson")
258+
self.cursor.execute("delete from TestJson")
259259
insert_sql = "insert into TestJson values (:1, :2)"
260260
json_data = [
261261
dict(name="John", city="Delhi"),

tests/test_4300_cursor_other.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,15 @@ def type_handler(cursor, metadata):
558558

559559
self.conn.outputtypehandler = type_handler
560560
blob_data = b"An arbitrary set of blob data for test case 4348"
561-
self.cursor.execute("truncate table TestBLOBs")
561+
self.cursor.execute("delete from TestBLOBs")
562562
self.cursor.execute(
563563
"insert into TestBLOBs (IntCol, BlobCol) values (1, :data)",
564564
[blob_data],
565565
)
566566
self.cursor.execute("select IntCol, BlobCol from TestBLOBs")
567567
self.assertEqual(self.cursor.fetchall(), [(1, blob_data)])
568568

569-
self.cursor.execute("truncate table TestBLOBs")
569+
self.cursor.execute("delete from TestBLOBs")
570570
self.cursor.execute(
571571
"insert into TestBLOBs (IntCol, BlobCol) values (1, :data)",
572572
[blob_data],
@@ -777,7 +777,7 @@ def test_4350_rowcount_after_close(self):
777777

778778
def test_4351_change_of_bind_type_with_define(self):
779779
"4351 - changing bind type with define needed"
780-
self.cursor.execute("truncate table TestClobs")
780+
self.cursor.execute("delete from TestClobs")
781781
row_for_1 = (1, "Short value 1")
782782
row_for_56 = (56, "Short value 56")
783783
for data in (row_for_1, row_for_56):
@@ -876,7 +876,7 @@ def test_4356_cursor_rowcount_for_queries(self):
876876

877877
def test_4357_bind_order_for_plsql(self):
878878
"4357 - test bind order for PL/SQL"
879-
self.cursor.execute("truncate table TestClobs")
879+
self.cursor.execute("delete from TestClobs")
880880
sql = """
881881
insert into TestClobs (IntCol, CLOBCol, ExtraNumCol1)
882882
values (:1, :2, :3)"""

0 commit comments

Comments
 (0)