@@ -134,6 +134,7 @@ async def test_backend_selection_by_feature_flags(
134134 def create_mock_flag_response (tc ):
135135 def mock_flag_response (flag_key , namespace , entity_id , context = None ):
136136 return tc .feature_flags .get (flag_key , False )
137+
137138 return mock_flag_response
138139
139140 mock_flag .side_effect = create_mock_flag_response (test_case )
@@ -169,14 +170,19 @@ async def test_rollout_percentage_distribution(self, backend_selector):
169170 ) as mock_flag :
170171 # Mock percentage-based rollout - capture scenario in closure
171172 def create_mock_percentage_rollout (scen ):
172- def mock_percentage_rollout (flag_key , namespace , entity_id , context = None ):
173+ def mock_percentage_rollout (
174+ flag_key , namespace , entity_id , context = None
175+ ):
173176 if flag_key == "task_abstraction_enabled" :
174177 import hashlib
175178
176- hash_value = int (hashlib .md5 (entity_id .encode ()).hexdigest (), 16 )
179+ hash_value = int (
180+ hashlib .md5 (entity_id .encode ()).hexdigest (), 16
181+ )
177182 user_bucket = hash_value % 100
178183 return user_bucket < scen ["percentage" ]
179184 return False
185+
180186 return mock_percentage_rollout
181187
182188 mock_flag .side_effect = create_mock_percentage_rollout (scenario )
@@ -226,21 +232,24 @@ async def test_organization_based_selection(self, backend_selector):
226232 with patch (
227233 "unstract.flags.feature_flag.check_feature_flag_status"
228234 ) as mock_flag :
229-
230235 # Capture case in closure
231236 def create_mock_org_based_flags (c ):
232- def mock_org_based_flags (flag_key , namespace , entity_id , context = None ):
237+ def mock_org_based_flags (
238+ flag_key , namespace , entity_id , context = None
239+ ):
233240 org_id = context .get ("organization_id" ) if context else None
234241
235242 # Organization-specific logic
236243 if org_id == "beta_org" and flag_key == "hatchet_backend_enabled" :
237244 return True
238245 elif (
239- org_id == "stable_org" and flag_key == "task_abstraction_enabled"
246+ org_id == "stable_org"
247+ and flag_key == "task_abstraction_enabled"
240248 ):
241249 return True
242250
243251 return c ["feature_flags" ].get (flag_key , False )
252+
244253 return mock_org_based_flags
245254
246255 mock_flag .side_effect = create_mock_org_based_flags (case )
@@ -269,11 +278,11 @@ async def test_fallback_chain_construction(
269278 with patch (
270279 "unstract.flags.feature_flag.check_feature_flag_status"
271280 ) as mock_flag :
272-
273281 # Capture test_case in closure
274282 def create_mock_flag_response (tc ):
275283 def mock_flag_response (flag_key , namespace , entity_id , context = None ):
276284 return tc .feature_flags .get (flag_key , False )
285+
277286 return mock_flag_response
278287
279288 mock_flag .side_effect = create_mock_flag_response (test_case )
@@ -344,7 +353,6 @@ async def test_user_segment_based_selection(self, backend_selector):
344353 with patch (
345354 "unstract.flags.feature_flag.check_feature_flag_status"
346355 ) as mock_flag :
347-
348356 # Capture segment in closure
349357 def create_mock_segment_based_flags (seg ):
350358 def mock_segment_based_flags (
@@ -362,6 +370,7 @@ def mock_segment_based_flags(
362370 elif seg ["segment" ] == "free_users" :
363371 return flag_key == "unified_celery_enabled"
364372 return False
373+
365374 return mock_segment_based_flags
366375
367376 mock_flag .side_effect = create_mock_segment_based_flags (segment )
@@ -405,11 +414,11 @@ async def test_workflow_specific_backend_preferences(self, backend_selector):
405414 with patch (
406415 "unstract.flags.feature_flag.check_feature_flag_status"
407416 ) as mock_flag :
408-
409417 # Capture preference in closure
410418 def create_mock_flag_response (pref ):
411419 def mock_flag_response (flag_key , namespace , entity_id , context = None ):
412420 return pref ["feature_flags" ].get (flag_key , False )
421+
413422 return mock_flag_response
414423
415424 mock_flag .side_effect = create_mock_flag_response (preference )
0 commit comments