# Path: nacc/uds3/m/builder.py
# def build_uds3_m_form(record):
# def update_header(record, packet):
# def parse_date(date, DMY_choice):
# def subject_deceased(status):
# def subject_discont(status):
# 
# 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/packet.py
# class Packet(list):
#     def __init__(self):
#     def __getitem__(self, key):
# 
# Path: nacc/uds3/m/forms.py
# CURRENT_YEAR = date.today().year
# def header_fields():  # may not need the headers.
#     def __init__(self):
# class FormM(nacc.uds3.FieldBag):


import unittest
from nacc.uds3.m import builder as m_builder
from nacc.uds3 import blanks
from nacc.uds3 import packet as m_packet
from nacc.uds3.m import forms as m_form

class TestM1(unittest.TestCase):
    # add tests in class
    def test_m1_death_date_accept(self):
        """ death date format interpreter accept correct dates """
        date = ['12/12/2012', '12-12-2012', '2012/12/12', '2012-12-12']
        date_parsed = ['12', '12', '2012', '12', '12', '2012', '12', '12',
                       '2012', '12', '12', '2012']
        record = make_blank_m()
        out = []
        for x in date:
            record['DECEASED'] = '1'
            record['DEATHMO'] = m_builder.parse_date(x, 'M')
            record['DEATHDY'] = m_builder.parse_date(x, 'D')
            record['DEATHYR'] = m_builder.parse_date(x, 'Y')
            out += [str(record['DEATHMO']), str(record['DEATHDY']),
                    str(record['DEATHYR'])]
        self.assertEqual(date_parsed, out)

    def test_m1_death_date_reject(self):
        """ death date format interpreter rejects wrong dates """
        date = ['12/12/2012', '12-1212', '12/2012/12', '2012-12-12']
        date_parsed = ['12', '12', '2012', '12', '12', '2012', '12', '12',
                       '2012', '12', '12', '2012']
        record = make_blank_m()
        out = []
        with self.assertRaises(ValueError):
            for x in date:
                record['DECEASED'] = '1'
                record['DEATHMO'] = m_builder.parse_date(x, 'M')

# Path: nacc/uds3/m/builder.py
# def build_uds3_m_form(record):
# def update_header(record, packet):
# def parse_date(date, DMY_choice):
# def subject_deceased(status):
# def subject_discont(status):
# 
# 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/packet.py
# class Packet(list):
#     def __init__(self):
#     def __getitem__(self, key):
# 
# Path: nacc/uds3/m/forms.py
# CURRENT_YEAR = date.today().year
# def header_fields():  # may not need the headers.
#     def __init__(self):
# class FormM(nacc.uds3.FieldBag):


# Path: tests/test_m1.py
import unittest
from nacc.uds3.m import builder as m_builder
from nacc.uds3 import blanks
from nacc.uds3 import packet as m_packet
from nacc.uds3.m import forms as m_form


class TestM1(unittest.TestCase):
    # add tests in class
    def test_m1_death_date_accept(self):
        """ death date format interpreter accept correct dates """
        date = ['12/12/2012', '12-12-2012', '2012/12/12', '2012-12-12']
        date_parsed = ['12', '12', '2012', '12', '12', '2012', '12', '12',
                       '2012', '12', '12', '2012']
        record = make_blank_m()
        out = []
        for x in date:
            record['DECEASED'] = '1'
            record['DEATHMO'] = m_builder.parse_date(x, 'M')
            record['DEATHDY'] = m_builder.parse_date(x, 'D')
            record['DEATHYR'] = m_builder.parse_date(x, 'Y')
            out += [str(record['DEATHMO']), str(record['DEATHDY']),
                    str(record['DEATHYR'])]
        self.assertEqual(date_parsed, out)

    def test_m1_death_date_reject(self):
        """ death date format interpreter rejects wrong dates """
        date = ['12/12/2012', '12-1212', '12/2012/12', '2012-12-12']
        date_parsed = ['12', '12', '2012', '12', '12', '2012', '12', '12',
                       '2012', '12', '12', '2012']
        record = make_blank_m()
        out = []
        with self.assertRaises(ValueError):
            for x in date:
                record['DECEASED'] = '1'
                record['DEATHMO'] = m_builder.parse_date(x, 'M')

                record['DEATHDY'] = m_builder.parse_date(x, 'D')