Skip to content

Commit cc2c07c

Browse files
authored
break up check row and check table functions (googleapis#4407)
1 parent cc852af commit cc2c07c

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

spanner/tests/system/test_system.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,23 @@ def _assert_timestamp(self, value, nano_value):
219219
else:
220220
self.assertEqual(value.microsecond * 1000, nano_value.nanosecond)
221221

222-
def _check_row_data(self, row_data, expected=None):
222+
def _check_rows_data(self, rows_data, expected=None):
223223
if expected is None:
224224
expected = self.ROW_DATA
225225

226+
self.assertEqual(len(rows_data), len(expected))
227+
for row, expected in zip(rows_data, expected):
228+
self._check_row_data(row, expected)
229+
230+
def _check_row_data(self, row_data, expected):
226231
self.assertEqual(len(row_data), len(expected))
227-
for found, expected in zip(row_data, expected):
228-
self.assertEqual(len(found), len(expected))
229-
for found_cell, expected_cell in zip(found, expected):
230-
if isinstance(found_cell, TimestampWithNanoseconds):
231-
self._assert_timestamp(expected_cell, found_cell)
232-
elif isinstance(found_cell, float) and math.isnan(found_cell):
233-
self.assertTrue(math.isnan(expected_cell))
234-
else:
235-
self.assertEqual(found_cell, expected_cell)
232+
for found_cell, expected_cell in zip(row_data, expected):
233+
if isinstance(found_cell, TimestampWithNanoseconds):
234+
self._assert_timestamp(expected_cell, found_cell)
235+
elif isinstance(found_cell, float) and math.isnan(found_cell):
236+
self.assertTrue(math.isnan(expected_cell))
237+
else:
238+
self.assertEqual(found_cell, expected_cell)
236239

237240

238241
class TestDatabaseAPI(unittest.TestCase, _TestData):
@@ -309,7 +312,7 @@ def test_db_batch_insert_then_db_snapshot_read(self):
309312
with self._db.snapshot(read_timestamp=batch.committed) as snapshot:
310313
from_snap = list(snapshot.read(self.TABLE, self.COLUMNS, self.ALL))
311314

312-
self._check_row_data(from_snap)
315+
self._check_rows_data(from_snap)
313316

314317
def test_db_run_in_transaction_then_snapshot_execute_sql(self):
315318
retry = RetryInstanceState(_has_all_ddl)
@@ -329,7 +332,7 @@ def _unit_of_work(transaction, test):
329332

330333
with self._db.snapshot() as after:
331334
rows = list(after.execute_sql(self.SQL))
332-
self._check_row_data(rows)
335+
self._check_rows_data(rows)
333336

334337
def test_db_run_in_transaction_twice(self):
335338
retry = RetryInstanceState(_has_all_ddl)
@@ -347,7 +350,7 @@ def _unit_of_work(transaction, test):
347350

348351
with self._db.snapshot() as after:
349352
rows = list(after.execute_sql(self.SQL))
350-
self._check_row_data(rows)
353+
self._check_rows_data(rows)
351354

352355
def test_db_run_in_transaction_twice_4181(self):
353356
retry = RetryInstanceState(_has_all_ddl)
@@ -448,7 +451,7 @@ def test_batch_insert_then_read(self):
448451

449452
snapshot = session.snapshot(read_timestamp=batch.committed)
450453
rows = list(snapshot.read(self.TABLE, self.COLUMNS, self.ALL))
451-
self._check_row_data(rows)
454+
self._check_rows_data(rows)
452455

453456
def test_batch_insert_then_read_string_array_of_string(self):
454457
TABLE = 'string_plus_array_of_string'
@@ -472,7 +475,7 @@ def test_batch_insert_then_read_string_array_of_string(self):
472475

473476
snapshot = session.snapshot(read_timestamp=batch.committed)
474477
rows = list(snapshot.read(TABLE, COLUMNS, self.ALL))
475-
self._check_row_data(rows, expected=ROWDATA)
478+
self._check_rows_data(rows, expected=ROWDATA)
476479

477480
def test_batch_insert_then_read_all_datatypes(self):
478481
retry = RetryInstanceState(_has_all_ddl)
@@ -492,7 +495,7 @@ def test_batch_insert_then_read_all_datatypes(self):
492495
snapshot = session.snapshot(read_timestamp=batch.committed)
493496
rows = list(snapshot.read(
494497
self.ALL_TYPES_TABLE, self.ALL_TYPES_COLUMNS, self.ALL))
495-
self._check_row_data(rows, expected=self.ALL_TYPES_ROWDATA)
498+
self._check_rows_data(rows, expected=self.ALL_TYPES_ROWDATA)
496499

497500
def test_batch_insert_or_update_then_query(self):
498501
retry = RetryInstanceState(_has_all_ddl)
@@ -507,7 +510,7 @@ def test_batch_insert_or_update_then_query(self):
507510

508511
snapshot = session.snapshot(read_timestamp=batch.committed)
509512
rows = list(snapshot.execute_sql(self.SQL))
510-
self._check_row_data(rows)
513+
self._check_rows_data(rows)
511514

512515
@RetryErrors(exception=GrpcRendezvous)
513516
def test_transaction_read_and_insert_then_rollback(self):
@@ -586,7 +589,7 @@ def test_transaction_read_and_insert_or_update_then_commit(self):
586589
self.assertEqual(rows, [])
587590

588591
rows = list(session.read(self.TABLE, self.COLUMNS, self.ALL))
589-
self._check_row_data(rows)
592+
self._check_rows_data(rows)
590593

591594
def _transaction_concurrency_helper(self, unit_of_work, pkey):
592595
INITIAL_VALUE = 123
@@ -709,7 +712,6 @@ def _row_data(max_index):
709712
]
710713

711714
def _set_up_table(self, row_count, db=None):
712-
713715
if db is None:
714716
db = self._db
715717
retry = RetryInstanceState(_has_all_ddl)
@@ -902,7 +904,7 @@ def test_read_w_index(self):
902904

903905
expected = list(reversed(
904906
[(row[0], row[2]) for row in self._row_data(ROW_COUNT)]))
905-
self._check_row_data(rows, expected)
907+
self._check_rows_data(rows, expected)
906908

907909
def test_read_w_single_key(self):
908910
ROW_COUNT = 40
@@ -1012,7 +1014,7 @@ def _check_sql_results(
10121014
sql += ' ORDER BY eye_d'
10131015
rows = list(snapshot.execute_sql(
10141016
sql, params=params, param_types=param_types))
1015-
self._check_row_data(rows, expected=expected)
1017+
self._check_rows_data(rows, expected=expected)
10161018

10171019
def test_multiuse_snapshot_execute_sql_isolation_strong(self):
10181020
ROW_COUNT = 40

0 commit comments

Comments
 (0)