Skip to content

Commit fd64654

Browse files
authored
Add a unit test for the tag_proto_objects method (feast-dev#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>
1 parent 2e41d03 commit fd64654

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from feast.diff.FcoDiff import diff_between, tag_proto_objects_for_keep_delete_add
2+
from feast.feature_view import FeatureView
3+
from tests.utils.data_source_utils import prep_file_source
4+
5+
6+
def test_tag_proto_objects_for_keep_delete_add(simple_dataset_1):
7+
with prep_file_source(
8+
df=simple_dataset_1, event_timestamp_column="ts_1"
9+
) as file_source:
10+
to_delete = FeatureView(
11+
name="to_delete", entities=["id"], batch_source=file_source, ttl=None,
12+
).to_proto()
13+
unchanged_fv = FeatureView(
14+
name="fv1", entities=["id"], batch_source=file_source, ttl=None,
15+
).to_proto()
16+
pre_changed = FeatureView(
17+
name="fv2",
18+
entities=["id"],
19+
batch_source=file_source,
20+
ttl=None,
21+
tags={"when": "before"},
22+
).to_proto()
23+
post_changed = FeatureView(
24+
name="fv2",
25+
entities=["id"],
26+
batch_source=file_source,
27+
ttl=None,
28+
tags={"when": "after"},
29+
).to_proto()
30+
to_add = FeatureView(
31+
name="to_add", entities=["id"], batch_source=file_source, ttl=None,
32+
).to_proto()
33+
34+
keep, delete, add = tag_proto_objects_for_keep_delete_add(
35+
[unchanged_fv, pre_changed, to_delete], [unchanged_fv, post_changed, to_add]
36+
)
37+
38+
assert len(list(keep)) == 2
39+
assert unchanged_fv in keep
40+
assert post_changed in keep
41+
assert pre_changed not in keep
42+
assert len(list(delete)) == 1
43+
assert to_delete in delete
44+
assert len(list(add)) == 1
45+
assert to_add in add
46+
47+
48+
def test_diff_between_feature_views(simple_dataset_1):
49+
with prep_file_source(
50+
df=simple_dataset_1, event_timestamp_column="ts_1"
51+
) as file_source:
52+
pre_changed = FeatureView(
53+
name="fv2",
54+
entities=["id"],
55+
batch_source=file_source,
56+
ttl=None,
57+
tags={"when": "before"},
58+
).to_proto()
59+
post_changed = FeatureView(
60+
name="fv2",
61+
entities=["id"],
62+
batch_source=file_source,
63+
ttl=None,
64+
tags={"when": "after"},
65+
).to_proto()
66+
67+
fco_diffs = diff_between(pre_changed, pre_changed, "feature view")
68+
assert len(fco_diffs.fco_property_diffs) == 0
69+
70+
fco_diffs = diff_between(pre_changed, post_changed, "feature view")
71+
assert len(fco_diffs.fco_property_diffs) == 1
72+
73+
assert fco_diffs.fco_property_diffs[0].property_name == "tags"
74+
assert fco_diffs.fco_property_diffs[0].val_existing == {"when": "before"}
75+
assert fco_diffs.fco_property_diffs[0].val_declared == {"when": "after"}

0 commit comments

Comments
 (0)