Beispiel #1
0
def test_parse_comment_annotation():
    def a():
        pass

    # asdfasdf
    def b():
        pass

    # asdfasdf
    # schema : s:int
    # # # schema : a : int,b:str
    # schema : a : str ,b:str
    # asdfasdf
    def c():
        pass

    # schema:
    def d():
        pass

    assert parse_comment_annotation(a, "schema") is None
    assert parse_comment_annotation(b, "schema") is None
    assert "a : str ,b:str" == parse_comment_annotation(c, "schema")
    assert "" == parse_comment_annotation(d, "schema")
Beispiel #2
0
def parse_validation_rules_from_comment(func: Callable) -> Dict[str, Any]:
    res: Dict[str, Any] = {}
    for key in [
            "partitionby_has",
            "partitionby_is",
            "presort_has",
            "presort_is",
            "input_has",
            "input_is",
    ]:
        v = parse_comment_annotation(func, key)
        if v is None:
            continue
        assert_or_throw(v != "", lambda: SyntaxError(f"{key} can't be empty"))
        res[key] = v
    return to_validation_rules(res)