Example #1
0
def test_single_output_new_decorator():
    def q(a: int, b: str) -> int:
        return a + len(b)

    result = transform_variable_map(
        extract_return_annotation(inspect.signature(q).return_annotation))
    assert result["o0"].type.simple == 1
Example #2
0
def test_sig_files():
    def q() -> os.PathLike:
        ...

    result = transform_variable_map(
        extract_return_annotation(inspect.signature(q).return_annotation))
    assert isinstance(result["o0"].type.blob, _core_types.BlobType)
Example #3
0
def test_unnamed_typing_tuple():
    def z(a: int, b: str) -> typing.Tuple[int, str]:
        return 5, "hello world"

    result = transform_variable_map(
        extract_return_annotation(inspect.signature(z).return_annotation))
    assert result["o0"].type.simple == 1
    assert result["o1"].type.simple == 3
Example #4
0
def test_regular_tuple():
    def q(a: int, b: str) -> (int, str):
        return 5, "hello world"

    result = transform_variable_map(
        extract_return_annotation(inspect.signature(q).return_annotation))
    assert result["o0"].type.simple == 1
    assert result["o1"].type.simple == 3
Example #5
0
def test_sig_files():
    def q() -> os.PathLike:
        ...

    result = transform_variable_map(
        extract_return_annotation(
            typing.get_type_hints(q).get("return", None)))
    assert isinstance(result["o0"].type.blob, _core_types.BlobType)
Example #6
0
def test_single_output_new_decorator():
    def q(a: int, b: str) -> int:
        return a + len(b)

    result = transform_variable_map(
        extract_return_annotation(
            typing.get_type_hints(q).get("return", None)))
    assert result["o0"].type.simple == 1
Example #7
0
def test_named_tuples():
    nt1 = typing.NamedTuple("NT1", x_str=str, y_int=int)

    def x(a: int, b: str) -> typing.NamedTuple("NT1", x_str=str, y_int=int):
        return ("hello world", 5)

    def y(a: int, b: str) -> nt1:
        return nt1("hello world", 5)

    result = transform_variable_map(
        extract_return_annotation(inspect.signature(x).return_annotation))
    assert result["x_str"].type.simple == 3
    assert result["y_int"].type.simple == 1

    result = transform_variable_map(
        extract_return_annotation(inspect.signature(y).return_annotation))
    assert result["x_str"].type.simple == 3
    assert result["y_int"].type.simple == 1
Example #8
0
def test_regular_tuple():
    def q(a: int, b: str) -> (int, str):
        return 5, "hello world"

    result = transform_variable_map(
        extract_return_annotation(
            typing.get_type_hints(q).get("return", None)))
    assert result["o0"].type.simple == 1
    assert result["o1"].type.simple == 3
Example #9
0
def test_unnamed_typing_tuple():
    def z(a: int, b: str) -> typing.Tuple[int, str]:
        return 5, "hello world"

    result = transform_variable_map(
        extract_return_annotation(
            typing.get_type_hints(z).get("return", None)))
    assert result["o0"].type.simple == 1
    assert result["o1"].type.simple == 3
Example #10
0
def test_named_tuples():
    nt1 = typing.NamedTuple("NT1", x_str=str, y_int=int)

    def x(a: int, b: str) -> typing.NamedTuple("NT1", x_str=str, y_int=int):
        return ("hello world", 5)

    def y(a: int, b: str) -> nt1:
        return nt1("hello world", 5)

    result = transform_variable_map(
        extract_return_annotation(
            typing.get_type_hints(x).get("return", None)))
    assert result["x_str"].type.simple == 3
    assert result["y_int"].type.simple == 1

    result = transform_variable_map(
        extract_return_annotation(
            typing.get_type_hints(y).get("return", None)))
    assert result["x_str"].type.simple == 3
    assert result["y_int"].type.simple == 1