Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw committed Aug 17, 2022
1 parent d313077 commit 9f8a134
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def _deserialize_flyte_type(self, python_val: T, expected_python_type: Type) ->
def _fix_val_int(self, t: typing.Type, val: typing.Any) -> typing.Any:
if val is None:
return val
if t == int:
if t == int or t == typing.Optional[int]:
return int(val)

if isinstance(val, list):
Expand Down Expand Up @@ -1314,7 +1314,7 @@ def _get_element_type(element_property: typing.Dict[str, str]) -> Type[T]:

if type(element_type) == list:
# Element type of Optional[int] is [integer, None]
element_type = element_type[0]
return typing.Optional[_get_element_type({"type": element_type[0]})]

if element_type == "string":
return str
Expand Down
32 changes: 17 additions & 15 deletions tests/flytekit/unit/core/test_type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,23 @@ class Foo(object):
schema = JSONSchema().dump(typing.cast(DataClassJsonMixin, Foo).schema())
foo_class = convert_json_schema_to_python_class(schema["definitions"], "FooSchema")

pv = transformer.to_python_value(ctx, lv, expected_python_type=typing.List[foo_class])
assert isinstance(pv, list)
assert pv[0].u == foo.u
assert pv[0].v == foo.v
assert pv[0].w == foo.w
assert pv[0].x == foo.x
assert pv[0].y == foo.y
assert pv[0].z.x == foo.z.x
assert type(pv[0].u) == int
assert pv[0].v is None
assert type(pv[0].w) == int
assert type(pv[0].z.x) == float
assert pv[0].z.y == foo.z.y
assert pv[0].z.z == foo.z.z
assert foo == dataclass_from_dict(Foo, asdict(pv[0]))
guessed_pv = transformer.to_python_value(ctx, lv, expected_python_type=typing.List[foo_class])
print("=====")
pv = transformer.to_python_value(ctx, lv, expected_python_type=typing.List[Foo])
assert isinstance(guessed_pv, list)
assert guessed_pv[0].u == pv[0].u
assert guessed_pv[0].v == pv[0].v
assert guessed_pv[0].w == pv[0].w
assert guessed_pv[0].x == pv[0].x
assert guessed_pv[0].y == pv[0].y
assert guessed_pv[0].z.x == pv[0].z.x
assert type(guessed_pv[0].u) == int
assert guessed_pv[0].v is None
assert type(guessed_pv[0].w) == int
assert type(guessed_pv[0].z.x) == float
assert guessed_pv[0].z.y == pv[0].z.y
assert guessed_pv[0].z.z == pv[0].z.z
assert pv[0] == dataclass_from_dict(Foo, asdict(guessed_pv[0]))


def test_file_no_downloader_default():
Expand Down

0 comments on commit 9f8a134

Please sign in to comment.