Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a unit test for the tag_proto_objects method #2163

Merged
merged 2 commits into from
Dec 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions sdk/python/tests/unit/diff/test_fco_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from feast.diff.FcoDiff import diff_between, tag_proto_objects_for_keep_delete_add
from feast.feature_view import FeatureView
from tests.utils.data_source_utils import prep_file_source


def test_tag_proto_objects_for_keep_delete_add(simple_dataset_1):
with prep_file_source(
df=simple_dataset_1, event_timestamp_column="ts_1"
) as file_source:
to_delete = FeatureView(
name="to_delete", entities=["id"], batch_source=file_source, ttl=None,
).to_proto()
unchanged_fv = FeatureView(
name="fv1", entities=["id"], batch_source=file_source, ttl=None,
).to_proto()
pre_changed = FeatureView(
name="fv2",
entities=["id"],
batch_source=file_source,
ttl=None,
tags={"when": "before"},
).to_proto()
post_changed = FeatureView(
name="fv2",
entities=["id"],
batch_source=file_source,
ttl=None,
tags={"when": "after"},
).to_proto()
to_add = FeatureView(
name="to_add", entities=["id"], batch_source=file_source, ttl=None,
).to_proto()

keep, delete, add = tag_proto_objects_for_keep_delete_add(
[unchanged_fv, pre_changed, to_delete], [unchanged_fv, post_changed, to_add]
)

assert len(list(keep)) == 2
assert unchanged_fv in keep
assert post_changed in keep
assert pre_changed not in keep
assert len(list(delete)) == 1
assert to_delete in delete
assert len(list(add)) == 1
assert to_add in add


def test_diff_between_feature_views(simple_dataset_1):
with prep_file_source(
df=simple_dataset_1, event_timestamp_column="ts_1"
) as file_source:
pre_changed = FeatureView(
name="fv2",
entities=["id"],
batch_source=file_source,
ttl=None,
tags={"when": "before"},
).to_proto()
post_changed = FeatureView(
name="fv2",
entities=["id"],
batch_source=file_source,
ttl=None,
tags={"when": "after"},
).to_proto()

fco_diffs = diff_between(pre_changed, pre_changed, "feature view")
assert len(fco_diffs.fco_property_diffs) == 0

fco_diffs = diff_between(pre_changed, post_changed, "feature view")
assert len(fco_diffs.fco_property_diffs) == 1

assert fco_diffs.fco_property_diffs[0].property_name == "tags"
assert fco_diffs.fco_property_diffs[0].val_existing == {"when": "before"}
assert fco_diffs.fco_property_diffs[0].val_declared == {"when": "after"}