From 2bfffe67e60e73480b4e0ad996a546d069896a70 Mon Sep 17 00:00:00 2001 From: Cole Bailey Date: Sat, 27 Apr 2024 19:20:40 +0200 Subject: [PATCH] fix: float/int type casting Signed-off-by: Cole Bailey --- .../provider/flagd/resolvers/in_process.py | 10 ++++++-- ..._grpc_events.py => test_inprocess_grpc.py} | 23 +++---------------- .../grpc/test_inprocess_grpc_evals.py | 6 ----- .../grpc/test_inprocess_grpc_zero_evals.py | 23 ------------------- 4 files changed, 11 insertions(+), 51 deletions(-) rename providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/{test_inprocess_grpc_events.py => test_inprocess_grpc.py} (72%) delete mode 100644 providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_evals.py delete mode 100644 providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_zero_evals.py diff --git a/providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/in_process.py b/providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/in_process.py index e292dfa..b3094b5 100644 --- a/providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/in_process.py +++ b/providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/in_process.py @@ -64,7 +64,10 @@ def resolve_float_details( default_value: float, evaluation_context: typing.Optional[EvaluationContext] = None, ) -> FlagResolutionDetails[float]: - return self._resolve(key, default_value, evaluation_context) + result = self._resolve(key, default_value, evaluation_context) + if not isinstance(result.value, float): + result.value = float(result.value) + return result def resolve_integer_details( self, @@ -72,7 +75,10 @@ def resolve_integer_details( default_value: int, evaluation_context: typing.Optional[EvaluationContext] = None, ) -> FlagResolutionDetails[int]: - return self._resolve(key, default_value, evaluation_context) + result = self._resolve(key, default_value, evaluation_context) + if not isinstance(result.value, int): + result.value = int(result.value) + return result def resolve_object_details( self, diff --git a/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_events.py b/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc.py similarity index 72% rename from providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_events.py rename to providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc.py index 5f038da..96a33f0 100644 --- a/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_events.py +++ b/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc.py @@ -1,23 +1,14 @@ -import logging import time import pytest -from pytest_bdd import parsers, scenario, then, when +from pytest_bdd import parsers, scenarios, then, when from openfeature.client import OpenFeatureClient, ProviderEvent GHERKIN_FOLDER = "../../../../test-harness/gherkin/" - -@scenario(f"{GHERKIN_FOLDER}flagd.feature", "Provider ready event") -def test_ready_event(caplog): - """Provider ready event""" - caplog.set_level(logging.DEBUG) - - -@scenario(f"{GHERKIN_FOLDER}flagd.feature", "Flag change event") -def test_change_event(): - """Flag change event""" +scenarios(f"{GHERKIN_FOLDER}flagd-json-evaluator.feature") +scenarios(f"{GHERKIN_FOLDER}flagd.feature") @pytest.fixture @@ -71,14 +62,6 @@ def modify_flag(key): pass -# def modify_flag(flag_file, key): -# time.sleep(0.1) # guard against race condition -# with open("test-harness/flags/changing-flag-foo.json") as src_file: -# contents = src_file.read() -# with open(flag_file, "w") as f: -# f.write(contents) - - @then(parsers.cfparse('the event details must indicate "{key}" was altered')) def assert_flag_changed(handles, key): handle = None diff --git a/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_evals.py b/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_evals.py deleted file mode 100644 index 926c219..0000000 --- a/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_evals.py +++ /dev/null @@ -1,6 +0,0 @@ -from pytest_bdd import scenarios - -GHERKIN_FOLDER = "../../../../test-harness/gherkin/" - -scenarios(f"{GHERKIN_FOLDER}flagd-json-evaluator.feature") -scenarios(f"{GHERKIN_FOLDER}flagd.feature") diff --git a/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_zero_evals.py b/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_zero_evals.py deleted file mode 100644 index 444548d..0000000 --- a/providers/openfeature-provider-flagd/tests/e2e/inprocess/grpc/test_inprocess_grpc_zero_evals.py +++ /dev/null @@ -1,23 +0,0 @@ -# from pytest_bdd import scenario - -# GHERKIN_FOLDER = "../../../../test-harness/gherkin/" - - -# @scenario(f"{GHERKIN_FOLDER}flagd.feature", "Resolves boolean zero value") -# def test_eval_boolean(): -# """Resolve boolean zero value""" - - -# @scenario(f"{GHERKIN_FOLDER}flagd.feature", "Resolves string zero value") -# def test_eval_string(): -# """Resolve string zero value""" - - -# @scenario(f"{GHERKIN_FOLDER}flagd.feature", "Resolves integer zero value") -# def test_eval_integer(): -# """Resolve integer zero value""" - - -# @scenario(f"{GHERKIN_FOLDER}flagd.feature", "Resolves float zero value") -# def test_eval_float(): -# """Resolve float zero value"""