11# flake8: noqa: F811
22
3+ from time import sleep
4+
35from behave import given , then , when
46
57from openfeature .api import get_client , set_provider
1820 'the resolved {flag_type} details reason of flag with key "{key}" should be '
1921 '"{reason}"'
2022)
21- def step_impl (context , flag_type , key , expected_reason ):
23+ def step_impl_resolved_should_be (context , flag_type , key , expected_reason ):
2224 details : FlagEvaluationDetails = None
2325 if flag_type == "boolean" :
2426 details = context .boolean_flag_details
2527 assert expected_reason == details .reason .value
2628
2729
2830@given ("a provider is registered with cache disabled" )
29- def step_impl (context ):
31+ def step_impl_provider_without_cache (context ):
3032 set_provider (InMemoryProvider (IN_MEMORY_FLAGS ))
3133 context .client = get_client ()
3234
3335
3436@given ("a provider is registered" )
35- def step_impl (context ):
37+ def step_impl_provider (context ):
3638 set_provider (InMemoryProvider (IN_MEMORY_FLAGS ))
3739 context .client = get_client ()
3840
@@ -41,7 +43,7 @@ def step_impl(context):
4143 'a {flag_type} flag with key "{key}" is evaluated with details and default value '
4244 '"{default_value}"'
4345)
44- def step_impl (context , flag_type , key , default_value ):
46+ def step_impl_evaluated_with_details (context , flag_type , key , default_value ):
4547 context .client = get_client ()
4648 if flag_type == "boolean" :
4749 context .boolean_flag_details = context .client .get_boolean_details (
@@ -57,7 +59,7 @@ def step_impl(context, flag_type, key, default_value):
5759 'a boolean flag with key "{key}" is evaluated with {eval_details} and default '
5860 'value "{default_value}"'
5961)
60- def step_impl (context , key , eval_details , default_value ):
62+ def step_impl_bool_evaluated_with_details_and_default (context , key , eval_details , default_value ):
6163 client : OpenFeatureClient = context .client
6264
6365 context .boolean_flag_details = client .get_boolean_details (key , default_value )
@@ -67,7 +69,7 @@ def step_impl(context, key, eval_details, default_value):
6769 'a {flag_type} flag with key "{key}" is evaluated with default value '
6870 '"{default_value}"'
6971)
70- def step_impl (context , flag_type , key , default_value ):
72+ def step_impl_evaluated_with_default (context , flag_type , key , default_value ):
7173 client : OpenFeatureClient = context .client
7274
7375 if flag_type == "boolean" :
@@ -77,20 +79,20 @@ def step_impl(context, flag_type, key, default_value):
7779
7880
7981@then ('the resolved string value should be "{expected_value}"' )
80- def step_impl (context , expected_value ):
82+ def step_impl_resolved_string_should_be (context , expected_value ):
8183 assert expected_value == context .string_flag_details .value
8284
8385
8486@then ('the resolved boolean value should be "{expected_value}"' )
85- def step_impl (context , expected_value ):
87+ def step_impl_resolved_bool_should_be (context , expected_value ):
8688 assert parse_boolean (expected_value ) == context .boolean_flag_details .value
8789
8890
8991@when (
9092 'an integer flag with key "{key}" is evaluated with details and default value '
9193 "{default_value:d}"
9294)
93- def step_impl (context , key , default_value ):
95+ def step_impl_int_evaluated_with_details_and_default (context , key , default_value ):
9496 context .flag_key = key
9597 context .default_value = default_value
9698 context .integer_flag_details = context .client .get_integer_details (
@@ -101,7 +103,7 @@ def step_impl(context, key, default_value):
101103@when (
102104 'an integer flag with key "{key}" is evaluated with default value {default_value:d}'
103105)
104- def step_impl (context , key , default_value ):
106+ def step_impl_int_evaluated_with_default (context , key , default_value ):
105107 context .flag_key = key
106108 context .default_value = default_value
107109 context .integer_flag_details = context .client .get_integer_details (
@@ -110,26 +112,26 @@ def step_impl(context, key, default_value):
110112
111113
112114@when ('a float flag with key "{key}" is evaluated with default value {default_value:f}' )
113- def step_impl (context , key , default_value ):
115+ def step_impl_float_evaluated_with_default (context , key , default_value ):
114116 context .flag_key = key
115117 context .default_value = default_value
116118 context .float_flag_details = context .client .get_float_details (key , default_value )
117119
118120
119121@when ('an object flag with key "{key}" is evaluated with a null default value' )
120- def step_impl (context , key ):
122+ def step_impl_obj_evaluated_with_default (context , key ):
121123 context .flag_key = key
122124 context .default_value = None
123125 context .object_flag_details = context .client .get_object_details (key , None )
124126
125127
126128@then ("the resolved integer value should be {expected_value:d}" )
127- def step_impl (context , expected_value ):
129+ def step_impl_resolved_int_should_be (context , expected_value ):
128130 assert expected_value == context .integer_flag_details .value
129131
130132
131133@then ("the resolved float value should be {expected_value:f}" )
132- def step_impl (context , expected_value ):
134+ def step_impl_resolved_bool_should_be (context , expected_value ):
133135 assert expected_value == context .float_flag_details .value
134136
135137
@@ -138,7 +140,7 @@ def step_impl(context, expected_value):
138140 'the resolved boolean details value should be "{expected_value}", the variant '
139141 'should be "{variant}", and the reason should be "{reason}"'
140142)
141- def step_impl (context , expected_value , variant , reason ):
143+ def step_impl_resolved_bool_should_be_with_reason (context , expected_value , variant , reason ):
142144 assert parse_boolean (expected_value ) == context .boolean_flag_details .value
143145 assert variant == context .boolean_flag_details .variant
144146 assert reason == context .boolean_flag_details .reason
@@ -148,7 +150,7 @@ def step_impl(context, expected_value, variant, reason):
148150 'the resolved string details value should be "{expected_value}", the variant '
149151 'should be "{variant}", and the reason should be "{reason}"'
150152)
151- def step_impl (context , expected_value , variant , reason ):
153+ def step_impl_resolved_string_should_be_with_reason (context , expected_value , variant , reason ):
152154 assert expected_value == context .string_flag_details .value
153155 assert variant == context .string_flag_details .variant
154156 assert reason == context .string_flag_details .reason
@@ -158,7 +160,7 @@ def step_impl(context, expected_value, variant, reason):
158160 'the resolved object value should be contain fields "{field1}", "{field2}", and '
159161 '"{field3}", with values "{val1}", "{val2}" and {val3}, respectively'
160162)
161- def step_impl (context , field1 , field2 , field3 , val1 , val2 , val3 ):
163+ def step_impl_resolved_obj_should_contain (context , field1 , field2 , field3 , val1 , val2 , val3 ):
162164 value = context .object_flag_details .value
163165 assert field1 in value
164166 assert field2 in value
@@ -169,7 +171,7 @@ def step_impl(context, field1, field2, field3, val1, val2, val3):
169171
170172
171173@then ('the resolved flag value is "{flag_value}" when the context is empty' )
172- def step_impl (context , flag_value ):
174+ def step_impl_resolved_is_with_empty_context (context , flag_value ):
173175 context .string_flag_details = context .client .get_boolean_details (
174176 context .flag_key , context .default_value
175177 )
@@ -180,13 +182,13 @@ def step_impl(context, flag_value):
180182 "the reason should indicate an error and the error code should indicate a missing "
181183 'flag with "{error_code}"'
182184)
183- def step_impl (context , error_code ):
185+ def step_impl_reason_should_indicate (context , error_code ):
184186 assert context .string_flag_details .reason == Reason .ERROR
185187 assert context .string_flag_details .error_code == ErrorCode [error_code ]
186188
187189
188190@then ("the default {flag_type} value should be returned" )
189- def step_impl (context , flag_type ):
191+ def step_impl_return_default (context , flag_type ):
190192 flag_details = getattr (context , f"{ flag_type } _flag_details" )
191193 assert context .default_value == flag_details .value
192194
@@ -195,15 +197,15 @@ def step_impl(context, flag_type):
195197 'a float flag with key "{key}" is evaluated with details and default value '
196198 "{default_value:f}"
197199)
198- def step_impl (context , key , default_value ):
200+ def step_impl_float_with_details (context , key , default_value ):
199201 context .float_flag_details = context .client .get_float_details (key , default_value )
200202
201203
202204@then (
203205 "the resolved float details value should be {expected_value:f}, the variant should "
204206 'be "{variant}", and the reason should be "{reason}"'
205207)
206- def step_impl (context , expected_value , variant , reason ):
208+ def step_impl_resolved_float_with_variant (context , expected_value , variant , reason ):
207209 assert expected_value == context .float_flag_details .value
208210 assert variant == context .float_flag_details .variant
209211 assert reason == context .float_flag_details .reason
@@ -212,15 +214,15 @@ def step_impl(context, expected_value, variant, reason):
212214@when (
213215 'an object flag with key "{key}" is evaluated with details and a null default value'
214216)
215- def step_impl (context , key ):
217+ def step_impl_eval_obj (context , key ):
216218 context .object_flag_details = context .client .get_object_details (key , None )
217219
218220
219221@then (
220222 'the resolved object details value should be contain fields "{field1}", "{field2}",'
221223 ' and "{field3}", with values "{val1}", "{val2}" and {val3}, respectively'
222224)
223- def step_impl (context , field1 , field2 , field3 , val1 , val2 , val3 ):
225+ def step_impl_eval_obj_with_fields (context , field1 , field2 , field3 , val1 , val2 , val3 ):
224226 value = context .object_flag_details .value
225227 assert field1 in value
226228 assert field2 in value
@@ -231,7 +233,7 @@ def step_impl(context, field1, field2, field3, val1, val2, val3):
231233
232234
233235@then ('the variant should be "{variant}", and the reason should be "{reason}"' )
234- def step_impl (context , variant , reason ):
236+ def step_impl_variant (context , variant , reason ):
235237 assert variant == context .object_flag_details .variant
236238 assert reason == context .object_flag_details .reason
237239
@@ -240,7 +242,7 @@ def step_impl(context, variant, reason):
240242 'context contains keys "{key1}", "{key2}", "{key3}", "{key4}" with values "{val1}",'
241243 ' "{val2}", {val3:d}, "{val4}"'
242244)
243- def step_impl (context , key1 , key2 , key3 , key4 , val1 , val2 , val3 , val4 ):
245+ def step_impl_context (context , key1 , key2 , key3 , key4 , val1 , val2 , val3 , val4 ):
244246 context .evaluation_context = EvaluationContext (
245247 None ,
246248 {
@@ -253,7 +255,7 @@ def step_impl(context, key1, key2, key3, key4, val1, val2, val3, val4):
253255
254256
255257@when ('a flag with key "{key}" is evaluated with default value "{default_value}"' )
256- def step_impl (context , key , default_value ):
258+ def step_impl_flag_with_key_and_default (context , key , default_value ):
257259 context .flag_key = key
258260 context .default_value = default_value
259261 context .string_flag_details = context .client .get_string_details (
@@ -262,15 +264,15 @@ def step_impl(context, key, default_value):
262264
263265
264266@then ('the resolved string response should be "{expected_value}"' )
265- def step_impl (context , expected_value ):
267+ def step_impl_reason (context , expected_value ):
266268 assert expected_value == context .string_flag_details .value
267269
268270
269271@when (
270272 'a non-existent string flag with key "{flag_key}" is evaluated with details and a '
271273 'default value "{default_value}"'
272274)
273- def step_impl (context , flag_key , default_value ):
275+ def step_impl_non_existing (context , flag_key , default_value ):
274276 context .flag_key = flag_key
275277 context .default_value = default_value
276278 context .string_flag_details = context .client .get_string_details (
@@ -282,7 +284,7 @@ def step_impl(context, flag_key, default_value):
282284 'a string flag with key "{flag_key}" is evaluated as an integer, with details and a'
283285 " default value {default_value:d}"
284286)
285- def step_impl (context , flag_key , default_value ):
287+ def step_impl_string_with_details (context , flag_key , default_value ):
286288 context .flag_key = flag_key
287289 context .default_value = default_value
288290 context .integer_flag_details = context .client .get_integer_details (
@@ -294,7 +296,7 @@ def step_impl(context, flag_key, default_value):
294296 "the reason should indicate an error and the error code should indicate a type "
295297 'mismatch with "{error_code}"'
296298)
297- def step_impl (context , error_code ):
299+ def step_impl_type_mismatch (context , error_code ):
298300 assert context .integer_flag_details .reason == Reason .ERROR
299301 assert context .integer_flag_details .error_code == ErrorCode [error_code ]
300302
@@ -306,17 +308,17 @@ def step_impl(context, error_code):
306308 'the flag\' s configuration with key "{key}" is updated to defaultVariant '
307309 '"{variant}"'
308310)
309- def step_impl (context , key , variant ):
311+ def step_impl_config_update (context , key , variant ):
310312 raise NotImplementedError ("Step definition not implemented yet" )
311313
312314
313315@given ("sleep for {duration} milliseconds" )
314- def step_impl (context , duration ):
315- raise NotImplementedError ( "Step definition not implemented yet" )
316+ def step_impl_sleep (context , duration ):
317+ sleep ( float ( duration ) * .001 )
316318
317319
318320@then ('the resolved string details reason should be "{reason}"' )
319- def step_impl (context , reason ):
321+ def step_impl_reason_should_be (context , reason ):
320322 raise NotImplementedError ("Step definition not implemented yet" )
321323
322324
0 commit comments