def check_blanks(packet): """ Parses rules for when each field should be blank and then checks them """ pattern = re.compile(r"Blank if Question \d+ (\w+) (ne|=) (\d+)") warnings = [] for form in packet: # Find all fields that: # 1) have blanking rules; and # 2) aren't blank. for field in [ f for f in form.fields.itervalues() if f.blanks and not empty(f) ]: for rule in field.blanks: r = blanks.convert_rule_to_python(field.name, rule) if r(packet): warnings.append( "'%s' is '%s' with length '%s', but should be blank: '%s'." % (field.name, field.value, len(field.value), rule)) # "'%s' is '%s' with length '%s', but should be blank: '%s'. Test form: '%s'" % # (field.name, field.value, len(field.value), rule, form.form_name)) return warnings
def check_blanks(packet: uds3_packet.Packet, options: argparse.Namespace) \ -> typing.List: """ Parses rules for when each field should be blank and then checks them """ warnings = [] for form in packet: # Find all fields that: # 1) have blanking rules; and # 2) aren't blank. for field in [ f for f in form.fields.values() if f.blanks and not empty(f) ]: for rule in field.blanks: if not options.lbd and not options.ftld and not options.csf: r = blanks_uds3.convert_rule_to_python(field.name, rule) if r(packet): warnings.append( "'%s' is '%s' with length '%s', but should be" " blank: '%s'." % (field.name, field.value, len(field.value), rule)) if options.lbd: t = blanks_lbd.convert_rule_to_python(field.name, rule) if t(packet): warnings.append( "'%s' is '%s' with length '%s', but should be" " blank: '%s'." % (field.name, field.value, len(field.value), rule)) if options.ftld: s = blanks_ftld.convert_rule_to_python(field.name, rule) if s(packet): warnings.append( "'%s' is '%s' with length '%s', but should be" " blank: '%s'." % (field.name, field.value, len(field.value), rule)) if options.csf: q = blanks_csf.convert_rule_to_python(field.name, rule) if q(packet): warnings.append( "'%s' is '%s' with length '%s', but should be" " blank: '%s'." % (field.name, field.value, len(field.value), rule)) return warnings
def check_blanks(packet): """ Parses rules for when each field should be blank and then checks them """ pattern = re.compile(r"Blank if Question \d+ (\w+) (ne|=) (\d+)") warnings = [] for form in packet: # Find all fields that: # 1) have blanking rules; and # 2) aren't blank. for field in form.fields.itervalues(): # Ad-hoc warning from __init__.py in nacc\uds3 statement "len(value) != end-start+1:" value = field.value start, end = field.position start -= 1 end -= 1 if len(value) != end-start+1: warnings.append("Data error [Must Fix!!]: Length of field {} with value {} is not valid. {} != {}".format(field.name, value, len(value), end-start+1)) ## This part is to see which forms have been processed, but the output.txt has that too #for rule in field.blanks: # print("form processed: '%s' " % (form.form_name)) for field in [f for f in form.fields.itervalues() if f.blanks and not empty(f)]: for rule in field.blanks: r = blanks.convert_rule_to_python(field.name, rule) if r(packet): warnings.append( "'%s' is '%s' with length '%s', but should be blank: '%s'." % (field.name, field.value, len(field.value), rule)) # "'%s' is '%s' with length '%s', but should be blank: '%s'. Test form: '%s'" % # (field.name, field.value, len(field.value), rule, form.form_name)) return warnings