-
Notifications
You must be signed in to change notification settings - Fork 996
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a unit test for the tag_proto_objects method (#2163)
* Add a unit test for the tag_proto_objects method Signed-off-by: Achal Shah <achals@gmail.com> * fix tests Signed-off-by: Achal Shah <achals@gmail.com>
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |