Commit ed182877 authored by Asitha Senanayake's avatar Asitha Senanayake
Browse files

Fix #105: Replace 'AGS Format Rule ?' with 'Validator Process Error'

parent b92329cf
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
Changelog
=========

0.6.0 (Pending)
--------------
- Report exceptions in the error log using the description 'Validation Process
  Error'

0.5.0 (2024-01-27)
------------------

+13 −4
Original line number Diff line number Diff line
@@ -906,9 +906,11 @@ def check_file(filepath_or_buffer, standard_AGS4_dictionary=None, rename_duplica

        ags_errors = check.add_error_msg(ags_errors, 'General', '-', '',
                                         'Could not complete validation. Please fix listed errors and try again.')
        ags_errors = check.add_error_msg(ags_errors, 'AGS Format Rule ?', '-', '', str(err))
        ags_errors = check.add_error_msg(ags_errors, 'Validator Process Error', '-', '', str(err))

    except UnboundLocalError as err:
        logger.exception(err)

    except UnboundLocalError:
        # The presence of a byte-order-mark (BOM) in the same row as first
        # "GROUP" line can cause this exception. This will be caught by line
        # checks for Rule 1 (since the BOM is not an ASCII character) and Rule 3
@@ -931,7 +933,7 @@ def check_file(filepath_or_buffer, standard_AGS4_dictionary=None, rename_duplica

        ags_errors = check.add_error_msg(ags_errors, 'General', '-', '',
                                         'Could not complete validation. Please fix listed errors and try again.')
        ags_errors = check.add_error_msg(ags_errors, 'AGS Format Rule ?', '-', '', 'Unexpected parsing error.')
        ags_errors = check.add_error_msg(ags_errors, 'Validator Process Error', '-', '', str(err))

    finally:
        if close_file:
@@ -1020,6 +1022,13 @@ def write_error_report(ags_errors, output_file, show_warnings=False, show_fyi=Fa
                    f.write(f'''  Line {entry['line']:<8} {entry['group'].strip('"'):<7} {entry['desc']}\r\n''')
                f.write('\r\n')

            # Write parsing and process error messages
            for key in [x for x in ags_errors if 'Validator Process Error' in x]:
                f.write(f'{key}:\r\n')
                for entry in ags_errors[key]:
                    f.write(f'''  Line {entry['line']:<8} {entry['group'].strip('"'):<7} {entry['desc']}\r\n''')
                f.write('\r\n')

            # Write warning messages
            if show_warnings is True:
                for key in [x for x in ags_errors if 'Warning' in x]:
@@ -1070,7 +1079,7 @@ def count_errors(ags_errors):
    warnings_count = 0
    fyi_count = 0
    for key, val in ags_errors.items():
        error_count += len(val) if 'AGS Format Rule' in key else 0
        error_count += len(val) if ('AGS Format Rule' in key) or ('Validator Process Error' in key) else 0
        warnings_count += len(val) if 'Warning' in key else 0
        fyi_count += len(val) if 'FYI' in key else 0

+7 −0
Original line number Diff line number Diff line
@@ -333,6 +333,13 @@ def print_to_screen(ags_errors, show_warnings=False, show_fyi=False):
                console.print(f'''  Line {entry['line']}\t [bold]{entry['group'].strip('"')}[/bold]\t {entry['desc']}''')
            console.print('')

        # Write parsing and process error messages
        for key in [x for x in ags_errors if 'Validator Process Error' in x]:
            console.print(f'''[white underline]{key}[/white underline]:''')
            for entry in ags_errors[key]:
                console.print(f'''  Line {entry['line']}\t [bold]{entry['group'].strip('"')}[/bold]\t {entry['desc']}''')
            console.print('')

        # Print warnings
        if show_warnings is True:
            for key in [x for x in ags_errors if 'Warning' in x]:
+6 −6
Original line number Diff line number Diff line
@@ -760,18 +760,18 @@ def test_checking_without_dictionary_raises_error():
    # force exception to be raised
    error_list = AGS4.check_file('tests/test_files/4.1-rule1-utf8.ags', standard_AGS4_dictionary='tests/test_files/4.1-rule1-utf8.ags')

    assert 'AGS Format Rule ?' in error_list.keys()
    assert error_list['AGS Format Rule ?'][0]['group'] == ''
    assert error_list['AGS Format Rule ?'][0]['desc'] == 'No DICT groups available to proceed with checking. Please ensure '\
    assert 'Validator Process Error' in error_list.keys()
    assert error_list['Validator Process Error'][0]['group'] == ''
    assert error_list['Validator Process Error'][0]['desc'] == 'No DICT groups available to proceed with checking. Please ensure '\
                                                               'the input file has a DICT group or provide file with standard AGS4 dictionary.'


def test_duplicate_groups_raises_error():
    error_list = AGS4.check_file('tests/test_files/DuplicateGroups.ags', standard_AGS4_dictionary='python_ags4/Standard_dictionary_v4_1.ags')

    assert 'AGS Format Rule ?' in error_list.keys()
    assert 'Validator Process Error' in error_list.keys()
    msg = 'SAMP group duplicated in Line 42. Cannot parse file without overwriting data, therefore please combine all duplicate groups first.'
    assert error_list['AGS Format Rule ?'][0]['desc'] == msg
    assert error_list['Validator Process Error'][0]['desc'] == msg


def test_data_summary():