55as both batch FeatureViews and OnDemandFeatureViews for serving.
66"""
77
8- import pytest
9- from unittest .mock import Mock , patch , MagicMock
8+ from unittest .mock import Mock , patch
9+
10+ from feast .entity import Entity
1011from feast .feature_store import FeatureStore
1112from feast .feature_view import FeatureView
12- from feast .on_demand_feature_view import OnDemandFeatureView
13- from feast .transformation .base import transformation , Transformation
14- from feast .transformation .mode import TransformationMode
1513from feast .field import Field
16- from feast .types import Float64 , Int64
17- from feast .entity import Entity
1814from feast .infra .offline_stores .file_source import FileSource
15+ from feast .on_demand_feature_view import OnDemandFeatureView
16+ from feast .transformation .base import Transformation , transformation
17+ from feast .types import Float64
1918
2019
2120class TestDualRegistration :
@@ -29,9 +28,7 @@ def test_online_enabled_creates_odfv(self):
2928
3029 # Create transformation
3130 test_transformation = Transformation (
32- mode = "python" ,
33- udf = lambda x : x ,
34- udf_string = "lambda x: x"
31+ mode = "python" , udf = lambda x : x , udf_string = "lambda x: x"
3532 )
3633
3734 fv = FeatureView (
@@ -41,15 +38,15 @@ def test_online_enabled_creates_odfv(self):
4138 schema = [Field (name = "feature1" , dtype = Float64 )],
4239 feature_transformation = test_transformation ,
4340 when = "on_write" ,
44- online_enabled = True
41+ online_enabled = True ,
4542 )
4643
4744 # Mock registry and provider
4845 mock_registry = Mock ()
4946 mock_provider = Mock ()
5047
5148 # Create FeatureStore instance with mocked initialization
52- with patch .object (FeatureStore , ' __init__' , return_value = None ):
49+ with patch .object (FeatureStore , " __init__" , return_value = None ):
5350 fs = FeatureStore ()
5451 fs ._registry = mock_registry
5552 fs ._provider = mock_provider
@@ -89,15 +86,17 @@ def capture_feature_view(view, project, commit):
8986 generated_odfv = None
9087
9188 for view in applied_views :
92- if isinstance (view , FeatureView ) and not isinstance (view , OnDemandFeatureView ):
89+ if isinstance (view , FeatureView ) and not isinstance (
90+ view , OnDemandFeatureView
91+ ):
9392 original_fv = view
9493 elif isinstance (view , OnDemandFeatureView ):
9594 generated_odfv = view
9695
9796 # Verify original FV
9897 assert original_fv is not None
9998 assert original_fv .name == "test_fv"
100- assert original_fv .online_enabled == True
99+ assert original_fv .online_enabled
101100 assert original_fv .feature_transformation is not None
102101
103102 # Verify generated ODFV
@@ -119,12 +118,12 @@ def test_no_dual_registration_when_online_disabled(self):
119118 source = mock_source ,
120119 entities = [driver ],
121120 schema = [Field (name = "feature1" , dtype = Float64 )],
122- online_enabled = False # Disabled
121+ online_enabled = False , # Disabled
123122 )
124123
125124 # Mock FeatureStore
126125 # Create FeatureStore instance with mocked initialization
127- with patch .object (FeatureStore , ' __init__' , return_value = None ):
126+ with patch .object (FeatureStore , " __init__" , return_value = None ):
128127 fs = FeatureStore ()
129128 fs .config = Mock ()
130129 fs .config .project = "test_project"
@@ -134,7 +133,9 @@ def test_no_dual_registration_when_online_disabled(self):
134133 fs ._make_inferences = Mock ()
135134
136135 applied_views = []
137- fs ._registry .apply_feature_view .side_effect = lambda view , project , commit : applied_views .append (view )
136+ fs ._registry .apply_feature_view .side_effect = (
137+ lambda view , project , commit : applied_views .append (view )
138+ )
138139 fs ._registry .apply_entity = Mock ()
139140 fs ._registry .apply_data_source = Mock ()
140141 fs ._registry .apply_feature_service = Mock ()
@@ -168,7 +169,7 @@ def test_no_dual_registration_without_transformation(self):
168169
169170 # Mock FeatureStore
170171 # Create FeatureStore instance with mocked initialization
171- with patch .object (FeatureStore , ' __init__' , return_value = None ):
172+ with patch .object (FeatureStore , " __init__" , return_value = None ):
172173 fs = FeatureStore ()
173174 fs .config = Mock ()
174175 fs .config .project = "test_project"
@@ -178,7 +179,9 @@ def test_no_dual_registration_without_transformation(self):
178179 fs ._make_inferences = Mock ()
179180
180181 applied_views = []
181- fs ._registry .apply_feature_view .side_effect = lambda view , project , commit : applied_views .append (view )
182+ fs ._registry .apply_feature_view .side_effect = (
183+ lambda view , project , commit : applied_views .append (view )
184+ )
182185 fs ._registry .apply_entity = Mock ()
183186 fs ._registry .apply_data_source = Mock ()
184187 fs ._registry .apply_feature_service = Mock ()
@@ -201,7 +204,9 @@ def test_enhanced_decorator_with_dual_registration(self):
201204 driver = Entity (name = "driver" , join_keys = ["driver_id" ])
202205
203206 # Create FeatureView using enhanced decorator with dummy source
204- dummy_source = FileSource (path = "test.parquet" , timestamp_field = "event_timestamp" )
207+ dummy_source = FileSource (
208+ path = "test.parquet" , timestamp_field = "event_timestamp"
209+ )
205210
206211 @transformation (
207212 mode = "python" ,
@@ -210,19 +215,19 @@ def test_enhanced_decorator_with_dual_registration(self):
210215 sources = [dummy_source ],
211216 schema = [Field (name = "doubled" , dtype = Float64 )],
212217 entities = [driver ],
213- name = "doubling_transform"
218+ name = "doubling_transform" ,
214219 )
215220 def doubling_transform (inputs ):
216221 return [{"doubled" : inp .get ("value" , 0 ) * 2 } for inp in inputs ]
217222
218223 # Verify it's a FeatureView with the right properties
219224 assert isinstance (doubling_transform , FeatureView )
220- assert doubling_transform .online_enabled == True
225+ assert doubling_transform .online_enabled
221226 assert doubling_transform .feature_transformation is not None
222227
223228 # Mock FeatureStore and apply
224229 # Create FeatureStore instance with mocked initialization
225- with patch .object (FeatureStore , ' __init__' , return_value = None ):
230+ with patch .object (FeatureStore , " __init__" , return_value = None ):
226231 fs = FeatureStore ()
227232 fs .config = Mock ()
228233 fs .config .project = "test_project"
@@ -232,7 +237,9 @@ def doubling_transform(inputs):
232237 fs ._make_inferences = Mock ()
233238
234239 applied_views = []
235- fs ._registry .apply_feature_view .side_effect = lambda view , project , commit : applied_views .append (view )
240+ fs ._registry .apply_feature_view .side_effect = (
241+ lambda view , project , commit : applied_views .append (view )
242+ )
236243 fs ._registry .apply_entity = Mock ()
237244 fs ._registry .apply_data_source = Mock ()
238245 fs ._registry .apply_feature_service = Mock ()
@@ -249,7 +256,9 @@ def doubling_transform(inputs):
249256 assert len (applied_views ) == 2
250257
251258 # Verify the ODFV has the same transformation
252- odfv = next ((v for v in applied_views if isinstance (v , OnDemandFeatureView )), None )
259+ odfv = next (
260+ (v for v in applied_views if isinstance (v , OnDemandFeatureView )), None
261+ )
253262 assert odfv is not None
254263 assert odfv .name == "doubling_transform_online"
255264
@@ -261,4 +270,4 @@ def doubling_transform(inputs):
261270 odfv_udf = odfv .feature_transformation .udf
262271
263272 assert original_udf (test_input ) == expected_output
264- assert odfv_udf (test_input ) == expected_output
273+ assert odfv_udf (test_input ) == expected_output
0 commit comments