Skip to content

Commit 767be68

Browse files
Simplify code in test suite.
1 parent e1fc085 commit 767be68

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

tests/test_8000_dataframe.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@
235235
),
236236
]
237237

238+
QUERY_SQL = """
239+
select
240+
Id,
241+
FirstName,
242+
LastName,
243+
City,
244+
Country,
245+
DateOfBirth,
246+
Salary,
247+
CreditScore,
248+
LastUpdated
249+
from TestDataFrame
250+
order by id
251+
"""
252+
238253

239254
class TestCase(test_env.BaseTestCase):
240255

@@ -341,7 +356,7 @@ def __populate_table(self, data):
341356
"""
342357
Populate the test table with the given data.
343358
"""
344-
self.cursor.execute("truncate table TestDataframe")
359+
self.cursor.execute("delete from TestDataframe")
345360
types = [None] * len(data[0])
346361
types[8] = oracledb.DB_TYPE_TIMESTAMP
347362
self.cursor.setinputsizes(*types)
@@ -366,8 +381,7 @@ def __test_df_interop(self, data):
366381
"""
367382
self.__check_interop()
368383
self.__populate_table(data)
369-
statement = "select * from TestDataFrame order by Id"
370-
ora_df = self.conn.fetch_df_all(statement)
384+
ora_df = self.conn.fetch_df_all(QUERY_SQL)
371385
self.__validate_df(ora_df, data)
372386

373387
def __test_df_batches_interop(self, data, batch_size, num_batches):
@@ -377,8 +391,7 @@ def __test_df_batches_interop(self, data, batch_size, num_batches):
377391
"""
378392
self.__check_interop()
379393
self.__populate_table(data)
380-
statement = "select * from TestDataFrame order by Id"
381-
batches = list(self.conn.fetch_df_batches(statement, size=batch_size))
394+
batches = list(self.conn.fetch_df_batches(QUERY_SQL, size=batch_size))
382395
self.assertEqual(len(batches), num_batches)
383396
if num_batches == 1:
384397
self.__validate_df(batches[0], data)
@@ -402,8 +415,7 @@ def __validate_df(self, ora_df, data):
402415
def test_8000(self):
403416
"8000 - test basic fetch of data frame"
404417
self.__populate_table(DATASET_1)
405-
statement = "select * from TestDataFrame order by Id"
406-
ora_df = self.conn.fetch_df_all(statement)
418+
ora_df = self.conn.fetch_df_all(QUERY_SQL)
407419
self.assertEqual(ora_df.num_rows(), len(DATASET_1))
408420
self.assertEqual(ora_df.num_columns(), len(DATASET_1[0]))
409421

@@ -452,8 +464,7 @@ def test_8010(self):
452464
"8010 - verify passing Arrow arrays twice works"
453465
self.__check_interop()
454466
self.__populate_table(DATASET_1)
455-
statement = "select * from TestDataFrame order by Id"
456-
ora_df = self.conn.fetch_df_all(statement)
467+
ora_df = self.conn.fetch_df_all(QUERY_SQL)
457468
self.__validate_df(ora_df, DATASET_1)
458469
self.__validate_df(ora_df, DATASET_1)
459470

@@ -474,8 +485,7 @@ def test_8012(self):
474485
def test_8013(self):
475486
"8013 - negative checks on attributes"
476487
self.__populate_table(DATASET_1)
477-
statement = "select * from TestDataFrame order by Id"
478-
ora_df = self.conn.fetch_df_all(statement)
488+
ora_df = self.conn.fetch_df_all(QUERY_SQL)
479489
with self.assertRaises(IndexError):
480490
ora_df.get_column(121)
481491
with self.assertRaises(IndexError):
@@ -499,8 +509,7 @@ def test_8016(self):
499509
"8016 - verify get_column() returns the correct value"
500510
self.__check_interop()
501511
self.__populate_table(DATASET_1)
502-
statement = "select * from TestDataFrame order by Id"
503-
ora_df = self.conn.fetch_df_all(statement)
512+
ora_df = self.conn.fetch_df_all(QUERY_SQL)
504513
array = pyarrow.array(ora_df.get_column(1))
505514
self.assertEqual(array.to_pylist(), ["John", "Big"])
506515

tests/test_8100_dataframe_async.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@
235235
),
236236
]
237237

238+
QUERY_SQL = """
239+
select
240+
Id,
241+
FirstName,
242+
LastName,
243+
City,
244+
Country,
245+
DateOfBirth,
246+
Salary,
247+
CreditScore,
248+
LastUpdated
249+
from TestDataFrame
250+
order by id
251+
"""
252+
238253

239254
@test_env.skip_unless_thin_mode()
240255
class TestCase(test_env.BaseAsyncTestCase):
@@ -342,7 +357,7 @@ async def __populate_table(self, data):
342357
"""
343358
Populate the test table with the given data.
344359
"""
345-
await self.cursor.execute("truncate table TestDataframe")
360+
await self.cursor.execute("delete from TestDataframe")
346361
types = [None] * len(data[0])
347362
types[8] = oracledb.DB_TYPE_TIMESTAMP
348363
self.cursor.setinputsizes(*types)
@@ -367,8 +382,7 @@ async def __test_df_interop(self, data):
367382
"""
368383
self.__check_interop()
369384
await self.__populate_table(data)
370-
statement = "select * from TestDataFrame order by Id"
371-
ora_df = await self.conn.fetch_df_all(statement)
385+
ora_df = await self.conn.fetch_df_all(QUERY_SQL)
372386
self.__validate_df(ora_df, data)
373387

374388
async def __test_df_batches_interop(self, data, batch_size, num_batches):
@@ -378,11 +392,10 @@ async def __test_df_batches_interop(self, data, batch_size, num_batches):
378392
"""
379393
self.__check_interop()
380394
await self.__populate_table(data)
381-
statement = "select * from TestDataFrame order by Id"
382395
batches = [
383396
df
384397
async for df in self.conn.fetch_df_batches(
385-
statement, size=batch_size
398+
QUERY_SQL, size=batch_size
386399
)
387400
]
388401
self.assertEqual(len(batches), num_batches)
@@ -408,8 +421,7 @@ def __validate_df(self, ora_df, data):
408421
async def test_8100(self):
409422
"8100 - test basic fetch of data frame"
410423
await self.__populate_table(DATASET_1)
411-
statement = "select * from TestDataFrame order by Id"
412-
ora_df = await self.conn.fetch_df_all(statement)
424+
ora_df = await self.conn.fetch_df_all(QUERY_SQL)
413425
self.assertEqual(ora_df.num_rows(), len(DATASET_1))
414426
self.assertEqual(ora_df.num_columns(), len(DATASET_1[0]))
415427

@@ -460,8 +472,7 @@ async def test_8110(self):
460472
"8110 - verify passing Arrow arrays twice works"
461473
self.__check_interop()
462474
await self.__populate_table(DATASET_1)
463-
statement = "select * from TestDataFrame order by Id"
464-
ora_df = await self.conn.fetch_df_all(statement)
475+
ora_df = await self.conn.fetch_df_all(QUERY_SQL)
465476
self.__validate_df(ora_df, DATASET_1)
466477
self.__validate_df(ora_df, DATASET_1)
467478

@@ -482,8 +493,7 @@ async def test_8112(self):
482493
async def test_8113(self):
483494
"8113 - negative checks on attributes"
484495
await self.__populate_table(DATASET_1)
485-
statement = "select * from TestDataFrame order by Id"
486-
ora_df = await self.conn.fetch_df_all(statement)
496+
ora_df = await self.conn.fetch_df_all(QUERY_SQL)
487497
with self.assertRaises(IndexError):
488498
ora_df.get_column(121)
489499
with self.assertRaises(IndexError):

0 commit comments

Comments
 (0)