@@ -491,6 +491,46 @@ def test_snapshot(library):
491
491
assert versions [2 ]['snapshots' ] == ['current' ]
492
492
493
493
494
+ def test_snapshot_with_versions (library ):
495
+ """ Test snapshot of write versions consistency """
496
+ library .write (symbol , ts1 )
497
+ library .write (symbol , ts2 )
498
+
499
+ # ensure snapshot of previous version is taken
500
+ library .snapshot ('previous' , versions = {symbol : 1 })
501
+ versions = library .list_versions (symbol )
502
+ assert versions [0 ]['snapshots' ] == []
503
+ assert versions [1 ]['snapshots' ] == ['previous' ]
504
+ assert_frame_equal (library .read (symbol , as_of = 'previous' ).data , ts1 )
505
+
506
+ # ensure new snapshots are ordered after previous ones
507
+ library .snapshot ('new' )
508
+ versions = library .list_versions (symbol )
509
+ assert versions [0 ]['snapshots' ] == ['new' ]
510
+ assert versions [0 ]['version' ] == 2
511
+ assert_frame_equal (library .read (symbol , as_of = 'new' ).data , ts2 )
512
+
513
+ assert versions [1 ]['snapshots' ] == ['previous' ]
514
+ assert versions [1 ]['version' ] == 1
515
+ assert_frame_equal (library .read (symbol , as_of = 'previous' ).data , ts1 )
516
+
517
+ # ensure snapshot of previous version doesn't overwrite current version
518
+ library .write (symbol , ts1 , prune_previous_version = True )
519
+ library .snapshot ('another' , versions = {symbol : 1 })
520
+ versions = library .list_versions (symbol )
521
+
522
+ assert versions [0 ]['snapshots' ] == []
523
+ assert versions [0 ]['version' ] == 3
524
+ assert_frame_equal (library .read (symbol ).data , ts1 )
525
+
526
+ assert versions [1 ]['snapshots' ] == ['new' ]
527
+ assert versions [1 ]['version' ] == 2
528
+
529
+ assert versions [2 ]['snapshots' ] == ['previous' , 'another' ]
530
+ assert versions [2 ]['version' ] == 1
531
+ assert_frame_equal (library .read (symbol , as_of = 'another' ).data , ts1 )
532
+
533
+
494
534
def test_snapshot_exclusion (library ):
495
535
library .write (symbol , ts1 )
496
536
library .snapshot ('current' , skip_symbols = [symbol ])
0 commit comments