src/table_validator/api.py
def validate(template: List[List[Any]], candidate: List[List[Any]]) -> bool:
    """Validate a candidate using a given template."""
    rules, repeats = _consume_parsed_template(parse_template(template))

    current_row_index = 0
    while current_row_index <= len(candidate):
        current_row_rules = rules.get(current_row_index)
        if current_row_rules is None:
            current_row_index += 1
            continue

        current_column_index = 0
        try:
            current_row = candidate[current_row_index]
        except IndexError:
            print('current row index', current_row_index)
            raise

        while current_column_index <= len(current_row):
            validators = current_row_rules.get(current_column_index)
            if validators is None:
                current_column_index += 1
                continue

            for validator in validators:
                if not validator(candidate, current_row_index, current_column_index):
                    return False

            current_column_index += 1
        current_row_index += 1
    return True

    # passed = True
    # row_offset = 0
    #
    # for rule in rules:
    #     if isinstance(rule, list):
    #         # multiple validations
    #         for validator, row, column in rule:
    #             if not validator(candidate, row, column):
    #                 print(f'failed at ({row}, {column}, {candidate[row][column]}: {validator}')
    #                 passed = False
    #                 break
    #     elif isinstance(rule, str):
    #         pass  # keep going until one row fails
    #         inner_passed = True
    #         while inner_passed:
    #             break
    #
    #     elif not rule(candidate, row, column):
    #         print(f'failed at ({row}, {column}, {candidate[row][column]}: {validator}')
    #         passed = False
    #
    # return passed
Validate a candidate using a given template.
Validate a candidate using a given template.
Validate a candidate using a given template .
def validate(template: List[List[Any]], candidate: List[List[Any]]) -> bool:
    rules, repeats = _consume_parsed_template(parse_template(template))
    current_row_index = 0
    while current_row_index <= len(candidate):
        current_row_rules = rules.get(current_row_index)
        if current_row_rules is None:
            current_row_index += 1
            continue
        current_column_index = 0
        try:
            current_row = candidate[current_row_index]
        except IndexError:
            print('current row index', current_row_index)
            raise
        while current_column_index <= len(current_row):
            validators = current_row_rules.get(current_column_index)
            if validators is None:
                current_column_index += 1
                continue
            for validator in validators:
                if not validator(candidate, current_row_index, current_column_index):
                    return False
            current_column_index += 1
        current_row_index += 1
    return True
     for rule in rules:
         if isinstance(rule, list):
              multiple validations
             for validator, row, column in rule:
                 if not validator(candidate, row, column):
                     print(f'failed at ({row}, {column}, {candidate[row][column]}: {validator}')
                     passed = False
                     break
         elif isinstance(rule, str):
             pass   keep going until one row fails
             inner_passed = True
             while inner_passed:
                 break
         elif not rule(candidate, row, column):
             print(f'failed at ({row}, {column}, {candidate[row][column]}: {validator}')
             passed = False
     return passed
def validate ( template : List [ List [ Any ] ] , candidate : List [ List [ Any ] ] ) -> bool : rules , repeats = _consume_parsed_template ( parse_template ( template ) ) current_row_index = 0 while current_row_index <= len ( candidate ) : current_row_rules = rules . get ( current_row_index ) if current_row_rules is None : current_row_index += 1 continue current_column_index = 0 try : current_row = candidate [ current_row_index ] except IndexError : print ( 'current row index' , current_row_index ) raise while current_column_index <= len ( current_row ) : validators = current_row_rules . get ( current_column_index ) if validators is None : current_column_index += 1 continue for validator in validators : if not validator ( candidate , current_row_index , current_column_index ) : return False current_column_index += 1 current_row_index += 1 return True
Validate a candidate using a given template.
Validate a candidate using a given template .
"""Validate a candidate using a given template.""" # passed = True # row_offset = 0 # # for rule in rules: #     if isinstance(rule, list): #         # multiple validations #         for validator, row, column in rule: #             if not validator(candidate, row, column): #                 print(f'failed at ({row}, {column}, {candidate[row][column]}: {validator}') #                 passed = False #                 break #     elif isinstance(rule, str): #         pass  # keep going until one row fails #         inner_passed = True #         while inner_passed: #             break # #     elif not rule(candidate, row, column): #         print(f'failed at ({row}, {column}, {candidate[row][column]}: {validator}') #         passed = False # # return passed
template
List[List[Any]]
candidate
List[List[Any]]