Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/refactor_and_switch_to_single_client
Browse files Browse the repository at this point in the history
leohoare authored Jan 23, 2025
2 parents 5d34cd8 + b69e81a commit dfdce36
Showing 7 changed files with 89 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ jobs:

- if: matrix.python-version == '3.11'
name: Upload coverage to Codecov
uses: codecov/codecov-action@v5.1.2
uses: codecov/codecov-action@v5.2.0
with:
flags: unittests # optional
name: coverage # optional
13 changes: 7 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -37,12 +37,14 @@ jobs:
# IMPORTANT: this permission is mandatory for trusted publishing to pypi
id-token: write
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}
container:
image: "python:3.13"
if: ${{ fromJSON(needs.release-please.outputs.release_created || false) }}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5
with:
python-version: '3.13'

- name: Upgrade pip
run: pip install --upgrade pip
@@ -54,5 +56,4 @@ jobs:
run: hatch build

- name: Publish a Python distribution to PyPI
# pinning till fixed https://github.com/pypa/gh-action-pypi-publish/issues/300
uses: pypa/gh-action-pypi-publish@release/v1.11
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "test-harness"]
path = test-harness
url = https://github.com/open-feature/test-harness.git
[submodule "spec"]
path = spec
url = https://github.com/open-feature/spec.git
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default_stages: [commit]
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.9.2
hooks:
- id: ruff
args: [--fix]
12 changes: 12 additions & 0 deletions tests/features/data.py
Original file line number Diff line number Diff line change
@@ -69,4 +69,16 @@ def context_func(flag: InMemoryFlag, evaluation_context: EvaluationContext):
variants={"one": "uno", "two": "dos"},
default_variant="one",
),
"metadata-flag": InMemoryFlag(
state=InMemoryFlag.State.ENABLED,
default_variant="on",
variants={"on": True, "off": False},
context_evaluator=None,
flag_metadata={
"string": "1.0.2",
"integer": 2,
"float": 0.1,
"boolean": True,
},
),
}
22 changes: 22 additions & 0 deletions tests/features/steps/flag_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from behave import given, when


@given('a {flag_type}-flag with key "{flag_key}" and a default value "{default_value}"')
def step_impl_flag(context, flag_type: str, flag_key, default_value):
context.flag = (flag_type, flag_key, default_value)


@when("the flag was evaluated with details")
def step_impl_evaluation(context):
client = context.client
flag_type, key, default_value = context.flag
if flag_type.lower() == "string":
context.evaluation = client.get_string_details(key, default_value)
elif flag_type.lower() == "boolean":
context.evaluation = client.get_boolean_details(key, default_value)
elif flag_type.lower() == "object":
context.evaluation = client.get_object_details(key, default_value)
elif flag_type.lower() == "float":
context.evaluation = client.get_float_details(key, default_value)
elif flag_type.lower() == "integer":
context.evaluation = client.get_integer_details(key, default_value)
43 changes: 43 additions & 0 deletions tests/features/steps/metadata_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from behave import given, then

from openfeature.api import get_client, set_provider
from openfeature.provider.in_memory_provider import InMemoryProvider
from tests.features.data import IN_MEMORY_FLAGS


@given("a stable provider")
def step_impl_stable_provider(context):
set_provider(InMemoryProvider(IN_MEMORY_FLAGS))
context.client = get_client()


@then('the resolved metadata value "{key}" should be "{value}"')
def step_impl_check_metadata(context, key, value):
assert context.evaluation.flag_metadata[key] == value


@then("the resolved metadata is empty")
def step_impl_empty_metadata(context):
assert not context.evaluation.flag_metadata


@then("the resolved metadata should contain")
def step_impl_metadata_contains(context):
for row in context.table:
key, metadata_type, value = row

assert context.evaluation.flag_metadata[
key
] == convert_value_from_metadata_type(value, metadata_type)


def convert_value_from_metadata_type(value, metadata_type):
if value == "None":
return None
if metadata_type.lower() == "boolean":
return bool(value)
elif metadata_type.lower() == "integer":
return int(value)
elif metadata_type.lower() == "float":
return float(value)
return value

0 comments on commit dfdce36

Please sign in to comment.