Ejemplo n.º 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",
        ]
Ejemplo n.º 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",
        }
Ejemplo n.º 3
0
def test_parse_signature_should_raise_error_if_missing_input_parameter_closing_parentheses(
):
    with raises(ValueError):
        parse_signature("(str, int -> int")
Ejemplo n.º 4
0
def test_parse_signature_should_raise_error_if_multiple_arrows():
    with raises(ValueError):
        parse_signature("() -> None -> int")
Ejemplo n.º 5
0
def test_parse_signature_should_correctly_handle_multiline_signature():
    assert parse_signature("(\n  str\n) -> int") == (["str"], "int",
                                                     {"str", "int"})
Ejemplo n.º 6
0
def test_parse_signature_should_treat_signature_as_variable_type_comment_if_no_arrow(
):
    assert parse_signature("int") == (None, "int", {"int"})
Ejemplo n.º 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"
    }
Ejemplo n.º 8
0
def test_parse_signature_should_return_non_duplicated_required_types():
    assert parse_signature("(str, str) -> int")[2] == {"str", "int"}
Ejemplo n.º 9
0
def test_parse_signature_should_accept_none_as_a_type():
    assert parse_signature("() -> None") == ([], "None", {"None"})
Ejemplo n.º 10
0
def test_parse_signature_should_return_empty_input_types_if_no_input_parameters(
):
    assert parse_signature("() -> int")[0] == []
Ejemplo n.º 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]"
    ]
Ejemplo n.º 12
0
def test_parse_signature_should_treat_bracketed_types_as_a_unit():
    assert parse_signature("(List[str]) -> int")[0] == ["List[str]"]
Ejemplo n.º 13
0
def test_parse_signature_should_return_all_input_types_if_duplicates():
    assert parse_signature("(str, str) -> int")[0] == ["str", "str"]
Ejemplo n.º 14
0
def test_parse_signature_should_return_multiple_input_types_in_sequence():
    assert parse_signature("(str, bool) -> int")[0] == ["str", "bool"]
Ejemplo n.º 15
0
def test_parse_signature_should_return_input_types_return_type_and_required_types(
):
    assert parse_signature("(str) -> int") == (["str"], "int", {"str", "int"})