Exemplo n.º 1
0
def validate(fp, verbose=False, validator_name=None, allow_warnings=False):
    try:
        validator_class = Registry.find(validator_name)
    except KeyError:
        sys.stderr.write('Validator %s not found.' % validator_name)
        return 4

    val = GeoFeedValidator(fp,
                           validator=validator_class,
                           store_raw_records=True)
    write_console('Validating feed: ')
    result = val.validate()
    write_console_line('DONE.')

    records_with_warnings = 0
    records_with_errors = 0
    for record in result.records:
        line_status = 'OK'
        if record.has_errors or record.has_warnings:
            line_status = '%s%s' % ('E' if record.has_errors else ' ',
                                    'W' if record.has_warnings else ' ')

            if record.has_errors:
                records_with_errors += 1
            if records_with_warnings:
                records_with_warnings += 1

        if verbose or record.has_errors or record.has_warnings:
            write_console_line('[%s %d %s] %s', val.record_name,
                               record.record_no, line_status, record.raw)

        for field_result in record.field_results:
            for err_string in field_result.errors:
                write_console_line('  E %s - %s', field_result.field.name,
                                   err_string)
            for warn_string in field_result.warnings:
                write_console_line('  W %s - %s', field_result.field.name,
                                   warn_string)

    write_console_line('%s%ss: %d TOTAL, %d VALID, %d ERROR, %d WARNING',
                       val.record_name[0].upper(), val.record_name[1:],
                       len(result.records),
                       len(result.records) - records_with_errors,
                       records_with_errors, records_with_warnings)
    write_console_line('Counts: %d ERROR%s, %d WARNING%s', result.error_count,
                       's' if result.error_count != 1 else '',
                       result.warning_count,
                       's' if result.warning_count != 1 else '')

    if val.is_valid(allow_warnings=allow_warnings):
        write_console_line('*** Feed VALID ***')
        return 0
    write_console_line('*** Feed INVALID ***')
    return 3
def validate(fp, verbose=False, validator_name=None, allow_warnings=False):
    try:
        validator_class = Registry.find(validator_name)
    except KeyError:
        sys.stderr.write('Validator %s not found.' % validator_name)
        return 4

    val = GeoFeedValidator(fp, validator=validator_class, store_raw_records=True)
    write_console('Validating feed: ')
    result = val.validate()
    write_console_line('DONE.')

    records_with_warnings = 0
    records_with_errors = 0
    for record in result.records:
        line_status = 'OK'
        if record.has_errors or record.has_warnings:
            line_status = '%s%s' % ('E' if record.has_errors else ' ',
                                    'W' if record.has_warnings else ' ')

            if record.has_errors:
                records_with_errors += 1
            if records_with_warnings:
                records_with_warnings += 1

        if verbose or record.has_errors or record.has_warnings:
            write_console_line('[%s %d %s] %s', val.record_name, record.record_no, line_status, record.raw)

        for field_result in record.field_results:
            for err_string in field_result.errors:
                write_console_line('  E %s - %s', field_result.field.name, err_string)
            for warn_string in field_result.warnings:
                write_console_line('  W %s - %s', field_result.field.name, warn_string)

    write_console_line('%s%ss: %d TOTAL, %d VALID, %d ERROR, %d WARNING', val.record_name[0].upper(),
                       val.record_name[1:], len(result.records), len(result.records)-records_with_errors,
                       records_with_errors, records_with_warnings)
    write_console_line('Counts: %d ERROR%s, %d WARNING%s',
                       result.error_count, 's' if result.error_count != 1 else '',
                       result.warning_count, 's' if result.warning_count != 1 else '')

    if val.is_valid(allow_warnings=allow_warnings):
        write_console_line('*** Feed VALID ***')
        return 0
    write_console_line('*** Feed INVALID ***')
    return 3
Exemplo n.º 3
0
 def test_0010_fields(self):
     validator = GeoFeedValidator('')
     self.assertEqual(list(), validator.fields)
     validator.validate()
     self.assertEqual(validator._validator.FIELDS, validator.fields)
Exemplo n.º 4
0
 def test_0009_record_name(self):
     validator = GeoFeedValidator('')
     self.assertEqual('???', validator.record_name)
     validator.validate()
     self.assertEqual(validator._validator.RECORD_NAME,
                      validator.record_name)
Exemplo n.º 5
0
 def test_0008_validate_by_is_valid(self):
     validator = GeoFeedValidator('')
     self.assertTrue(validator.is_valid(allow_warnings=False))
     self.assertIsInstance(validator.validate(), ValidationResult)
Exemplo n.º 6
0
 def test_0007_validate(self):
     validator = GeoFeedValidator('')
     res = validator.validate()
     self.assertIsInstance(res, ValidationResult)
     self.assertTrue(res.is_valid(allow_warnings=False))
Exemplo n.º 7
0
 def test_0010_fields(self):
     validator = GeoFeedValidator('')
     self.assertEqual(list(), validator.fields)
     validator.validate()
     self.assertEqual(validator._validator.FIELDS, validator.fields)
Exemplo n.º 8
0
 def test_0009_record_name(self):
     validator = GeoFeedValidator('')
     self.assertEqual('???', validator.record_name)
     validator.validate()
     self.assertEqual(validator._validator.RECORD_NAME, validator.record_name)
Exemplo n.º 9
0
 def test_0008_validate_by_is_valid(self):
     validator = GeoFeedValidator('')
     self.assertTrue(validator.is_valid(allow_warnings=False))
     self.assertIsInstance(validator.validate(), ValidationResult)
Exemplo n.º 10
0
 def test_0007_validate(self):
     validator = GeoFeedValidator('')
     res = validator.validate()
     self.assertIsInstance(res, ValidationResult)
     self.assertTrue(res.is_valid(allow_warnings=False))