Skip to content

Commit 92523ec

Browse files
committed
test: cover delete_feature_view, the API the docs example uses
Addresses review feedback on #6504: the new docs snippet demonstrates store.delete_feature_view(name), but the only test added went through apply(objects_to_delete=..., partial=False), so the documented API was still untested. - Add test_delete_feature_view, mirroring the registry.md snippet step for step: list, delete by name, list again, then assert get_feature_view raises FeatureViewNotFoundException. - Add test_delete_feature_view_raises_when_missing, covering the FeatureViewNotFoundException that delete_feature_view's own docstring promises for an unregistered name. - Keep the apply(objects_to_delete=...) test for the `feast apply` path documented in the hint block, and note in its docstring that it is deliberately distinct from delete_feature_view. - Lift the shared source frame and registration into two helpers so the two lifecycle tests do not duplicate ~30 lines of setup. Signed-off-by: Linda Oraegbunam <obielinda@gmail.com>
1 parent 713da8c commit 92523ec

1 file changed

Lines changed: 83 additions & 26 deletions

File tree

‎sdk/python/tests/unit/local_feast_tests/test_local_feature_store.py‎

Lines changed: 83 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,30 @@ def test_apply_permissions(test_feature_store):
443443
test_feature_store.teardown()
444444

445445

446-
@pytest.mark.parametrize(
447-
"test_feature_store",
448-
[lazy_fixture("feature_store_with_local_registry")],
449-
)
450-
def test_apply_delete_feature_view(test_feature_store):
451-
"""Test that a feature view can be deleted using objects_to_delete with partial=False."""
452-
assert isinstance(test_feature_store, FeatureStore)
446+
def _apply_feature_view_to_delete(test_feature_store, file_source):
447+
"""Register an entity and a feature view, and return the feature view."""
448+
entity = Entity(
449+
name="driver_entity", join_keys=["test_key"], value_type=ValueType.INT64
450+
)
451+
driver_fv = FeatureView(
452+
name="driver_fv_to_delete",
453+
entities=[entity],
454+
schema=[Field(name="test_key", dtype=Int64)],
455+
source=file_source,
456+
)
457+
test_feature_store.apply([entity, driver_fv])
458+
459+
fvs = test_feature_store.list_batch_feature_views()
460+
assert len(fvs) == 1
461+
assert fvs[0].name == driver_fv.name
462+
463+
return driver_fv
453464

465+
466+
def _deletion_source_dataframe():
467+
"""Build the small source frame both deletion tests register against."""
454468
now = pd.Timestamp.utcnow().round("ms")
455-
dataframe_source = pd.DataFrame(
469+
return pd.DataFrame(
456470
{
457471
"test_key": [1, 2, 1, 3, 3],
458472
"feature_value": [0.1, 0.2, 0.3, 4.0, 5.0],
@@ -466,33 +480,76 @@ def test_apply_delete_feature_view(test_feature_store):
466480
}
467481
)
468482

469-
with prep_file_source(df=dataframe_source, timestamp_field="ts_1") as file_source:
470-
entity = Entity(
471-
name="driver_entity", join_keys=["test_key"], value_type=ValueType.INT64
472-
)
473-
driver_fv = FeatureView(
474-
name="driver_fv_to_delete",
475-
entities=[entity],
476-
schema=[Field(name="test_key", dtype=Int64)],
477-
source=file_source,
478-
)
479483

480-
# Register entity and feature view
481-
test_feature_store.apply([entity, driver_fv])
484+
@pytest.mark.parametrize(
485+
"test_feature_store",
486+
[lazy_fixture("feature_store_with_local_registry")],
487+
)
488+
def test_delete_feature_view(test_feature_store):
489+
"""Test the delete_feature_view lifecycle documented in registry.md.
482490
483-
# Verify feature view exists
484-
fvs = test_feature_store.list_batch_feature_views()
485-
assert len(fvs) == 1
486-
assert fvs[0].name == driver_fv.name
491+
Mirrors the end-to-end snippet in docs/getting-started/components/registry.md:
492+
list the object, delete it by name, list again to confirm it is gone, and
493+
check that fetching it afterwards raises FeatureViewNotFoundException.
494+
"""
495+
assert isinstance(test_feature_store, FeatureStore)
496+
497+
with prep_file_source(
498+
df=_deletion_source_dataframe(), timestamp_field="ts_1"
499+
) as file_source:
500+
driver_fv = _apply_feature_view_to_delete(test_feature_store, file_source)
501+
502+
# Delete the feature view by name
503+
test_feature_store.delete_feature_view(driver_fv.name)
504+
505+
# Verify feature view is deleted
506+
assert len(test_feature_store.list_batch_feature_views()) == 0
507+
508+
# Verify get_feature_view raises FeatureViewNotFoundException
509+
with pytest.raises(FeatureViewNotFoundException):
510+
test_feature_store.get_feature_view(driver_fv.name)
511+
512+
test_feature_store.teardown()
513+
514+
515+
@pytest.mark.parametrize(
516+
"test_feature_store",
517+
[lazy_fixture("feature_store_with_local_registry")],
518+
)
519+
def test_delete_feature_view_raises_when_missing(test_feature_store):
520+
"""Deleting a feature view that was never registered raises, as documented."""
521+
assert isinstance(test_feature_store, FeatureStore)
522+
523+
with pytest.raises(FeatureViewNotFoundException):
524+
test_feature_store.delete_feature_view("feature_view_that_does_not_exist")
525+
526+
test_feature_store.teardown()
527+
528+
529+
@pytest.mark.parametrize(
530+
"test_feature_store",
531+
[lazy_fixture("feature_store_with_local_registry")],
532+
)
533+
def test_apply_delete_feature_view(test_feature_store):
534+
"""Test that a feature view can be deleted using objects_to_delete with partial=False.
535+
536+
This is the `feast apply` path called out in the hint block in registry.md,
537+
and is distinct from the delete_feature_view path covered above.
538+
"""
539+
assert isinstance(test_feature_store, FeatureStore)
540+
541+
with prep_file_source(
542+
df=_deletion_source_dataframe(), timestamp_field="ts_1"
543+
) as file_source:
544+
driver_fv = _apply_feature_view_to_delete(test_feature_store, file_source)
487545

488546
# Delete the feature view using objects_to_delete
489547
test_feature_store.apply(
490548
objects=[], objects_to_delete=[driver_fv], partial=False
491549
)
492550

493551
# Verify feature view is deleted
494-
fvs = test_feature_store.list_batch_feature_views()
495-
assert len(fvs) == 0
552+
assert len(test_feature_store.list_batch_feature_views()) == 0
496553

497554
# Verify get_feature_view raises FeatureViewNotFoundException
498555
with pytest.raises(FeatureViewNotFoundException):

0 commit comments

Comments
 (0)