Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "tests/engine/engine-test-data"]
path = tests/engine/engine-test-data
url = https://github.com/Flagsmith/engine-test-data.git
branch = v3.6.0
172 changes: 171 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pre-commit = { version = "^4.2.0", python = ">=3.9,<4" }
responses = "^0.24.1"
types-requests = "^2.32"
pyfakefs = "^5.9.2"
pyjson5 = "^2.0.0"

[tool.mypy]
exclude = ["example/*"]
Expand Down
Empty file added tests/engine/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/engine/engine-test-data
Submodule engine-test-data added at 930793
45 changes: 45 additions & 0 deletions tests/engine/test_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import typing
from itertools import chain
from pathlib import Path

import pyjson5
import pytest
from _pytest.mark import ParameterSet
from flag_engine.context.types import EvaluationContext
from flag_engine.engine import get_evaluation_result
from flag_engine.result.types import EvaluationResult

TEST_CASES_PATH = Path(__file__).parent / "engine-test-data/test_cases"


def _extract_test_cases(
test_cases_dir_path: Path,
) -> typing.Iterable[ParameterSet]:
for file_path in chain(
test_cases_dir_path.glob("*.json"),
test_cases_dir_path.glob("*.jsonc"),
):
test_data = pyjson5.loads(file_path.read_text())
yield pytest.param(
test_data["context"],
test_data["result"],
id=file_path.stem,
)


TEST_CASES = sorted(
_extract_test_cases(TEST_CASES_PATH),
key=lambda param: str(param.id),
)


@pytest.mark.parametrize(
"context, expected_result",
TEST_CASES,
)
def test_engine(
context: EvaluationContext,
expected_result: EvaluationResult,
) -> None:
result = get_evaluation_result(context)
assert result == expected_result
Loading