Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Future-Outlier <[email protected]>
  • Loading branch information
Future-Outlier committed Sep 19, 2024
1 parent 5539c1e commit bcaf573
Showing 1 changed file with 55 additions and 41 deletions.
96 changes: 55 additions & 41 deletions tests/flytekit/unit/core/test_type_engine_binary_idl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,71 @@
def test_simple_type_transformer():
ctx = FlyteContextManager.current_context()

int_input = 20240918
int_inputs = [1, 2, 20240918, -1, -2, -20240918]
encoder = MessagePackEncoder(int)
int_msgpack_bytes = encoder.encode(int_input)
lv = Literal(scalar=Scalar(binary=Binary(value=int_msgpack_bytes, tag="msgpack")))
int_output = TypeEngine.to_python_value(ctx, lv, int)
assert int_input == int_output
for int_input in int_inputs:
int_msgpack_bytes = encoder.encode(int_input)
lv = Literal(scalar=Scalar(binary=Binary(value=int_msgpack_bytes, tag="msgpack")))
int_output = TypeEngine.to_python_value(ctx, lv, int)
assert int_input == int_output

float_input = 2024.0918
float_inputs = [2024.0918, 5.0, -2024.0918, -5.0]
encoder = MessagePackEncoder(float)
float_msgpack_bytes = encoder.encode(float_input)
lv = Literal(scalar=Scalar(binary=Binary(value=float_msgpack_bytes, tag="msgpack")))
float_output = TypeEngine.to_python_value(ctx, lv, float)
assert float_input == float_output
for float_input in float_inputs:
float_msgpack_bytes = encoder.encode(float_input)
lv = Literal(scalar=Scalar(binary=Binary(value=float_msgpack_bytes, tag="msgpack")))
float_output = TypeEngine.to_python_value(ctx, lv, float)
assert float_input == float_output

bool_input = True
bool_inputs = [True, False]
encoder = MessagePackEncoder(bool)
bool_msgpack_bytes = encoder.encode(bool_input)
lv = Literal(scalar=Scalar(binary=Binary(value=bool_msgpack_bytes, tag="msgpack")))
bool_output = TypeEngine.to_python_value(ctx, lv, bool)
assert bool_input == bool_output
for bool_input in bool_inputs:
bool_msgpack_bytes = encoder.encode(bool_input)
lv = Literal(scalar=Scalar(binary=Binary(value=bool_msgpack_bytes, tag="msgpack")))
bool_output = TypeEngine.to_python_value(ctx, lv, bool)
assert bool_input == bool_output

bool_input = False
bool_msgpack_bytes = encoder.encode(bool_input)
lv = Literal(scalar=Scalar(binary=Binary(value=bool_msgpack_bytes, tag="msgpack")))
bool_output = TypeEngine.to_python_value(ctx, lv, bool)
assert bool_input == bool_output

str_input = "hello"
str_inputs = ["hello", "world", "flyte", "kit", "is", "awesome"]
encoder = MessagePackEncoder(str)
str_msgpack_bytes = encoder.encode(str_input)
lv = Literal(scalar=Scalar(binary=Binary(value=str_msgpack_bytes, tag="msgpack")))
str_output = TypeEngine.to_python_value(ctx, lv, str)
assert str_input == str_output
for str_input in str_inputs:
str_msgpack_bytes = encoder.encode(str_input)
lv = Literal(scalar=Scalar(binary=Binary(value=str_msgpack_bytes, tag="msgpack")))
str_output = TypeEngine.to_python_value(ctx, lv, str)
assert str_input == str_output

datetime_input = datetime.now()
datetime_inputs = [datetime.now(),
datetime(2024, 9, 18),
datetime(2024, 9, 18, 1),
datetime(2024, 9, 18, 1, 1),
datetime(2024, 9, 18, 1, 1, 1),
datetime(2024, 9, 18, 1, 1, 1, 1)]
encoder = MessagePackEncoder(datetime)
datetime_msgpack_bytes = encoder.encode(datetime_input)
lv = Literal(scalar=Scalar(binary=Binary(value=datetime_msgpack_bytes, tag="msgpack")))
datetime_output = TypeEngine.to_python_value(ctx, lv, datetime)
assert datetime_input == datetime_output
for datetime_input in datetime_inputs:
datetime_msgpack_bytes = encoder.encode(datetime_input)
lv = Literal(scalar=Scalar(binary=Binary(value=datetime_msgpack_bytes, tag="msgpack")))
datetime_output = TypeEngine.to_python_value(ctx, lv, datetime)
assert datetime_input == datetime_output

date_input = date.today()
date_inputs = [date.today(),
date(2024, 9, 18)]
encoder = MessagePackEncoder(date)
date_msgpack_bytes = encoder.encode(date_input)
lv = Literal(scalar=Scalar(binary=Binary(value=date_msgpack_bytes, tag="msgpack")))
date_output = TypeEngine.to_python_value(ctx, lv, date)
assert date_input == date_output
for date_input in date_inputs:
date_msgpack_bytes = encoder.encode(date_input)
lv = Literal(scalar=Scalar(binary=Binary(value=date_msgpack_bytes, tag="msgpack")))
date_output = TypeEngine.to_python_value(ctx, lv, date)
assert date_input == date_output

timedelta_input = timedelta(days=1, seconds=1, microseconds=1, milliseconds=1, minutes=1, hours=1, weeks=1)
timedelta_inputs = [timedelta(days=1),
timedelta(days=1, seconds=1),
timedelta(days=1, seconds=1, microseconds=1),
timedelta(days=1, seconds=1, microseconds=1, milliseconds=1),
timedelta(days=1, seconds=1, microseconds=1, milliseconds=1, minutes=1),
timedelta(days=1, seconds=1, microseconds=1, milliseconds=1, minutes=1, hours=1),
timedelta(days=1, seconds=1, microseconds=1, milliseconds=1, minutes=1, hours=1, weeks=1),
timedelta(days=-1, seconds=-1, microseconds=-1, milliseconds=-1, minutes=-1, hours=-1, weeks=-1)]
encoder = MessagePackEncoder(timedelta)
timedelta_msgpack_bytes = encoder.encode(timedelta_input)
lv = Literal(scalar=Scalar(binary=Binary(value=timedelta_msgpack_bytes, tag="msgpack")))
timedelta_output = TypeEngine.to_python_value(ctx, lv, timedelta)
assert timedelta_input == timedelta_output
for timedelta_input in timedelta_inputs:
timedelta_msgpack_bytes = encoder.encode(timedelta_input)
lv = Literal(scalar=Scalar(binary=Binary(value=timedelta_msgpack_bytes, tag="msgpack")))
timedelta_output = TypeEngine.to_python_value(ctx, lv, timedelta)
assert timedelta_input == timedelta_output

0 comments on commit bcaf573

Please sign in to comment.