Skip to content

Commit e552e4c

Browse files
committed
ci: integrate-engine-tests-data
1 parent 14fd76e commit e552e4c

7 files changed

Lines changed: 224 additions & 1 deletion

File tree

.github/workflows/pytest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
uses: actions/checkout@v4
2121
with:
2222
fetch-depth: 0
23+
submodules: true
2324

2425
- name: Set up Python ${{ matrix.python-version }}
2526
uses: actions/setup-python@v5

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "tests/engine/engine-test-data"]
2+
path = tests/engine/engine-test-data
3+
url = https://github.com/Flagsmith/engine-test-data.git
4+
branch = v3.6.0

poetry.lock

Lines changed: 171 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pre-commit = { version = "^4.2.0", python = ">=3.9,<4" }
3030
responses = "^0.24.1"
3131
types-requests = "^2.32"
3232
pyfakefs = "^5.9.2"
33+
pyjson5 = "^2.0.0"
3334

3435
[tool.mypy]
3536
exclude = ["example/*"]

tests/engine/__init__.py

Whitespace-only changes.

tests/engine/engine-test-data

Submodule engine-test-data added at 9307930

tests/engine/test_engine.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import typing
2+
from itertools import chain
3+
from pathlib import Path
4+
5+
import pyjson5
6+
import pytest
7+
from _pytest.mark import ParameterSet
8+
9+
from flag_engine.context.types import EvaluationContext
10+
from flag_engine.engine import get_evaluation_result
11+
from flag_engine.result.types import EvaluationResult
12+
13+
TEST_CASES_PATH = Path(__file__).parent / "engine-test-data/test_cases"
14+
15+
16+
def _extract_test_cases(
17+
test_cases_dir_path: Path,
18+
) -> typing.Iterable[ParameterSet]:
19+
for file_path in chain(
20+
test_cases_dir_path.glob("*.json"),
21+
test_cases_dir_path.glob("*.jsonc"),
22+
):
23+
test_data = pyjson5.loads(file_path.read_text())
24+
yield pytest.param(
25+
test_data["context"],
26+
test_data["result"],
27+
id=file_path.stem,
28+
)
29+
30+
31+
TEST_CASES = sorted(
32+
_extract_test_cases(TEST_CASES_PATH),
33+
key=lambda param: str(param.id),
34+
)
35+
36+
37+
@pytest.mark.parametrize(
38+
"context, expected_result",
39+
TEST_CASES,
40+
)
41+
def test_engine(
42+
context: EvaluationContext,
43+
expected_result: EvaluationResult,
44+
) -> None:
45+
result = get_evaluation_result(context)
46+
assert result == expected_result

0 commit comments

Comments
 (0)