Skip to content

Commit 192f7c4

Browse files
chrfwowgruebel
andauthored
feat: Update test harness (copy test files) #1467 (#416)
* feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! feat: Update test harness (copy test files) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> --------- Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> Co-authored-by: Anton Grübel <anton.gruebel@gmail.com>
1 parent b69e81a commit 192f7c4

File tree

4 files changed

+52
-40
lines changed

4 files changed

+52
-40
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "test-harness"]
2-
path = test-harness
3-
url = https://github.com/open-feature/test-harness.git
41
[submodule "spec"]
52
path = spec
63
url = https://github.com/open-feature/spec.git

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ cov = [
4848
"cov-report",
4949
]
5050
e2e = [
51-
"git submodule update --init",
52-
"cp test-harness/features/evaluation.feature tests/features/",
51+
"git submodule add --force https://github.com/open-feature/spec.git spec",
52+
"cp -r spec/specification/assets/gherkin/evaluation.feature tests/features/",
5353
"behave tests/features/",
5454
"rm tests/features/*.feature",
5555
]

test-harness

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/features/steps/steps.py

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# flake8: noqa: F811
22

3+
from time import sleep
4+
35
from behave import given, then, when
46

57
from openfeature.api import get_client, set_provider
@@ -17,15 +19,21 @@
1719
'the resolved {flag_type} details reason of flag with key "{key}" should be '
1820
'"{reason}"'
1921
)
20-
def step_impl(context, flag_type, key, expected_reason):
22+
def step_impl_resolved_should_be(context, flag_type, key, expected_reason):
2123
details: FlagEvaluationDetails = None
2224
if flag_type == "boolean":
2325
details = context.boolean_flag_details
2426
assert expected_reason == details.reason.value
2527

2628

2729
@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):
2937
set_provider(InMemoryProvider(IN_MEMORY_FLAGS))
3038
context.client = get_client()
3139

@@ -34,7 +42,7 @@ def step_impl(context):
3442
'a {flag_type} flag with key "{key}" is evaluated with details and default value '
3543
'"{default_value}"'
3644
)
37-
def step_impl(context, flag_type, key, default_value):
45+
def step_impl_evaluated_with_details(context, flag_type, key, default_value):
3846
context.client = get_client()
3947
if flag_type == "boolean":
4048
context.boolean_flag_details = context.client.get_boolean_details(
@@ -50,7 +58,9 @@ def step_impl(context, flag_type, key, default_value):
5058
'a boolean flag with key "{key}" is evaluated with {eval_details} and default '
5159
'value "{default_value}"'
5260
)
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+
):
5464
client: OpenFeatureClient = context.client
5565

5666
context.boolean_flag_details = client.get_boolean_details(key, default_value)
@@ -60,7 +70,7 @@ def step_impl(context, key, eval_details, default_value):
6070
'a {flag_type} flag with key "{key}" is evaluated with default value '
6171
'"{default_value}"'
6272
)
63-
def step_impl(context, flag_type, key, default_value):
73+
def step_impl_evaluated_with_default(context, flag_type, key, default_value):
6474
client: OpenFeatureClient = context.client
6575

6676
if flag_type == "boolean":
@@ -70,20 +80,20 @@ def step_impl(context, flag_type, key, default_value):
7080

7181

7282
@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):
7484
assert expected_value == context.string_flag_details.value
7585

7686

7787
@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):
7989
assert parse_boolean(expected_value) == context.boolean_flag_details.value
8090

8191

8292
@when(
8393
'an integer flag with key "{key}" is evaluated with details and default value '
8494
"{default_value:d}"
8595
)
86-
def step_impl(context, key, default_value):
96+
def step_impl_int_evaluated_with_details_and_default(context, key, default_value):
8797
context.flag_key = key
8898
context.default_value = default_value
8999
context.integer_flag_details = context.client.get_integer_details(
@@ -94,7 +104,7 @@ def step_impl(context, key, default_value):
94104
@when(
95105
'an integer flag with key "{key}" is evaluated with default value {default_value:d}'
96106
)
97-
def step_impl(context, key, default_value):
107+
def step_impl_int_evaluated_with_default(context, key, default_value):
98108
context.flag_key = key
99109
context.default_value = default_value
100110
context.integer_flag_details = context.client.get_integer_details(
@@ -103,26 +113,26 @@ def step_impl(context, key, default_value):
103113

104114

105115
@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):
107117
context.flag_key = key
108118
context.default_value = default_value
109119
context.float_flag_details = context.client.get_float_details(key, default_value)
110120

111121

112122
@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):
114124
context.flag_key = key
115125
context.default_value = None
116126
context.object_flag_details = context.client.get_object_details(key, None)
117127

118128

119129
@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):
121131
assert expected_value == context.integer_flag_details.value
122132

123133

124134
@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):
126136
assert expected_value == context.float_flag_details.value
127137

128138

@@ -131,7 +141,9 @@ def step_impl(context, expected_value):
131141
'the resolved boolean details value should be "{expected_value}", the variant '
132142
'should be "{variant}", and the reason should be "{reason}"'
133143
)
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+
):
135147
assert parse_boolean(expected_value) == context.boolean_flag_details.value
136148
assert variant == context.boolean_flag_details.variant
137149
assert reason == context.boolean_flag_details.reason
@@ -141,7 +153,9 @@ def step_impl(context, expected_value, variant, reason):
141153
'the resolved string details value should be "{expected_value}", the variant '
142154
'should be "{variant}", and the reason should be "{reason}"'
143155
)
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+
):
145159
assert expected_value == context.string_flag_details.value
146160
assert variant == context.string_flag_details.variant
147161
assert reason == context.string_flag_details.reason
@@ -151,7 +165,9 @@ def step_impl(context, expected_value, variant, reason):
151165
'the resolved object value should be contain fields "{field1}", "{field2}", and '
152166
'"{field3}", with values "{val1}", "{val2}" and {val3}, respectively'
153167
)
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+
):
155171
value = context.object_flag_details.value
156172
assert field1 in value
157173
assert field2 in value
@@ -162,7 +178,7 @@ def step_impl(context, field1, field2, field3, val1, val2, val3):
162178

163179

164180
@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):
166182
context.string_flag_details = context.client.get_boolean_details(
167183
context.flag_key, context.default_value
168184
)
@@ -173,13 +189,13 @@ def step_impl(context, flag_value):
173189
"the reason should indicate an error and the error code should indicate a missing "
174190
'flag with "{error_code}"'
175191
)
176-
def step_impl(context, error_code):
192+
def step_impl_reason_should_indicate(context, error_code):
177193
assert context.string_flag_details.reason == Reason.ERROR
178194
assert context.string_flag_details.error_code == ErrorCode[error_code]
179195

180196

181197
@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):
183199
flag_details = getattr(context, f"{flag_type}_flag_details")
184200
assert context.default_value == flag_details.value
185201

@@ -188,15 +204,15 @@ def step_impl(context, flag_type):
188204
'a float flag with key "{key}" is evaluated with details and default value '
189205
"{default_value:f}"
190206
)
191-
def step_impl(context, key, default_value):
207+
def step_impl_float_with_details(context, key, default_value):
192208
context.float_flag_details = context.client.get_float_details(key, default_value)
193209

194210

195211
@then(
196212
"the resolved float details value should be {expected_value:f}, the variant should "
197213
'be "{variant}", and the reason should be "{reason}"'
198214
)
199-
def step_impl(context, expected_value, variant, reason):
215+
def step_impl_resolved_float_with_variant(context, expected_value, variant, reason):
200216
assert expected_value == context.float_flag_details.value
201217
assert variant == context.float_flag_details.variant
202218
assert reason == context.float_flag_details.reason
@@ -205,15 +221,15 @@ def step_impl(context, expected_value, variant, reason):
205221
@when(
206222
'an object flag with key "{key}" is evaluated with details and a null default value'
207223
)
208-
def step_impl(context, key):
224+
def step_impl_eval_obj(context, key):
209225
context.object_flag_details = context.client.get_object_details(key, None)
210226

211227

212228
@then(
213229
'the resolved object details value should be contain fields "{field1}", "{field2}",'
214230
' and "{field3}", with values "{val1}", "{val2}" and {val3}, respectively'
215231
)
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):
217233
value = context.object_flag_details.value
218234
assert field1 in value
219235
assert field2 in value
@@ -224,7 +240,7 @@ def step_impl(context, field1, field2, field3, val1, val2, val3):
224240

225241

226242
@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):
228244
assert variant == context.object_flag_details.variant
229245
assert reason == context.object_flag_details.reason
230246

@@ -233,7 +249,7 @@ def step_impl(context, variant, reason):
233249
'context contains keys "{key1}", "{key2}", "{key3}", "{key4}" with values "{val1}",'
234250
' "{val2}", {val3:d}, "{val4}"'
235251
)
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):
237253
context.evaluation_context = EvaluationContext(
238254
None,
239255
{
@@ -246,7 +262,7 @@ def step_impl(context, key1, key2, key3, key4, val1, val2, val3, val4):
246262

247263

248264
@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):
250266
context.flag_key = key
251267
context.default_value = default_value
252268
context.string_flag_details = context.client.get_string_details(
@@ -255,15 +271,15 @@ def step_impl(context, key, default_value):
255271

256272

257273
@then('the resolved string response should be "{expected_value}"')
258-
def step_impl(context, expected_value):
274+
def step_impl_reason(context, expected_value):
259275
assert expected_value == context.string_flag_details.value
260276

261277

262278
@when(
263279
'a non-existent string flag with key "{flag_key}" is evaluated with details and a '
264280
'default value "{default_value}"'
265281
)
266-
def step_impl(context, flag_key, default_value):
282+
def step_impl_non_existing(context, flag_key, default_value):
267283
context.flag_key = flag_key
268284
context.default_value = default_value
269285
context.string_flag_details = context.client.get_string_details(
@@ -275,7 +291,7 @@ def step_impl(context, flag_key, default_value):
275291
'a string flag with key "{flag_key}" is evaluated as an integer, with details and a'
276292
" default value {default_value:d}"
277293
)
278-
def step_impl(context, flag_key, default_value):
294+
def step_impl_string_with_details(context, flag_key, default_value):
279295
context.flag_key = flag_key
280296
context.default_value = default_value
281297
context.integer_flag_details = context.client.get_integer_details(
@@ -287,7 +303,7 @@ def step_impl(context, flag_key, default_value):
287303
"the reason should indicate an error and the error code should indicate a type "
288304
'mismatch with "{error_code}"'
289305
)
290-
def step_impl(context, error_code):
306+
def step_impl_type_mismatch(context, error_code):
291307
assert context.integer_flag_details.reason == Reason.ERROR
292308
assert context.integer_flag_details.error_code == ErrorCode[error_code]
293309

@@ -299,17 +315,17 @@ def step_impl(context, error_code):
299315
'the flag\'s configuration with key "{key}" is updated to defaultVariant '
300316
'"{variant}"'
301317
)
302-
def step_impl(context, key, variant):
318+
def step_impl_config_update(context, key, variant):
303319
raise NotImplementedError("Step definition not implemented yet")
304320

305321

306322
@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)
309325

310326

311327
@then('the resolved string details reason should be "{reason}"')
312-
def step_impl(context, reason):
328+
def step_impl_reason_should_be(context, reason):
313329
raise NotImplementedError("Step definition not implemented yet")
314330

315331

0 commit comments

Comments
 (0)