Skip to content

Commit

Permalink
75: ProtobufDict and ParamsDict types should use a Dict instead of un…
Browse files Browse the repository at this point in the history
…mutable Mapping.
  • Loading branch information
lfse-slafleur committed Oct 16, 2024
1 parent 3a47c6d commit afa2ec9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/omotes_sdk/types.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from datetime import timedelta, datetime
from typing import List, Union, Mapping
from typing import List, Union, Dict

ParamsDictValues = Union[
List["ParamsDictValues"], "ParamsDict", None, float, int, str, bool, datetime, timedelta
]
ParamsDict = Mapping[str, ParamsDictValues]
ParamsDict = Dict[str, ParamsDictValues]
PBStructCompatibleTypes = Union[list, float, str, bool]
ProtobufDict = Mapping[str, PBStructCompatibleTypes]
ProtobufDict = Dict[str, PBStructCompatibleTypes]
28 changes: 15 additions & 13 deletions unit_test/test_workflow_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
WorkflowTypeManager,
DurationParameter,
)
from omotes_sdk.types import ParamsDict
from omotes_sdk.types import ProtobufDict, ParamsDict


class WorkflowTypeTest(unittest.TestCase):
Expand Down Expand Up @@ -191,7 +191,7 @@ def test__convert_params_dict_to_struct__list_bool_float_int_datetime_timedelta(
# TODO Reenable when list is integrated as a workflow parameter
# def test__parse_workflow_config_parameter__list(self) -> None:
# # Arrange
# workflow_config: ParamsDict = {"some-key": [1.0, 2.0, 3.0]}
# workflow_config: ProtobufDict = {"some-key": [1.0, 2.0, 3.0]}
# field_key: str = "some-key"
# expected_type: Type[list] = list
# default_value: list[float] = []
Expand All @@ -207,7 +207,7 @@ def test__convert_params_dict_to_struct__list_bool_float_int_datetime_timedelta(

def test__parse_workflow_config_parameter__bool(self) -> None:
# Arrange
workflow_config = {"some-key": True}
workflow_config: ProtobufDict = {"some-key": True}
field_key = "some-key"
expected_type = BooleanParameter
default_value = False
Expand All @@ -222,7 +222,7 @@ def test__parse_workflow_config_parameter__bool(self) -> None:

def test__parse_workflow_config_parameter__str(self) -> None:
# Arrange
workflow_config = {"some-key": "some-str"}
workflow_config: ProtobufDict = {"some-key": "some-str"}
field_key = "some-key"
expected_type = StringParameter
default_value = "default"
Expand All @@ -238,7 +238,7 @@ def test__parse_workflow_config_parameter__str(self) -> None:

def test__parse_workflow_config_parameter__float(self) -> None:
# Arrange
workflow_config = {"some-key": 2.0}
workflow_config: ProtobufDict = {"some-key": 2.0}
field_key = "some-key"
expected_type = FloatParameter
default_value = 1
Expand All @@ -254,7 +254,7 @@ def test__parse_workflow_config_parameter__float(self) -> None:

def test__parse_workflow_config_parameter__int(self) -> None:
# Arrange
workflow_config = {"some-key": 2.0}
workflow_config: ProtobufDict = {"some-key": 2.0}
field_key = "some-key"
expected_type = IntegerParameter
default_value = 3
Expand All @@ -270,7 +270,9 @@ def test__parse_workflow_config_parameter__int(self) -> None:

def test__parse_workflow_config_parameter__datetime(self) -> None:
# Arrange
workflow_config = {"some-key": datetime.fromisoformat("2019-01-01T01:00:00").timestamp()}
workflow_config: ProtobufDict = {
"some-key": datetime.fromisoformat("2019-01-01T01:00:00").timestamp()
}
field_key = "some-key"
expected_type = DateTimeParameter
default_value = datetime.fromisoformat("2019-01-01T00:00:00")
Expand All @@ -286,7 +288,7 @@ def test__parse_workflow_config_parameter__datetime(self) -> None:

def test__parse_workflow_config_parameter__timedelta(self) -> None:
# Arrange
workflow_config = {"some-key": 3615.0}
workflow_config: ProtobufDict = {"some-key": 3615.0}
field_key = "some-key"
expected_type = DurationParameter
default_value = timedelta(hours=1)
Expand All @@ -302,7 +304,7 @@ def test__parse_workflow_config_parameter__timedelta(self) -> None:

def test__parse_workflow_config_parameter__key_available_expect_int_but_get_float(self) -> None:
# Arrange
workflow_config = {"some-key": 1.4}
workflow_config: ProtobufDict = {"some-key": 1.4}
field_key = "some-key"
expected_type = IntegerParameter
default_value = 2.0
Expand All @@ -318,7 +320,7 @@ def test__parse_workflow_config_parameter__key_available_expect_int_but_get_floa

def test__parse_workflow_config_parameter__key_unavailable_but_default(self) -> None:
# Arrange
workflow_config = {"no-key": 1.0}
workflow_config: ProtobufDict = {"no-key": 1.0}
field_key = "some-key"
expected_type = FloatParameter
default_value = 2.0
Expand All @@ -334,7 +336,7 @@ def test__parse_workflow_config_parameter__key_unavailable_but_default(self) ->

def test__parse_workflow_config_parameter__key_wrong_type_but_default(self) -> None:
# Arrange
workflow_config = {"some-key": True}
workflow_config: ProtobufDict = {"some-key": True}
field_key = "some-key"
expected_type = FloatParameter
default_value = 2.0
Expand All @@ -350,7 +352,7 @@ def test__parse_workflow_config_parameter__key_wrong_type_but_default(self) -> N

def test__parse_workflow_config_parameter__key_missing_and_no_default(self) -> None:
# Arrange
workflow_config = {"no-key": 1.0}
workflow_config: ProtobufDict = {"no-key": 1.0}
field_key = "some-key"
expected_type = FloatParameter
default_value = None
Expand All @@ -363,7 +365,7 @@ def test__parse_workflow_config_parameter__key_missing_and_no_default(self) -> N

def test__parse_workflow_config_parameter__key_wrong_type_and_no_default(self) -> None:
# Arrange
workflow_config = {"some-key": True}
workflow_config: ProtobufDict = {"some-key": True}
field_key = "some-key"
expected_type = FloatParameter
default_value = None
Expand Down

0 comments on commit afa2ec9

Please sign in to comment.