2828 Snapshot ,
2929 SnapshotChangeCategory ,
3030 SnapshotId ,
31+ SnapshotIntervals ,
3132 SnapshotTableCleanupTask ,
3233 missing_intervals ,
3334)
@@ -211,12 +212,21 @@ def test_snapshots_exists(state_sync: EngineAdapterStateSync, snapshots: t.List[
211212 assert state_sync .snapshots_exist (snapshot_ids ) == snapshot_ids
212213
213214
214- def get_snapshot_intervals (state_sync , snapshot ):
215- intervals = state_sync ._get_snapshot_intervals ([snapshot ])[- 1 ]
216- return intervals [0 ] if intervals else None
215+ @pytest .fixture
216+ def get_snapshot_intervals (state_sync ) -> t .Callable [[Snapshot ], t .Optional [SnapshotIntervals ]]:
217+
218+ def _get_snapshot_intervals (snapshot : Snapshot ) -> t .Optional [SnapshotIntervals ]:
219+ intervals = state_sync ._get_snapshot_intervals ([snapshot ])[- 1 ]
220+ return intervals [0 ] if intervals else None
221+
222+ return _get_snapshot_intervals
217223
218224
219- def test_add_interval (state_sync : EngineAdapterStateSync , make_snapshot : t .Callable ) -> None :
225+ def test_add_interval (
226+ state_sync : EngineAdapterStateSync ,
227+ make_snapshot : t .Callable ,
228+ get_snapshot_intervals : t .Callable ,
229+ ) -> None :
220230 snapshot = make_snapshot (
221231 SqlModel (
222232 name = "a" ,
@@ -229,24 +239,24 @@ def test_add_interval(state_sync: EngineAdapterStateSync, make_snapshot: t.Calla
229239 state_sync .push_snapshots ([snapshot ])
230240
231241 state_sync .add_interval (snapshot , "2020-01-01" , "20200101" )
232- assert get_snapshot_intervals (state_sync , snapshot ).intervals == [
242+ assert get_snapshot_intervals (snapshot ).intervals == [
233243 (to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-02" )),
234244 ]
235245
236246 state_sync .add_interval (snapshot , "20200101" , to_datetime ("2020-01-04" ))
237- assert get_snapshot_intervals (state_sync , snapshot ).intervals == [
247+ assert get_snapshot_intervals (snapshot ).intervals == [
238248 (to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-04" )),
239249 ]
240250
241251 state_sync .add_interval (snapshot , to_datetime ("2020-01-05" ), "2020-01-10" )
242- assert get_snapshot_intervals (state_sync , snapshot ).intervals == [
252+ assert get_snapshot_intervals (snapshot ).intervals == [
243253 (to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-04" )),
244254 (to_timestamp ("2020-01-05" ), to_timestamp ("2020-01-11" )),
245255 ]
246256
247257 snapshot .change_category = SnapshotChangeCategory .FORWARD_ONLY
248258 state_sync .add_interval (snapshot , to_datetime ("2020-01-16" ), "2020-01-20" , is_dev = True )
249- intervals = get_snapshot_intervals (state_sync , snapshot )
259+ intervals = get_snapshot_intervals (snapshot )
250260 assert intervals .intervals == [
251261 (to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-04" )),
252262 (to_timestamp ("2020-01-05" ), to_timestamp ("2020-01-11" )),
@@ -257,7 +267,9 @@ def test_add_interval(state_sync: EngineAdapterStateSync, make_snapshot: t.Calla
257267
258268
259269def test_add_interval_partial (
260- state_sync : EngineAdapterStateSync , make_snapshot : t .Callable
270+ state_sync : EngineAdapterStateSync ,
271+ make_snapshot : t .Callable ,
272+ get_snapshot_intervals : t .Callable ,
261273) -> None :
262274 snapshot = make_snapshot (
263275 SqlModel (
@@ -271,10 +283,10 @@ def test_add_interval_partial(
271283 state_sync .push_snapshots ([snapshot ])
272284
273285 state_sync .add_interval (snapshot , "2023-01-01" , to_timestamp ("2023-01-01" ) + 1000 )
274- assert get_snapshot_intervals (state_sync , snapshot ) is None
286+ assert get_snapshot_intervals (snapshot ) is None
275287
276288 state_sync .add_interval (snapshot , "2023-01-01" , to_timestamp ("2023-01-02" ) + 1000 )
277- assert get_snapshot_intervals (state_sync , snapshot ).intervals == [
289+ assert get_snapshot_intervals (snapshot ).intervals == [
278290 (to_timestamp ("2023-01-01" ), to_timestamp ("2023-01-02" )),
279291 ]
280292
@@ -338,7 +350,7 @@ def test_refresh_snapshot_intervals(
338350
339351
340352def test_get_snapshot_intervals (
341- state_sync : EngineAdapterStateSync , make_snapshot : t .Callable
353+ state_sync : EngineAdapterStateSync , make_snapshot : t .Callable , get_snapshot_intervals
342354) -> None :
343355 state_sync .SNAPSHOT_BATCH_SIZE = 1
344356
@@ -372,16 +384,20 @@ def test_get_snapshot_intervals(
372384 ),
373385 version = "c" ,
374386 )
375- state_sync .add_interval (snapshot_c , "2020-01-03" , "2020-01-03" )
376387 state_sync .push_snapshots ([snapshot_c ])
388+ state_sync .add_interval (snapshot_c , "2020-01-03" , "2020-01-03" )
377389
378- _ , intervals = state_sync . _get_snapshot_intervals ([ snapshot_b , snapshot_c ] )
379- assert len ( intervals ) == 2
380- assert intervals [ 0 ] .intervals == [(to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-02" ))]
381- assert intervals [ 1 ] .intervals == [(to_timestamp ("2020-01-03" ), to_timestamp ("2020-01-04" ))]
390+ a_intervals = get_snapshot_intervals ( snapshot_a )
391+ c_intervals = get_snapshot_intervals ( snapshot_c )
392+ assert a_intervals .intervals == [(to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-02" ))]
393+ assert c_intervals .intervals == [(to_timestamp ("2020-01-03" ), to_timestamp ("2020-01-04" ))]
382394
383395
384- def test_compact_intervals (state_sync : EngineAdapterStateSync , make_snapshot : t .Callable ) -> None :
396+ def test_compact_intervals (
397+ state_sync : EngineAdapterStateSync ,
398+ make_snapshot : t .Callable ,
399+ get_snapshot_intervals : t .Callable ,
400+ ) -> None :
385401 snapshot = make_snapshot (
386402 SqlModel (
387403 name = "a" ,
@@ -408,14 +424,14 @@ def test_compact_intervals(state_sync: EngineAdapterStateSync, make_snapshot: t.
408424 (to_timestamp ("2020-01-12" ), to_timestamp ("2020-01-14" )),
409425 ]
410426
411- assert get_snapshot_intervals (state_sync , snapshot ).intervals == expected_intervals
427+ assert get_snapshot_intervals (snapshot ).intervals == expected_intervals
412428
413429 state_sync .compact_intervals ()
414- assert get_snapshot_intervals (state_sync , snapshot ).intervals == expected_intervals
430+ assert get_snapshot_intervals (snapshot ).intervals == expected_intervals
415431
416432 # Make sure compaction is idempotent.
417433 state_sync .compact_intervals ()
418- assert get_snapshot_intervals (state_sync , snapshot ).intervals == expected_intervals
434+ assert get_snapshot_intervals (snapshot ).intervals == expected_intervals
419435
420436
421437def test_promote_snapshots (state_sync : EngineAdapterStateSync , make_snapshot : t .Callable ):
@@ -1248,13 +1264,17 @@ def test_unpause_snapshots_remove_intervals(
12481264 ),
12491265 version = "a" ,
12501266 )
1267+ snapshot .categorize_as (SnapshotChangeCategory .BREAKING )
1268+ snapshot .version = "a"
12511269 state_sync .push_snapshots ([snapshot ])
12521270 state_sync .add_interval (snapshot , "2023-01-01" , "2023-01-05" )
12531271
12541272 new_snapshot = make_snapshot (
12551273 SqlModel (name = "test_snapshot" , query = parse_one ("select 2, ds" ), cron = "@daily" ),
12561274 version = "a" ,
12571275 )
1276+ new_snapshot .categorize_as (SnapshotChangeCategory .FORWARD_ONLY )
1277+ new_snapshot .version = "a"
12581278 new_snapshot .effective_from = "2023-01-03"
12591279 state_sync .push_snapshots ([new_snapshot ])
12601280 state_sync .add_interval (snapshot , "2023-01-06" , "2023-01-06" )
0 commit comments