Example #1
0
def test_parse_signature_should_treat_nested_bracketed_types_as_a_unit():
    assert parse_signature(
        "(int, Optional[Tuple[str, int]], str) -> int")[0] == [
            "int",
            "Optional[Tuple[str, int]]",
            "str",
        ]
Example #2
0
def test_parse_signature_should_consider_components_of_nested_bracketed_types_as_separate(
):
    assert parse_signature(
        "(int, Optional[Tuple[str, int]], str) -> Tuple[int, bool]")[2] == {
            "int",
            "Optional",
            "Tuple",
            "str",
            "bool",
        }
Example #3
0
def test_parse_signature_should_raise_error_if_missing_input_parameter_closing_parentheses(
):
    with raises(ValueError):
        parse_signature("(str, int -> int")
Example #4
0
def test_parse_signature_should_raise_error_if_multiple_arrows():
    with raises(ValueError):
        parse_signature("() -> None -> int")
Example #5
0
def test_parse_signature_should_correctly_handle_multiline_signature():
    assert parse_signature("(\n  str\n) -> int") == (["str"], "int",
                                                     {"str", "int"})
Example #6
0
def test_parse_signature_should_treat_signature_as_variable_type_comment_if_no_arrow(
):
    assert parse_signature("int") == (None, "int", {"int"})
Example #7
0
def test_parse_signature_should_consider_components_of_bracketed_types_as_separate(
):
    assert parse_signature("(str, List[str]) -> None")[2] == {
        "str", "List", "None"
    }
Example #8
0
def test_parse_signature_should_return_non_duplicated_required_types():
    assert parse_signature("(str, str) -> int")[2] == {"str", "int"}
Example #9
0
def test_parse_signature_should_accept_none_as_a_type():
    assert parse_signature("() -> None") == ([], "None", {"None"})
Example #10
0
def test_parse_signature_should_return_empty_input_types_if_no_input_parameters(
):
    assert parse_signature("() -> int")[0] == []
Example #11
0
def test_parse_signature_should_treat_bracketed_csv_types_as_a_unit():
    assert parse_signature("(int, Tuple[str, int]) -> int")[0] == [
        "int", "Tuple[str, int]"
    ]
Example #12
0
def test_parse_signature_should_treat_bracketed_types_as_a_unit():
    assert parse_signature("(List[str]) -> int")[0] == ["List[str]"]
Example #13
0
def test_parse_signature_should_return_all_input_types_if_duplicates():
    assert parse_signature("(str, str) -> int")[0] == ["str", "str"]
Example #14
0
def test_parse_signature_should_return_multiple_input_types_in_sequence():
    assert parse_signature("(str, bool) -> int")[0] == ["str", "bool"]
Example #15
0
def test_parse_signature_should_return_input_types_return_type_and_required_types(
):
    assert parse_signature("(str) -> int") == (["str"], "int", {"str", "int"})