@@ -303,6 +303,8 @@ def test_no_track_times(self, setup_path):
303303
304304 import hashlib
305305 import time
306+ import tables
307+ from packaging .version import Version
306308
307309 def checksum (filename , hash_factory = hashlib .md5 , chunk_num_blocks = 128 ):
308310 h = hash_factory ()
@@ -315,32 +317,39 @@ def create_h5_and_return_checksum(track_times):
315317 with ensure_clean_path (setup_path ) as path :
316318 df = pd .DataFrame ({"a" : [1 ]})
317319
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 ()
320+ with pd .HDFStore (path , mode = "w" ) as hdf :
321+ hdf .put (
322+ "table" ,
323+ df ,
324+ format = "table" ,
325+ data_columns = True ,
326+ index = None ,
327+ track_times = track_times ,
328+ )
329+
328330 return checksum (path )
329331
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 )
332+ if Version (tables .__version__ ) < Version ("3.4.3" ):
333+ with pytest .raises (
334+ ValueError ,
335+ match = "You cannot set track_times with table version < 3.4.3" ,
336+ ):
337+ create_h5_and_return_checksum (track_times = False )
338+ else :
339+ checksum_0_tt_false = create_h5_and_return_checksum (track_times = False )
340+ checksum_0_tt_true = create_h5_and_return_checksum (track_times = True )
332341
333- # sleep is necessary to create h5 with different creation time
334- time .sleep (1 )
342+ # sleep is necessary to create h5 with different creation time
343+ time .sleep (1 )
335344
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 )
345+ checksum_1_tt_false = create_h5_and_return_checksum (track_times = False )
346+ checksum_1_tt_true = create_h5_and_return_checksum (track_times = True )
338347
339- # checksums are the same if track_time = False
340- assert checksum_0_tt_false == checksum_1_tt_false
348+ # checksums are the same if track_time = False
349+ assert checksum_0_tt_false == checksum_1_tt_false
341350
342- # checksums are NOT same if track_time = True
343- assert checksum_0_tt_true != checksum_1_tt_true
351+ # checksums are NOT same if track_time = True
352+ assert checksum_0_tt_true != checksum_1_tt_true
344353
345354 def test_keys_ignore_hdf_softlink (self , setup_path ):
346355
0 commit comments