@@ -303,6 +303,7 @@ def test_no_track_times(self, setup_path):
303
303
304
304
import hashlib
305
305
import time
306
+ import tables
306
307
307
308
def checksum (filename , hash_factory = hashlib .md5 , chunk_num_blocks = 128 ):
308
309
h = hash_factory ()
@@ -315,32 +316,39 @@ def create_h5_and_return_checksum(track_times):
315
316
with ensure_clean_path (setup_path ) as path :
316
317
df = pd .DataFrame ({"a" : [1 ]})
317
318
318
- hdf = pd .HDFStore (path , mode = "w" )
319
- hdf .put (
320
- "table" ,
321
- df ,
322
- format = "table" ,
323
- data_columns = True ,
324
- index = None ,
325
- track_times = track_times ,
326
- )
327
- hdf . close ()
319
+ with pd .HDFStore (path , mode = "w" ) as hdf :
320
+ hdf .put (
321
+ "table" ,
322
+ df ,
323
+ format = "table" ,
324
+ data_columns = True ,
325
+ index = None ,
326
+ track_times = track_times ,
327
+ )
328
+
328
329
return checksum (path )
329
330
330
- checksum_0_tt_false = create_h5_and_return_checksum (track_times = False )
331
- checksum_0_tt_true = create_h5_and_return_checksum (track_times = True )
331
+ if tables .__version__ < "3.4.3" :
332
+ with pytest .raises (
333
+ ValueError ,
334
+ match = "You cannot set track_times with table version < 3.4.3" ,
335
+ ):
336
+ create_h5_and_return_checksum (track_times = False )
337
+ else :
338
+ checksum_0_tt_false = create_h5_and_return_checksum (track_times = False )
339
+ checksum_0_tt_true = create_h5_and_return_checksum (track_times = True )
332
340
333
- # sleep is necessary to create h5 with different creation time
334
- time .sleep (1 )
341
+ # sleep is necessary to create h5 with different creation time
342
+ time .sleep (1 )
335
343
336
- checksum_1_tt_false = create_h5_and_return_checksum (track_times = False )
337
- checksum_1_tt_true = create_h5_and_return_checksum (track_times = True )
344
+ checksum_1_tt_false = create_h5_and_return_checksum (track_times = False )
345
+ checksum_1_tt_true = create_h5_and_return_checksum (track_times = True )
338
346
339
- # checksums are the same if track_time = False
340
- assert checksum_0_tt_false == checksum_1_tt_false
347
+ # checksums are the same if track_time = False
348
+ assert checksum_0_tt_false == checksum_1_tt_false
341
349
342
- # checksums are NOT same if track_time = True
343
- assert checksum_0_tt_true != checksum_1_tt_true
350
+ # checksums are NOT same if track_time = True
351
+ assert checksum_0_tt_true != checksum_1_tt_true
344
352
345
353
def test_keys_ignore_hdf_softlink (self , setup_path ):
346
354
0 commit comments