# Path: nacc/redcap2nacc.py
# def check_blanks(packet: uds3_packet.Packet, options: argparse.Namespace) \
# def blank_warnings(warnings, fieldname, formid, value, length, rule):
# def check_characters(packet: uds3_packet.Packet) -> typing.List:
# def check_for_bad_characters(field: Field) -> typing.List:
# def check_redcap_event(options, record) -> bool:
# def check_single_select(packet: uds3_packet.Packet):
# def empty(field):
# def exclusive(packet, fields, value_to_check=1):
# def set_blanks_to_zero(packet):
#     def set_to_zero_if_blank(*field_names):
# def convert(fp, options, out=sys.stdout, err=sys.stderr):
# def parse_args(args=None):
# def main():
# 
# Path: nacc/uds3/blanks.py
# def convert_rule_to_python(name: str, rule: str) -> bool:
# def extract_blanks(csvfile):
# def _blanking_rule_check_single_value(key, eq, value):
#     def should_be_blank(packet):
# def _blanking_rule_check_within_range(key, eq, start, stop):
#     def should_be_blank(packet):
# def _blanking_rule_dummy():
# def _blanking_rule_ftldsubt():
# def _blanking_rule_learned():
# def _blanking_rule_telmile():
# def set_zeros_to_blanks(packet):
#     def set_to_blank_if_zero(*field_names):
# def main():
# 
# Path: nacc/uds3/tfp/v3_2/builder.py
# def build_uds3_tfp_new_form(record, err=sys.stderr):
#     """ Converts REDCap CSV data into a packet (list of TFP V3.2 Form objects) """
#     packet = tfp_new_packet.Packet()
# 
#     # Set up the forms
#     add_z1x(record, packet)
#     add_t1(record, packet)
#     add_a1(record, packet)
#     add_a2(record, packet)
#     try:
#         z1x_complete = record['tvp_z1x_checklist_complete']
#     except KeyError:
#         try:
#             z1x_complete = record['tfp_z1x_complete']
#         except KeyError:
#             try:
#                 z1x_complete = record['tele_z1x_complete']
#             except KeyError:
#                 z1x_complete = '0'
#     if z1x_complete in ['1', '2']:
#         try:
#             if record['tele_a3sub'] == '1':
#                 add_a3(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['tele_a4sub'] == '1':
#                 add_a4(record, packet)
#         except KeyError:
#             pass
#         add_b4(record, packet)
#         try:
#             if record['tele_b5sub'] == '1':
#                 add_b5(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['tele_b6sub'] == '1':
#                 add_b6(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['tele_b7sub'] == '1':
#                 add_b7(record, packet)
#         except KeyError:
#             pass
# 
#         add_b9(record, packet)
#         try:
#             if record['tele_c2sub'] == '1':
#                 add_c2t(record, packet)
#         except KeyError:
#             pass
#     add_d1(record, packet)
#     add_d2(record, packet)
#     try:
#         clsform.add_cls(record, packet, tfp_new_forms)
#     except KeyError:
#         pass
#     update_header(record, packet)
# 
#     return packet


import unittest
from nacc import redcap2nacc
from nacc.uds3 import blanks
from nacc.uds3.tfp.v3_2.builder import build_uds3_tfp_new_form

    def test_for_single_blanking_rule_returned(self):
        '''
        Have it make sure that only one error is returned from a list of
        rules when not working with special cases (special cases need a
        fix in a later feature branch)
        '''
        record = make_filled_form()
        record['tele_mocalan'] = '2'
        record['tele_mocalanx'] = 'a'
        fpacket = build_uds3_tfp_new_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(fpacket, self.options)
        expected = ["MOCALANX in form C2  is 'a                               "
                    "                            ' with length '60', but"
                    " should be blank: 'Blank if 1b MOCALAN = 2'."]
        self.assertEqual(warnings, expected)

    def test_for_special_case_FTLDSUBT(self):
        '''
        FTLDSUBT in D1 should be blank if all of the parts of 14 is not marked
        as '1'
        '''
        record = make_filled_form()
        record['tele_psp'] = ''
        record['tele_cort'] = ''
        record['tele_ftldmo'] = ''
        record['tele_ftldnos'] = ''
        record['tele_ftldsubt'] = '1'

# Path: nacc/redcap2nacc.py
# def check_blanks(packet: uds3_packet.Packet, options: argparse.Namespace) \
# def blank_warnings(warnings, fieldname, formid, value, length, rule):
# def check_characters(packet: uds3_packet.Packet) -> typing.List:
# def check_for_bad_characters(field: Field) -> typing.List:
# def check_redcap_event(options, record) -> bool:
# def check_single_select(packet: uds3_packet.Packet):
# def empty(field):
# def exclusive(packet, fields, value_to_check=1):
# def set_blanks_to_zero(packet):
#     def set_to_zero_if_blank(*field_names):
# def convert(fp, options, out=sys.stdout, err=sys.stderr):
# def parse_args(args=None):
# def main():
# 
# Path: nacc/uds3/blanks.py
# def convert_rule_to_python(name: str, rule: str) -> bool:
# def extract_blanks(csvfile):
# def _blanking_rule_check_single_value(key, eq, value):
#     def should_be_blank(packet):
# def _blanking_rule_check_within_range(key, eq, start, stop):
#     def should_be_blank(packet):
# def _blanking_rule_dummy():
# def _blanking_rule_ftldsubt():
# def _blanking_rule_learned():
# def _blanking_rule_telmile():
# def set_zeros_to_blanks(packet):
#     def set_to_blank_if_zero(*field_names):
# def main():
# 
# Path: nacc/uds3/tfp/v3_2/builder.py
# def build_uds3_tfp_new_form(record, err=sys.stderr):
#     """ Converts REDCap CSV data into a packet (list of TFP V3.2 Form objects) """
#     packet = tfp_new_packet.Packet()
# 
#     # Set up the forms
#     add_z1x(record, packet)
#     add_t1(record, packet)
#     add_a1(record, packet)
#     add_a2(record, packet)
#     try:
#         z1x_complete = record['tvp_z1x_checklist_complete']
#     except KeyError:
#         try:
#             z1x_complete = record['tfp_z1x_complete']
#         except KeyError:
#             try:
#                 z1x_complete = record['tele_z1x_complete']
#             except KeyError:
#                 z1x_complete = '0'
#     if z1x_complete in ['1', '2']:
#         try:
#             if record['tele_a3sub'] == '1':
#                 add_a3(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['tele_a4sub'] == '1':
#                 add_a4(record, packet)
#         except KeyError:
#             pass
#         add_b4(record, packet)
#         try:
#             if record['tele_b5sub'] == '1':
#                 add_b5(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['tele_b6sub'] == '1':
#                 add_b6(record, packet)
#         except KeyError:
#             pass
#         try:
#             if record['tele_b7sub'] == '1':
#                 add_b7(record, packet)
#         except KeyError:
#             pass
# 
#         add_b9(record, packet)
#         try:
#             if record['tele_c2sub'] == '1':
#                 add_c2t(record, packet)
#         except KeyError:
#             pass
#     add_d1(record, packet)
#     add_d2(record, packet)
#     try:
#         clsform.add_cls(record, packet, tfp_new_forms)
#     except KeyError:
#         pass
#     update_header(record, packet)
# 
#     return packet


# Path: tests/test_tfp_blanks.py
import unittest
from nacc import redcap2nacc
from nacc.uds3 import blanks
from nacc.uds3.tfp.v3_2.builder import build_uds3_tfp_new_form


    def test_for_single_blanking_rule_returned(self):
        '''
        Have it make sure that only one error is returned from a list of
        rules when not working with special cases (special cases need a
        fix in a later feature branch)
        '''
        record = make_filled_form()
        record['tele_mocalan'] = '2'
        record['tele_mocalanx'] = 'a'
        fpacket = build_uds3_tfp_new_form(record)
        warnings = []

        warnings = redcap2nacc.check_blanks(fpacket, self.options)
        expected = ["MOCALANX in form C2  is 'a                               "
                    "                            ' with length '60', but"
                    " should be blank: 'Blank if 1b MOCALAN = 2'."]
        self.assertEqual(warnings, expected)

    def test_for_special_case_FTLDSUBT(self):
        '''
        FTLDSUBT in D1 should be blank if all of the parts of 14 is not marked
        as '1'
        '''
        record = make_filled_form()
        record['tele_psp'] = ''
        record['tele_cort'] = ''
        record['tele_ftldmo'] = ''
        record['tele_ftldnos'] = ''
        record['tele_ftldsubt'] = '1'

        fpacket = build_uds3_tfp_new_form(record)