1
1
# flake8: noqa: F811
2
2
3
+ from time import sleep
4
+
3
5
from behave import given , then , when
4
6
5
7
from openfeature .api import get_client , set_provider
17
19
'the resolved {flag_type} details reason of flag with key "{key}" should be '
18
20
'"{reason}"'
19
21
)
20
- def step_impl (context , flag_type , key , expected_reason ):
22
+ def step_impl_resolved_should_be (context , flag_type , key , expected_reason ):
21
23
details : FlagEvaluationDetails = None
22
24
if flag_type == "boolean" :
23
25
details = context .boolean_flag_details
24
26
assert expected_reason == details .reason .value
25
27
26
28
27
29
@given ("a provider is registered with cache disabled" )
28
- def step_impl (context ):
30
+ def step_impl_provider_without_cache (context ):
31
+ set_provider (InMemoryProvider (IN_MEMORY_FLAGS ))
32
+ context .client = get_client ()
33
+
34
+
35
+ @given ("a provider is registered" )
36
+ def step_impl_provider (context ):
29
37
set_provider (InMemoryProvider (IN_MEMORY_FLAGS ))
30
38
context .client = get_client ()
31
39
@@ -34,7 +42,7 @@ def step_impl(context):
34
42
'a {flag_type} flag with key "{key}" is evaluated with details and default value '
35
43
'"{default_value}"'
36
44
)
37
- def step_impl (context , flag_type , key , default_value ):
45
+ def step_impl_evaluated_with_details (context , flag_type , key , default_value ):
38
46
context .client = get_client ()
39
47
if flag_type == "boolean" :
40
48
context .boolean_flag_details = context .client .get_boolean_details (
@@ -50,7 +58,9 @@ def step_impl(context, flag_type, key, default_value):
50
58
'a boolean flag with key "{key}" is evaluated with {eval_details} and default '
51
59
'value "{default_value}"'
52
60
)
53
- def step_impl (context , key , eval_details , default_value ):
61
+ def step_impl_bool_evaluated_with_details_and_default (
62
+ context , key , eval_details , default_value
63
+ ):
54
64
client : OpenFeatureClient = context .client
55
65
56
66
context .boolean_flag_details = client .get_boolean_details (key , default_value )
@@ -60,7 +70,7 @@ def step_impl(context, key, eval_details, default_value):
60
70
'a {flag_type} flag with key "{key}" is evaluated with default value '
61
71
'"{default_value}"'
62
72
)
63
- def step_impl (context , flag_type , key , default_value ):
73
+ def step_impl_evaluated_with_default (context , flag_type , key , default_value ):
64
74
client : OpenFeatureClient = context .client
65
75
66
76
if flag_type == "boolean" :
@@ -70,20 +80,20 @@ def step_impl(context, flag_type, key, default_value):
70
80
71
81
72
82
@then ('the resolved string value should be "{expected_value}"' )
73
- def step_impl (context , expected_value ):
83
+ def step_impl_resolved_string_should_be (context , expected_value ):
74
84
assert expected_value == context .string_flag_details .value
75
85
76
86
77
87
@then ('the resolved boolean value should be "{expected_value}"' )
78
- def step_impl (context , expected_value ):
88
+ def step_impl_resolved_bool_should_be (context , expected_value ):
79
89
assert parse_boolean (expected_value ) == context .boolean_flag_details .value
80
90
81
91
82
92
@when (
83
93
'an integer flag with key "{key}" is evaluated with details and default value '
84
94
"{default_value:d}"
85
95
)
86
- def step_impl (context , key , default_value ):
96
+ def step_impl_int_evaluated_with_details_and_default (context , key , default_value ):
87
97
context .flag_key = key
88
98
context .default_value = default_value
89
99
context .integer_flag_details = context .client .get_integer_details (
@@ -94,7 +104,7 @@ def step_impl(context, key, default_value):
94
104
@when (
95
105
'an integer flag with key "{key}" is evaluated with default value {default_value:d}'
96
106
)
97
- def step_impl (context , key , default_value ):
107
+ def step_impl_int_evaluated_with_default (context , key , default_value ):
98
108
context .flag_key = key
99
109
context .default_value = default_value
100
110
context .integer_flag_details = context .client .get_integer_details (
@@ -103,26 +113,26 @@ def step_impl(context, key, default_value):
103
113
104
114
105
115
@when ('a float flag with key "{key}" is evaluated with default value {default_value:f}' )
106
- def step_impl (context , key , default_value ):
116
+ def step_impl_float_evaluated_with_default (context , key , default_value ):
107
117
context .flag_key = key
108
118
context .default_value = default_value
109
119
context .float_flag_details = context .client .get_float_details (key , default_value )
110
120
111
121
112
122
@when ('an object flag with key "{key}" is evaluated with a null default value' )
113
- def step_impl (context , key ):
123
+ def step_impl_obj_evaluated_with_default (context , key ):
114
124
context .flag_key = key
115
125
context .default_value = None
116
126
context .object_flag_details = context .client .get_object_details (key , None )
117
127
118
128
119
129
@then ("the resolved integer value should be {expected_value:d}" )
120
- def step_impl (context , expected_value ):
130
+ def step_impl_resolved_int_should_be (context , expected_value ):
121
131
assert expected_value == context .integer_flag_details .value
122
132
123
133
124
134
@then ("the resolved float value should be {expected_value:f}" )
125
- def step_impl (context , expected_value ):
135
+ def step_impl_resolved_bool_should_be (context , expected_value ):
126
136
assert expected_value == context .float_flag_details .value
127
137
128
138
@@ -131,7 +141,9 @@ def step_impl(context, expected_value):
131
141
'the resolved boolean details value should be "{expected_value}", the variant '
132
142
'should be "{variant}", and the reason should be "{reason}"'
133
143
)
134
- def step_impl (context , expected_value , variant , reason ):
144
+ def step_impl_resolved_bool_should_be_with_reason (
145
+ context , expected_value , variant , reason
146
+ ):
135
147
assert parse_boolean (expected_value ) == context .boolean_flag_details .value
136
148
assert variant == context .boolean_flag_details .variant
137
149
assert reason == context .boolean_flag_details .reason
@@ -141,7 +153,9 @@ def step_impl(context, expected_value, variant, reason):
141
153
'the resolved string details value should be "{expected_value}", the variant '
142
154
'should be "{variant}", and the reason should be "{reason}"'
143
155
)
144
- def step_impl (context , expected_value , variant , reason ):
156
+ def step_impl_resolved_string_should_be_with_reason (
157
+ context , expected_value , variant , reason
158
+ ):
145
159
assert expected_value == context .string_flag_details .value
146
160
assert variant == context .string_flag_details .variant
147
161
assert reason == context .string_flag_details .reason
@@ -151,7 +165,9 @@ def step_impl(context, expected_value, variant, reason):
151
165
'the resolved object value should be contain fields "{field1}", "{field2}", and '
152
166
'"{field3}", with values "{val1}", "{val2}" and {val3}, respectively'
153
167
)
154
- def step_impl (context , field1 , field2 , field3 , val1 , val2 , val3 ):
168
+ def step_impl_resolved_obj_should_contain (
169
+ context , field1 , field2 , field3 , val1 , val2 , val3
170
+ ):
155
171
value = context .object_flag_details .value
156
172
assert field1 in value
157
173
assert field2 in value
@@ -162,7 +178,7 @@ def step_impl(context, field1, field2, field3, val1, val2, val3):
162
178
163
179
164
180
@then ('the resolved flag value is "{flag_value}" when the context is empty' )
165
- def step_impl (context , flag_value ):
181
+ def step_impl_resolved_is_with_empty_context (context , flag_value ):
166
182
context .string_flag_details = context .client .get_boolean_details (
167
183
context .flag_key , context .default_value
168
184
)
@@ -173,13 +189,13 @@ def step_impl(context, flag_value):
173
189
"the reason should indicate an error and the error code should indicate a missing "
174
190
'flag with "{error_code}"'
175
191
)
176
- def step_impl (context , error_code ):
192
+ def step_impl_reason_should_indicate (context , error_code ):
177
193
assert context .string_flag_details .reason == Reason .ERROR
178
194
assert context .string_flag_details .error_code == ErrorCode [error_code ]
179
195
180
196
181
197
@then ("the default {flag_type} value should be returned" )
182
- def step_impl (context , flag_type ):
198
+ def step_impl_return_default (context , flag_type ):
183
199
flag_details = getattr (context , f"{ flag_type } _flag_details" )
184
200
assert context .default_value == flag_details .value
185
201
@@ -188,15 +204,15 @@ def step_impl(context, flag_type):
188
204
'a float flag with key "{key}" is evaluated with details and default value '
189
205
"{default_value:f}"
190
206
)
191
- def step_impl (context , key , default_value ):
207
+ def step_impl_float_with_details (context , key , default_value ):
192
208
context .float_flag_details = context .client .get_float_details (key , default_value )
193
209
194
210
195
211
@then (
196
212
"the resolved float details value should be {expected_value:f}, the variant should "
197
213
'be "{variant}", and the reason should be "{reason}"'
198
214
)
199
- def step_impl (context , expected_value , variant , reason ):
215
+ def step_impl_resolved_float_with_variant (context , expected_value , variant , reason ):
200
216
assert expected_value == context .float_flag_details .value
201
217
assert variant == context .float_flag_details .variant
202
218
assert reason == context .float_flag_details .reason
@@ -205,15 +221,15 @@ def step_impl(context, expected_value, variant, reason):
205
221
@when (
206
222
'an object flag with key "{key}" is evaluated with details and a null default value'
207
223
)
208
- def step_impl (context , key ):
224
+ def step_impl_eval_obj (context , key ):
209
225
context .object_flag_details = context .client .get_object_details (key , None )
210
226
211
227
212
228
@then (
213
229
'the resolved object details value should be contain fields "{field1}", "{field2}",'
214
230
' and "{field3}", with values "{val1}", "{val2}" and {val3}, respectively'
215
231
)
216
- def step_impl (context , field1 , field2 , field3 , val1 , val2 , val3 ):
232
+ def step_impl_eval_obj_with_fields (context , field1 , field2 , field3 , val1 , val2 , val3 ):
217
233
value = context .object_flag_details .value
218
234
assert field1 in value
219
235
assert field2 in value
@@ -224,7 +240,7 @@ def step_impl(context, field1, field2, field3, val1, val2, val3):
224
240
225
241
226
242
@then ('the variant should be "{variant}", and the reason should be "{reason}"' )
227
- def step_impl (context , variant , reason ):
243
+ def step_impl_variant (context , variant , reason ):
228
244
assert variant == context .object_flag_details .variant
229
245
assert reason == context .object_flag_details .reason
230
246
@@ -233,7 +249,7 @@ def step_impl(context, variant, reason):
233
249
'context contains keys "{key1}", "{key2}", "{key3}", "{key4}" with values "{val1}",'
234
250
' "{val2}", {val3:d}, "{val4}"'
235
251
)
236
- def step_impl (context , key1 , key2 , key3 , key4 , val1 , val2 , val3 , val4 ):
252
+ def step_impl_context (context , key1 , key2 , key3 , key4 , val1 , val2 , val3 , val4 ):
237
253
context .evaluation_context = EvaluationContext (
238
254
None ,
239
255
{
@@ -246,7 +262,7 @@ def step_impl(context, key1, key2, key3, key4, val1, val2, val3, val4):
246
262
247
263
248
264
@when ('a flag with key "{key}" is evaluated with default value "{default_value}"' )
249
- def step_impl (context , key , default_value ):
265
+ def step_impl_flag_with_key_and_default (context , key , default_value ):
250
266
context .flag_key = key
251
267
context .default_value = default_value
252
268
context .string_flag_details = context .client .get_string_details (
@@ -255,15 +271,15 @@ def step_impl(context, key, default_value):
255
271
256
272
257
273
@then ('the resolved string response should be "{expected_value}"' )
258
- def step_impl (context , expected_value ):
274
+ def step_impl_reason (context , expected_value ):
259
275
assert expected_value == context .string_flag_details .value
260
276
261
277
262
278
@when (
263
279
'a non-existent string flag with key "{flag_key}" is evaluated with details and a '
264
280
'default value "{default_value}"'
265
281
)
266
- def step_impl (context , flag_key , default_value ):
282
+ def step_impl_non_existing (context , flag_key , default_value ):
267
283
context .flag_key = flag_key
268
284
context .default_value = default_value
269
285
context .string_flag_details = context .client .get_string_details (
@@ -275,7 +291,7 @@ def step_impl(context, flag_key, default_value):
275
291
'a string flag with key "{flag_key}" is evaluated as an integer, with details and a'
276
292
" default value {default_value:d}"
277
293
)
278
- def step_impl (context , flag_key , default_value ):
294
+ def step_impl_string_with_details (context , flag_key , default_value ):
279
295
context .flag_key = flag_key
280
296
context .default_value = default_value
281
297
context .integer_flag_details = context .client .get_integer_details (
@@ -287,7 +303,7 @@ def step_impl(context, flag_key, default_value):
287
303
"the reason should indicate an error and the error code should indicate a type "
288
304
'mismatch with "{error_code}"'
289
305
)
290
- def step_impl (context , error_code ):
306
+ def step_impl_type_mismatch (context , error_code ):
291
307
assert context .integer_flag_details .reason == Reason .ERROR
292
308
assert context .integer_flag_details .error_code == ErrorCode [error_code ]
293
309
@@ -299,17 +315,17 @@ def step_impl(context, error_code):
299
315
'the flag\' s configuration with key "{key}" is updated to defaultVariant '
300
316
'"{variant}"'
301
317
)
302
- def step_impl (context , key , variant ):
318
+ def step_impl_config_update (context , key , variant ):
303
319
raise NotImplementedError ("Step definition not implemented yet" )
304
320
305
321
306
322
@given ("sleep for {duration} milliseconds" )
307
- def step_impl (context , duration ):
308
- raise NotImplementedError ( "Step definition not implemented yet" )
323
+ def step_impl_sleep (context , duration ):
324
+ sleep ( float ( duration ) * 0.001 )
309
325
310
326
311
327
@then ('the resolved string details reason should be "{reason}"' )
312
- def step_impl (context , reason ):
328
+ def step_impl_reason_should_be (context , reason ):
313
329
raise NotImplementedError ("Step definition not implemented yet" )
314
330
315
331
0 commit comments