Skip to content

[Resolver] Basic Logic for Filtering & Sorting added #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 18, 2025
Merged
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
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ maintainers = [
]
dependencies = [
"importlib-metadata; python_version < '3.10'",
"platformdirs>=4.3,<5.0",
"tomli; python_version < '3.11'",
"typing-extensions; python_version < '3.11'",
]

Expand All @@ -44,16 +46,18 @@ dev = [
"ruff>=0.10,<1.0",
]
test = [
"deepdiff>=8.0,<9.0",
"jsondiff>=2.2,<2.3",
"hypothesis>=6.0.0,<7",
"parameterized>=0.9.0,<0.10",
"pytest>=8.0.0,<9.0.0",
"pytest-cov>=5.0.0,<6.0.0",
"pytest-dotenv>=0.5.0,<1.0.0",
"pytest-env>=1.1.3,<2.0.0",
"pytest-mock>=3.14.0,<4.0.0",
"pytest-runner>=6.0.0,<7.0.0",
"pytest-ordering>=0.6,<1.0.0",
"parameterized>=0.9.0,<0.10",
"tomli_w>=1.2,<1.3",
]

[project.scripts]
Expand Down
107 changes: 107 additions & 0 deletions tests/models/test_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from __future__ import annotations

import pytest
from hypothesis import given
from hypothesis import strategies as st

from variantlib.constants import VALIDATION_FEATURE_REGEX
from variantlib.constants import VALIDATION_NAMESPACE_REGEX
from variantlib.constants import VALIDATION_VALUE_REGEX
from variantlib.models.configuration import VariantConfiguration
from variantlib.models.variant import VariantFeature
from variantlib.models.variant import VariantProperty


def test_default_configuration():
config = VariantConfiguration.default()
assert config.namespaces_priority == []
assert config.features_priority == []
assert config.property_priority == []


@pytest.mark.parametrize(
"config_params",
[
{
"namespaces": ["OmniCorp"],
"features": [],
"properties": [],
},
{
"namespaces": ["OmniCorp"],
"features": ["OmniCorp::custom_feat"],
"properties": ["OmniCorp::custom_feat::secret_value"],
},
{
"namespaces": ["OmniCorp", "AcmeCorp"],
"features": ["OmniCorp::custom_feat", "AcmeCorp :: custom_feat"],
"properties": [
"OmniCorp :: custom_featA :: secret_value",
"OmniCorp :: custom_featB:: secret_value",
"AcmeCorp::custom_feat::secret_value",
],
},
],
)
def test_from_toml_config(config_params: dict[str, list[str]]):
_ = VariantConfiguration.from_toml_config(
namespaces_priority=config_params["namespaces"],
features_priority=config_params["features"],
property_priority=config_params["properties"],
)


@given(st.lists(st.from_regex(VALIDATION_NAMESPACE_REGEX)))
def test_namespaces_priority_validation(namespaces: list[str]):
config = VariantConfiguration(namespaces_priority=namespaces)
assert config.namespaces_priority == namespaces


@given(
st.lists(st.from_regex(VALIDATION_NAMESPACE_REGEX)),
st.lists(
st.builds(
VariantFeature,
namespace=st.just("OmniCorp"),
feature=st.from_regex(VALIDATION_FEATURE_REGEX),
)
),
)
def test_features_priority_validation(
namespaces: list[str], features: list[VariantFeature]
):
config = VariantConfiguration(
namespaces_priority=namespaces, features_priority=features
)
assert config.features_priority == features


@given(
st.lists(st.from_regex(VALIDATION_NAMESPACE_REGEX)),
st.lists(
st.builds(
VariantFeature,
namespace=st.from_regex(VALIDATION_NAMESPACE_REGEX),
feature=st.from_regex(VALIDATION_FEATURE_REGEX),
)
),
st.lists(
st.builds(
VariantProperty,
namespace=st.from_regex(VALIDATION_NAMESPACE_REGEX),
feature=st.from_regex(VALIDATION_FEATURE_REGEX),
value=st.from_regex(VALIDATION_VALUE_REGEX),
)
),
)
def test_property_priority_validation(
namespaces: list[str],
features: list[VariantFeature],
properties: list[VariantProperty],
):
config = VariantConfiguration(
namespaces_priority=namespaces,
features_priority=features,
property_priority=properties,
)
assert config.property_priority == properties
Empty file added tests/resolver/__init__.py
Empty file.
Loading
Loading