diff --git a/tests/flytekit/unit/core/test_type_engine_binary_idl.py b/tests/flytekit/unit/core/test_type_engine_binary_idl.py index 318765c484..34010e37cf 100644 --- a/tests/flytekit/unit/core/test_type_engine_binary_idl.py +++ b/tests/flytekit/unit/core/test_type_engine_binary_idl.py @@ -10,60 +10,74 @@ 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 - - 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" - 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 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 - datetime_input = datetime.now() + str_inputs = ["hello", "world", "flyte", "kit", "is", "awesome"] + encoder = MessagePackEncoder(str) + 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_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 - - date_input = date.today() + 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_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 - - timedelta_input = timedelta(days=1, seconds=1, microseconds=1, milliseconds=1, minutes=1, hours=1, weeks=1) + 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_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 def test_untyped_dict(): ctx = FlyteContextManager.current_context()