@@ -318,6 +318,29 @@ def _unit_of_work(transaction, test):
318318
319319
320320class TestSessionAPI (unittest .TestCase , _TestData ):
321+ ALL_TYPES_TABLE = 'all_types'
322+ ALL_TYPES_COLUMNS = (
323+ 'list_goes_on' ,
324+ 'are_you_sure' ,
325+ 'raw_data' ,
326+ 'hwhen' ,
327+ 'approx_value' ,
328+ 'eye_d' ,
329+ 'description' ,
330+ 'exactly_hwhen' ,
331+ )
332+ SOME_DATE = datetime .date (2011 , 1 , 17 )
333+ SOME_TIME = datetime .datetime (1989 , 1 , 17 , 17 , 59 , 12 , 345612 )
334+ NANO_TIME = TimestampWithNanoseconds (1995 , 8 , 31 , nanosecond = 987654321 )
335+ OTHER_NAN , = struct .unpack ('<d' , b'\x01 \x00 \x01 \x00 \x00 \x00 \xf8 \xff ' )
336+ ALL_TYPES_ROWDATA = (
337+ ([1 ], True , b'Ymlu' , SOME_DATE , 0.0 , 19 , u'dog' , SOME_TIME ),
338+ ([5 , 10 ], True , b'Ymlu' , None , 1.25 , 99 , u'cat' , None ),
339+ ([], False , b'Ym9vdHM=' , None , float ('inf' ), 107 , u'frog' , None ),
340+ ([], False , None , None , float ('-inf' ), 207 , None , None ),
341+ ([], False , None , None , float ('nan' ), 1207 , None , None ),
342+ ([], False , None , None , OTHER_NAN , 2000 , None , NANO_TIME ),
343+ )
321344
322345 @classmethod
323346 def setUpClass (cls ):
@@ -366,46 +389,24 @@ def test_batch_insert_then_read(self):
366389 self ._check_row_data (rows )
367390
368391 def test_batch_insert_then_read_all_datatypes (self ):
369- from google .cloud .spanner import KeySet
370-
371- keyset = KeySet (all_ = True )
372392 retry = RetryInstanceState (_has_all_ddl )
373393 retry (self ._db .reload )()
374394
375395 session = self ._db .session ()
376396 session .create ()
377397 self .to_delete .append (session )
378398
379- table = 'all_types'
380- columns = (
381- 'list_goes_on' ,
382- 'are_you_sure' ,
383- 'raw_data' ,
384- 'hwhen' ,
385- 'approx_value' ,
386- 'eye_d' ,
387- 'description' ,
388- 'exactly_hwhen' ,
389- )
390- some_date = datetime .date (2011 , 1 , 17 )
391- some_time = datetime .datetime (1989 , 1 , 17 , 17 , 59 , 12 , 345612 )
392- nano_time = TimestampWithNanoseconds (1995 , 8 , 31 , nanosecond = 987654321 )
393- other_nan , = struct .unpack ('<d' , b'\x01 \x00 \x01 \x00 \x00 \x00 \xf8 \xff ' )
394- row_data = (
395- ([1 ], True , b'Ymlu' , some_date , 0.0 , 19 , u'dog' , some_time ),
396- ([5 , 10 ], True , b'Ymlu' , None , 1.25 , 99 , u'cat' , None ),
397- ([], False , b'Ym9vdHM=' , None , float ('inf' ), 107 , u'frog' , None ),
398- ([], False , None , None , float ('-inf' ), 207 , None , None ),
399- ([], False , None , None , float ('nan' ), 1207 , None , None ),
400- ([], False , None , None , other_nan , 2000 , None , nano_time ),
401- )
402399 with session .batch () as batch :
403- batch .delete (table , keyset )
404- batch .insert (table , columns , row_data )
400+ batch .delete (self .ALL_TYPES_TABLE , self .ALL )
401+ batch .insert (
402+ self .ALL_TYPES_TABLE ,
403+ self .ALL_TYPES_COLUMNS ,
404+ self .ALL_TYPES_ROWDATA )
405405
406406 snapshot = session .snapshot (read_timestamp = batch .committed )
407- rows = list (snapshot .read (table , columns , keyset ))
408- self ._check_row_data (rows , expected = row_data )
407+ rows = list (snapshot .read (
408+ self .ALL_TYPES_TABLE , self .ALL_TYPES_COLUMNS , self .ALL ))
409+ self ._check_row_data (rows , expected = self .ALL_TYPES_ROWDATA )
409410
410411 def test_batch_insert_or_update_then_query (self ):
411412 retry = RetryInstanceState (_has_all_ddl )
0 commit comments