Skip to content

Commit b56a879

Browse files
[Resolver] Basic Logic for Filtering & Sorting added (#25)
* Basic Filtering & Sorting added * WIP on sorting_and_filtering * Adding some unittests * Validation API Update * Work in progress * Review Comments * Review Fixes * Unittests more rugged * Final Cleanups
1 parent 4b14a23 commit b56a879

19 files changed

+2607
-12
lines changed

pyproject.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ maintainers = [
3030
]
3131
dependencies = [
3232
"importlib-metadata; python_version < '3.10'",
33+
"platformdirs>=4.3,<5.0",
34+
"tomli; python_version < '3.11'",
3335
"typing-extensions; python_version < '3.11'",
3436
]
3537

@@ -44,16 +46,18 @@ dev = [
4446
"ruff>=0.10,<1.0",
4547
]
4648
test = [
49+
"deepdiff>=8.0,<9.0",
4750
"jsondiff>=2.2,<2.3",
4851
"hypothesis>=6.0.0,<7",
52+
"parameterized>=0.9.0,<0.10",
4953
"pytest>=8.0.0,<9.0.0",
5054
"pytest-cov>=5.0.0,<6.0.0",
5155
"pytest-dotenv>=0.5.0,<1.0.0",
5256
"pytest-env>=1.1.3,<2.0.0",
5357
"pytest-mock>=3.14.0,<4.0.0",
5458
"pytest-runner>=6.0.0,<7.0.0",
5559
"pytest-ordering>=0.6,<1.0.0",
56-
"parameterized>=0.9.0,<0.10",
60+
"tomli_w>=1.2,<1.3",
5761
]
5862

5963
[project.scripts]

tests/models/test_configuration.py

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
from hypothesis import given
5+
from hypothesis import strategies as st
6+
7+
from variantlib.constants import VALIDATION_FEATURE_REGEX
8+
from variantlib.constants import VALIDATION_NAMESPACE_REGEX
9+
from variantlib.constants import VALIDATION_VALUE_REGEX
10+
from variantlib.models.configuration import VariantConfiguration
11+
from variantlib.models.variant import VariantFeature
12+
from variantlib.models.variant import VariantProperty
13+
14+
15+
def test_default_configuration():
16+
config = VariantConfiguration.default()
17+
assert config.namespaces_priority == []
18+
assert config.features_priority == []
19+
assert config.property_priority == []
20+
21+
22+
@pytest.mark.parametrize(
23+
"config_params",
24+
[
25+
{
26+
"namespaces": ["OmniCorp"],
27+
"features": [],
28+
"properties": [],
29+
},
30+
{
31+
"namespaces": ["OmniCorp"],
32+
"features": ["OmniCorp::custom_feat"],
33+
"properties": ["OmniCorp::custom_feat::secret_value"],
34+
},
35+
{
36+
"namespaces": ["OmniCorp", "AcmeCorp"],
37+
"features": ["OmniCorp::custom_feat", "AcmeCorp :: custom_feat"],
38+
"properties": [
39+
"OmniCorp :: custom_featA :: secret_value",
40+
"OmniCorp :: custom_featB:: secret_value",
41+
"AcmeCorp::custom_feat::secret_value",
42+
],
43+
},
44+
],
45+
)
46+
def test_from_toml_config(config_params: dict[str, list[str]]):
47+
_ = VariantConfiguration.from_toml_config(
48+
namespaces_priority=config_params["namespaces"],
49+
features_priority=config_params["features"],
50+
property_priority=config_params["properties"],
51+
)
52+
53+
54+
@given(st.lists(st.from_regex(VALIDATION_NAMESPACE_REGEX)))
55+
def test_namespaces_priority_validation(namespaces: list[str]):
56+
config = VariantConfiguration(namespaces_priority=namespaces)
57+
assert config.namespaces_priority == namespaces
58+
59+
60+
@given(
61+
st.lists(st.from_regex(VALIDATION_NAMESPACE_REGEX)),
62+
st.lists(
63+
st.builds(
64+
VariantFeature,
65+
namespace=st.just("OmniCorp"),
66+
feature=st.from_regex(VALIDATION_FEATURE_REGEX),
67+
)
68+
),
69+
)
70+
def test_features_priority_validation(
71+
namespaces: list[str], features: list[VariantFeature]
72+
):
73+
config = VariantConfiguration(
74+
namespaces_priority=namespaces, features_priority=features
75+
)
76+
assert config.features_priority == features
77+
78+
79+
@given(
80+
st.lists(st.from_regex(VALIDATION_NAMESPACE_REGEX)),
81+
st.lists(
82+
st.builds(
83+
VariantFeature,
84+
namespace=st.from_regex(VALIDATION_NAMESPACE_REGEX),
85+
feature=st.from_regex(VALIDATION_FEATURE_REGEX),
86+
)
87+
),
88+
st.lists(
89+
st.builds(
90+
VariantProperty,
91+
namespace=st.from_regex(VALIDATION_NAMESPACE_REGEX),
92+
feature=st.from_regex(VALIDATION_FEATURE_REGEX),
93+
value=st.from_regex(VALIDATION_VALUE_REGEX),
94+
)
95+
),
96+
)
97+
def test_property_priority_validation(
98+
namespaces: list[str],
99+
features: list[VariantFeature],
100+
properties: list[VariantProperty],
101+
):
102+
config = VariantConfiguration(
103+
namespaces_priority=namespaces,
104+
features_priority=features,
105+
property_priority=properties,
106+
)
107+
assert config.property_priority == properties

tests/resolver/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)