Skip to content

Commit

Permalink
use static values
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Aug 13, 2024
1 parent 6193d44 commit e11c727
Showing 1 changed file with 22 additions and 66 deletions.
88 changes: 22 additions & 66 deletions tests/test_local_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ def identifiers() -> Tuple[str, ...]:
return ("1", "2", "3", "4", "5")


def get_matching_str(*values: str) -> str:
class _matching_str(str):
_values = values

def __eq__(self, other: object) -> bool:
return other in self._values

return _matching_str(" / ".join(values))


def _get_flag_mock(**kwargs: object) -> mock.Mock:
mock_kwargs = {field.name: mock.ANY for field in fields(Flag)}
mock_kwargs.update(kwargs)
Expand All @@ -47,96 +37,58 @@ def _get_flag_mock(**kwargs: object) -> mock.Mock:


@pytest.fixture
def environment_default_or_percentage_split_value_flag_mock() -> mock.Mock:
return _get_flag_mock(
value=get_matching_str(
"environment default",
'overridden by "split_segment"',
),
)


@pytest.fixture
def mv_value_flag_mock() -> mock.Mock:
return _get_flag_mock(
value=get_matching_str(
"a",
"b",
),
)


@pytest.fixture
def mv_segment_override_value_flag_mock() -> mock.Mock:
return _get_flag_mock(
value=get_matching_str(
'overridden by segment "power_users"',
"a",
),
)


@pytest.fixture
def expected_flags_without_identity_overrides(
environment_default_or_percentage_split_value_flag_mock: mock.Mock,
mv_segment_override_value_flag_mock: mock.Mock,
mv_value_flag_mock: mock.Mock,
) -> Dict[str, Flags]:
def expected_flags_without_identity_overrides() -> Dict[str, Flags]:
return {
# - [ ] Identity 1:
# - [ ] multivariate feature: % split
# - [ ] normal feature: environment default / % split override
"1": Flags(
{
"multivariate_feature": mv_value_flag_mock,
"normal_feature": environment_default_or_percentage_split_value_flag_mock,
"multivariate_feature": _get_flag_mock(value="b"),
"normal_feature": _get_flag_mock(value='overridden by "split_segment"'),
},
),
# - [ ] Identity 2:
# - [ ] multivariate feature: % split
# - [ ] normal feature: environment default / % split override
"2": Flags(
{
"multivariate_feature": mv_value_flag_mock,
"normal_feature": environment_default_or_percentage_split_value_flag_mock,
"multivariate_feature": _get_flag_mock(value="b"),
"normal_feature": _get_flag_mock(value="environment default"),
},
),
# - [ ] Identity 3:
# - [ ] multivariate feature: segment override
# - [ ] normal feature: environment default / % split override
"3": Flags(
{
"multivariate_feature": mv_segment_override_value_flag_mock,
"normal_feature": environment_default_or_percentage_split_value_flag_mock,
"multivariate_feature": _get_flag_mock(value="a"),
"normal_feature": _get_flag_mock(value="environment default"),
},
),
# - [ ] Identity 4:
# - [ ] multivariate feature: % split
# - [ ] normal feature: environment default / % split override
"4": Flags(
{
"multivariate_feature": mv_value_flag_mock,
"normal_feature": environment_default_or_percentage_split_value_flag_mock,
"multivariate_feature": _get_flag_mock(value="b"),
"normal_feature": _get_flag_mock(value='overridden by "split_segment"'),
},
),
# - [ ] Identity 5:
# - [ ] multivariate feature: % split
# - [ ] normal feature: environment default / % split override
"5": Flags(
{
"multivariate_feature": mv_value_flag_mock,
"normal_feature": environment_default_or_percentage_split_value_flag_mock,
"multivariate_feature": _get_flag_mock(value="a"),
"normal_feature": _get_flag_mock(value='overridden by "split_segment"'),
},
),
}


@pytest.fixture
def expected_flags_with_identity_overrides(
environment_default_or_percentage_split_value_flag_mock: mock.Mock,
mv_segment_override_value_flag_mock: mock.Mock,
mv_value_flag_mock: mock.Mock,
) -> Dict[str, Flags]:
def expected_flags_with_identity_overrides() -> Dict[str, Flags]:
return {
# - [ ] Identity 1:
# - [ ] multivariate feature: identity override
Expand All @@ -152,7 +104,7 @@ def expected_flags_with_identity_overrides(
# - [ ] normal feature: identity override
"2": Flags(
{
"multivariate_feature": mv_value_flag_mock,
"multivariate_feature": _get_flag_mock(value="b"),
"normal_feature": _get_flag_mock(value="overridden for 2"),
},
),
Expand All @@ -161,7 +113,9 @@ def expected_flags_with_identity_overrides(
# - [ ] normal feature: identity override
"3": Flags(
{
"multivariate_feature": mv_segment_override_value_flag_mock,
"multivariate_feature": _get_flag_mock(
value='overridden by segment "power_users"'
),
"normal_feature": _get_flag_mock(value="overridden for 3"),
},
),
Expand All @@ -170,17 +124,19 @@ def expected_flags_with_identity_overrides(
# - [ ] normal feature: environment default / % split override
"4": Flags(
{
"multivariate_feature": mv_segment_override_value_flag_mock,
"normal_feature": environment_default_or_percentage_split_value_flag_mock,
"multivariate_feature": _get_flag_mock(
value='overridden by segment "power_users"'
),
"normal_feature": _get_flag_mock(value='overridden by "split_segment"'),
},
),
# - [ ] Identity 5:
# - [ ] multivariate feature: % split
# - [ ] normal feature: environment default / % split override
"5": Flags(
{
"multivariate_feature": mv_value_flag_mock,
"normal_feature": environment_default_or_percentage_split_value_flag_mock,
"multivariate_feature": _get_flag_mock(value="b"),
"normal_feature": _get_flag_mock(value='overridden by "split_segment"'),
},
),
}
Expand Down

0 comments on commit e11c727

Please sign in to comment.