Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
schmit committed Mar 15, 2024
1 parent bdcbb61 commit 7cae3d5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
22 changes: 11 additions & 11 deletions eppo_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ExperimentConfigurationRequestor,
)
from eppo_client.constants import POLL_INTERVAL_MILLIS, POLL_JITTER_MILLIS
from eppo_client.models import ValueType
from eppo_client.models import VariationType
from eppo_client.poller import Poller
from eppo_client.sharding import MD5Sharder
from eppo_client.validation import validate_not_blank
Expand Down Expand Up @@ -47,7 +47,7 @@ def get_string_assignment(
subject_key,
flag_key,
subject_attributes,
ValueType.STRING,
VariationType.STRING,
default=default,
)

Expand All @@ -62,7 +62,7 @@ def get_integer_assignment(
subject_key,
flag_key,
subject_attributes,
ValueType.INTEGER,
VariationType.INTEGER,
default=default,
)

Expand All @@ -77,7 +77,7 @@ def get_float_assignment(
subject_key,
flag_key,
subject_attributes,
ValueType.FLOAT,
VariationType.FLOAT,
default=default,
)

Expand Down Expand Up @@ -107,7 +107,7 @@ def get_boolean_assignment(
subject_key,
flag_key,
subject_attributes,
ValueType.BOOLEAN,
VariationType.BOOLEAN,
default=default,
)

Expand All @@ -122,7 +122,7 @@ def get_parsed_json_assignment(
subject_key,
flag_key,
subject_attributes,
ValueType.JSON,
VariationType.JSON,
default=default,
)
if variation_jsons:
Expand All @@ -147,12 +147,12 @@ def get_assignment_variation(
subject_key: str,
flag_key: str,
subject_attributes: Optional[Dict[str, Union[str, float, int, bool]]] = None,
expected_value_type: Optional[ValueType] = None,
expected_variation_type: Optional[VariationType] = None,
default=None,
):
try:
result = self.get_assignment_detail(
subject_key, flag_key, subject_attributes, expected_value_type
subject_key, flag_key, subject_attributes, expected_variation_type
)
if not result or not result.variation:
return default
Expand All @@ -171,7 +171,7 @@ def get_assignment_detail(
subject_key: str,
flag_key: str,
subject_attributes: Optional[Dict[str, Union[str, float, int, bool]]] = None,
expected_value_type: Optional[ValueType] = None,
expected_variation_type: Optional[VariationType] = None,
) -> Optional[FlagEvaluation]:
"""Maps a subject to a variation for a given experiment
Returns None if the subject is not part of the experiment sample.
Expand All @@ -192,9 +192,9 @@ def get_assignment_detail(
logger.info("[Eppo SDK] No assigned variation. Flag not found: " + flag_key)
return None

if not check_type_match(expected_value_type, flag.value_type):
if not check_type_match(expected_variation_type, flag.variation_type):
raise TypeError(
"Variation value does not have the correct type. Found: {flag.value_type} != {expected_value_type}"
f"Variation value does not have the correct type. Found: {flag.variation_type} != {expected_variation_type}"
)

if not flag.enabled:
Expand Down
4 changes: 2 additions & 2 deletions eppo_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from eppo_client.rules import Rule


class ValueType(Enum):
class VariationType(Enum):
STRING = "string"
INTEGER = "integer"
FLOAT = "float"
Expand Down Expand Up @@ -48,7 +48,7 @@ class Allocation(SdkBaseModel):
class Flag(SdkBaseModel):
key: str
enabled: bool
value_type: ValueType
variation_type: VariationType
variations: Dict[str, Variation]
allocations: List[Allocation]
total_shards: int = 10_000
12 changes: 6 additions & 6 deletions test/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Range,
Shard,
Split,
ValueType,
VariationType,
Variation,
)
from eppo_client.rules import Condition, OperatorType, Rule
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_log_assignment(mock_config_requestor, mock_logger):
flag = Flag(
key="flag-key",
enabled=True,
valueType=ValueType.STRING,
variation_type=VariationType.STRING,
variations={"control": Variation(key="control", value="control")},
allocations=[
Allocation(
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_get_assignment_handles_logging_exception(mock_config_requestor, mock_lo
flag = Flag(
key="flag-key",
enabled=True,
value_type=ValueType.STRING,
variation_type=VariationType.STRING,
variations={"control": Variation(key="control", value="control")},
allocations=[
Allocation(
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_assign_subject_in_sample(test_case):
"float": client.get_float_assignment,
"boolean": client.get_boolean_assignment,
"json": client.get_parsed_json_assignment,
}[test_case["valueType"]]
}[test_case["variationType"]]

assignments = get_assignments(test_case, get_typed_assignment)
for subject, assigned_variation in assignments:
Expand All @@ -230,7 +230,7 @@ def get_assignments(test_case, get_assignment_fn):
@pytest.mark.parametrize("test_case", test_data)
def test_get_numeric_assignment_on_bool_feature_flag_should_return_none(test_case):
client = get_instance()
if test_case["valueType"] == "boolean":
if test_case["variationType"] == "boolean":
assignments = get_assignments(
test_case=test_case, get_assignment_fn=client.get_float_assignment
)
Expand All @@ -245,4 +245,4 @@ def test_get_numeric_assignment_on_bool_feature_flag_should_return_none(test_cas


def test_check_type_match():
assert check_type_match(ValueType.STRING, "string")
assert check_type_match(VariationType.STRING, "string")
8 changes: 7 additions & 1 deletion test/configuration_store_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from eppo_client.models import Flag
from eppo_client.configuration_store import ConfigurationStore
from eppo_client.models import VariationType


TEST_MAX_SIZE = 10

store: ConfigurationStore[str] = ConfigurationStore(max_size=TEST_MAX_SIZE)
mock_flag = Flag(
key="mock_flag", enabled=True, variations={}, allocations=[], total_shards=10000
key="mock_flag",
variation_type=VariationType.STRING,
enabled=True,
variations={},
allocations=[],
total_shards=10000,
)


Expand Down
22 changes: 16 additions & 6 deletions test/eval_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Flag,
Allocation,
Range,
ValueType,
VariationType,
Variation,
Split,
Shard,
Expand All @@ -13,15 +13,16 @@
from eppo_client.rules import Condition, OperatorType, Rule
from eppo_client.sharding import DeterministicSharder, MD5Sharder

VARIATION_A = Variation(key="a", value="A", value_type=ValueType.STRING)
VARIATION_B = Variation(key="b", value="B", value_type=ValueType.STRING)
VARIATION_C = Variation(key="c", value="C", value_type=ValueType.STRING)
VARIATION_A = Variation(key="a", value="A")
VARIATION_B = Variation(key="b", value="B")
VARIATION_C = Variation(key="c", value="C")


def test_disabled_flag_returns_none_result():
flag = Flag(
key="disabled_flag",
enabled=False,
variation_type=VariationType.STRING,
variations={"a": VARIATION_A},
allocations=[
Allocation(
Expand Down Expand Up @@ -73,6 +74,7 @@ def test_eval_empty_flag():
empty_flag = Flag(
key="empty",
enabled=True,
variation_type=VariationType.STRING,
variations={
"a": VARIATION_A,
"b": VARIATION_B,
Expand All @@ -97,9 +99,10 @@ def test_simple_flag():
flag = Flag(
key="flag-key",
enabled=True,
variation_type=VariationType.STRING,
variations={
"control": Variation(
key="control", value="control", value_type=ValueType.STRING
key="control", value="control", value_type=VariationType.STRING
)
},
allocations=[
Expand All @@ -120,14 +123,15 @@ def test_simple_flag():
evaluator = Evaluator(sharder=MD5Sharder())
result = evaluator.evaluate_flag(flag, "user-1", {})
assert result.variation == Variation(
key="control", value="control", value_type=ValueType.STRING
key="control", value="control", value_type=VariationType.STRING
)


def test_catch_all_allocation():
flag = Flag(
key="flag",
enabled=True,
variation_type=VariationType.STRING,
variations={
"a": VARIATION_A,
"b": VARIATION_B,
Expand All @@ -154,6 +158,7 @@ def test_match_first_allocation_rule():
flag = Flag(
key="flag",
enabled=True,
variation_type=VariationType.STRING,
variations={
"a": VARIATION_A,
"b": VARIATION_B,
Expand Down Expand Up @@ -194,6 +199,7 @@ def test_do_not_match_first_allocation_rule():
flag = Flag(
key="flag",
enabled=True,
variation_type=VariationType.STRING,
variations={
"a": VARIATION_A,
"b": VARIATION_B,
Expand Down Expand Up @@ -234,6 +240,7 @@ def test_eval_sharding():
flag = Flag(
key="flag",
enabled=True,
variation_type=VariationType.STRING,
variations={
"a": VARIATION_A,
"b": VARIATION_B,
Expand Down Expand Up @@ -307,6 +314,7 @@ def test_eval_prior_to_alloc(mocker):
flag = Flag(
key="flag",
enabled=True,
variation_type=VariationType.STRING,
variations={"a": VARIATION_A},
allocations=[
Allocation(
Expand All @@ -332,6 +340,7 @@ def test_eval_during_alloc(mocker):
flag = Flag(
key="flag",
enabled=True,
variation_type=VariationType.STRING,
variations={"a": VARIATION_A},
allocations=[
Allocation(
Expand All @@ -357,6 +366,7 @@ def test_eval_after_alloc(mocker):
flag = Flag(
key="flag",
enabled=True,
variation_type=VariationType.STRING,
variations={"a": VARIATION_A},
allocations=[
Allocation(
Expand Down

0 comments on commit 7cae3d5

Please sign in to comment.