(validator)
return {
        "check": check_item,
        "expect": expect_value,
        "assert": assert_method,
        "message": message,
    }
unify validator

    Args:
        validator (dict): validator maybe in two formats:

            format1: this is kept for compatibility with the previous versions.
                {"check": "status_code", "comparator": "eq", "expect": 201}
                {"check": "$resp_body_success", "comparator": "eq", "expect": True}
            format2: recommended new version, {assert: [check_item, expected_value]}
                {'eq': ['status_code', 201]}
                {'eq': ['$resp_body_success', True]}

    Returns
        dict: validator info

            {
                "check": "status_code",
                "expect": 201,
                "assert": "equals"
            }
unify validator
unify validator
def uniform_validator(validator):
    """ unify validator

    Args:
        validator (dict): validator maybe in two formats:

            format1: this is kept for compatibility with the previous versions.
                {"check": "status_code", "comparator": "eq", "expect": 201}
                {"check": "$resp_body_success", "comparator": "eq", "expect": True}
            format2: recommended new version, {assert: [check_item, expected_value]}
                {'eq': ['status_code', 201]}
                {'eq': ['$resp_body_success', True]}

    Returns
        dict: validator info

            {
                "check": "status_code",
                "expect": 201,
                "assert": "equals"
            }

    """
    if not isinstance(validator, dict):
        raise ParamsError(f"invalid validator: {validator}")

    if "check" in validator and "expect" in validator:
        # format1
        check_item = validator["check"]
        expect_value = validator["expect"]
        message = validator.get("message", "")
        comparator = validator.get("comparator", "eq")

    elif len(validator) == 1:
        # format2
        comparator = list(validator.keys())[0]
        compare_values = validator[comparator]

        if not isinstance(compare_values, list) or len(compare_values) not in [2, 3]:
            raise ParamsError(f"invalid validator: {validator}")

        check_item = compare_values[0]
        expect_value = compare_values[1]
        if len(compare_values) == 3:
            message = compare_values[2]
        else:
            # len(compare_values) == 2
            message = ""

    else:
        raise ParamsError(f"invalid validator: {validator}")

    # uniform comparator, e.g. lt => less_than, eq => equals
    assert_method = get_uniform_comparator(comparator)

    return {
        "check": check_item,
        "expect": expect_value,
        "assert": assert_method,
        "message": message,
    }
def uniform_validator ( validator ) : if not isinstance ( validator , dict ) : raise ParamsError ( f"invalid validator: {validator}" ) if "check" in validator and "expect" in validator : # format1 check_item = validator [ "check" ] expect_value = validator [ "expect" ] message = validator . get ( "message" , "" ) comparator = validator . get ( "comparator" , "eq" ) elif len ( validator ) == 1 : # format2 comparator = list ( validator . keys ( ) ) [ 0 ] compare_values = validator [ comparator ] if not isinstance ( compare_values , list ) or len ( compare_values ) not in [ 2 , 3 ] : raise ParamsError ( f"invalid validator: {validator}" ) check_item = compare_values [ 0 ] expect_value = compare_values [ 1 ] if len ( compare_values ) == 3 : message = compare_values [ 2 ] else : # len(compare_values) == 2 message = "" else : raise ParamsError ( f"invalid validator: {validator}" ) # uniform comparator, e.g. lt => less_than, eq => equals assert_method = get_uniform_comparator ( comparator ) return { "check" : check_item , "expect" : expect_value , "assert" : assert_method , "message" : message , }