MCPcopy
hub / github.com/feast-dev/feast / test_diff_infra_protos

Function test_diff_infra_protos

sdk/python/tests/unit/diff/test_infra_diff.py:95–181  ·  view source on GitHub ↗
(_, tmp_path)

Source from the content-addressed store, hash-verified

93
94@patch("feast.infra.online_stores.sqlite._initialize_conn")
95def test_diff_infra_protos(_, tmp_path):
96 db_dir = tmp_path / "db"
97 db_dir.mkdir()
98 db_dir_str = str(db_dir)
99
100 to_delete = SqliteTable(path=db_dir_str, name="to_delete")
101 to_add = SqliteTable(path=db_dir_str, name="to_add")
102 unchanged_table = SqliteTable(path=db_dir_str, name="unchanged")
103 pre_changed = DatastoreTable(
104 project="test", name="table", project_id="pre", namespace="pre"
105 )
106 post_changed = DatastoreTable(
107 project="test", name="table", project_id="post", namespace="post"
108 )
109
110 infra_objects_before = [to_delete, unchanged_table, pre_changed]
111 infra_objects_after = [to_add, unchanged_table, post_changed]
112
113 infra_proto_before = InfraProto()
114 infra_proto_before.infra_objects.extend(
115 [obj.to_infra_object_proto() for obj in infra_objects_before]
116 )
117
118 infra_proto_after = InfraProto()
119 infra_proto_after.infra_objects.extend(
120 [obj.to_infra_object_proto() for obj in infra_objects_after]
121 )
122
123 infra_diff = diff_infra_protos(infra_proto_before, infra_proto_after)
124 infra_object_diffs = infra_diff.infra_object_diffs
125
126 # There should be one addition, one deletion, one unchanged, and one changed.
127 assert len(infra_object_diffs) == 4
128
129 additions = [
130 infra_object_diff
131 for infra_object_diff in infra_object_diffs
132 if infra_object_diff.transition_type == TransitionType.CREATE
133 ]
134 assert len(additions) == 1
135 assert not additions[0].current_infra_object
136 assert additions[0].new_infra_object == to_add.to_proto()
137 assert len(additions[0].infra_object_property_diffs) == 0
138
139 deletions = [
140 infra_object_diff
141 for infra_object_diff in infra_object_diffs
142 if infra_object_diff.transition_type == TransitionType.DELETE
143 ]
144 assert len(deletions) == 1
145 assert deletions[0].current_infra_object == to_delete.to_proto()
146 assert not deletions[0].new_infra_object
147 assert len(deletions[0].infra_object_property_diffs) == 0
148
149 unchanged = [
150 infra_object_diff
151 for infra_object_diff in infra_object_diffs
152 if infra_object_diff.transition_type == TransitionType.UNCHANGED

Callers

nothing calls this directly

Calls 6

to_protoMethod · 0.95
to_protoMethod · 0.95
SqliteTableClass · 0.90
DatastoreTableClass · 0.90
diff_infra_protosFunction · 0.90
to_infra_object_protoMethod · 0.45

Tested by

no test coverage detected