# Path: tools/generator.py
# class DynamicObject:
# class MethodField(str):
#     def method(self):
# def fields_to_strings(fields, this="self.") -> typing.Iterable[str]:
# def form_to_string(form: DynamicObject, class_prefix: str = "") -> str:
# def generate(ded: str, encoding: str = "utf-8") -> DynamicObject:
# def generate_form(form_id: str, reader: csv.DictReader) -> DynamicObject:
# def generate_header(path: str) -> DynamicObject:
# def indent(text, times=1, tab="    "):
# def main():
# def sort_by_starting_position(fields: typing.List[DynamicObject]) \
# def usage():


import csv
import io
import unittest
from tools import generator



class TestGenerator(unittest.TestCase):

    def test_new_format(self):
        a1_ivp_sample = """
"DORDER","ITEM","VAR","PACKET","FLDLENG","COLUMN1","COLUMN2","DTYPE","RANGE","VALUES","VAL1D","VAL2D","VAL3D","VAL4D","VAL5D","VAL6D","VAL7D","VAL8D","VAL9D","VAL10D","MISSVALS","NEWQUEST","BLANKS"
"1","1","REASON","I",1,45,45,1,"1||4","1||2||4||9","To participate in a research study","To have a clinical evaluation","Both (to participate in a research study and to have a clinical evaluation)","Unknown",,,,,,,"9","Primary reason for coming to ADC:",
        """.strip()

        expected = """
fields["REASON"] = nacc.uds3.Field(name="REASON", typename="Num", position=(45, 45), length=1, inclusive_range=(1, 4), allowable_values=['1', '2', '4', '9'], blanks=[])
        """.strip()

        reader = io.StringIO(a1_ivp_sample)
        reader = csv.DictReader(reader)
        forms = generator.generate_form("", reader)

# Path: tools/generator.py
# class DynamicObject:
# class MethodField(str):
#     def method(self):
# def fields_to_strings(fields, this="self.") -> typing.Iterable[str]:
# def form_to_string(form: DynamicObject, class_prefix: str = "") -> str:
# def generate(ded: str, encoding: str = "utf-8") -> DynamicObject:
# def generate_form(form_id: str, reader: csv.DictReader) -> DynamicObject:
# def generate_header(path: str) -> DynamicObject:
# def indent(text, times=1, tab="    "):
# def main():
# def sort_by_starting_position(fields: typing.List[DynamicObject]) \
# def usage():


# Path: tests/test_generator.py
import csv
import io
import unittest
from tools import generator




class TestGenerator(unittest.TestCase):

    def test_new_format(self):
        a1_ivp_sample = """
"DORDER","ITEM","VAR","PACKET","FLDLENG","COLUMN1","COLUMN2","DTYPE","RANGE","VALUES","VAL1D","VAL2D","VAL3D","VAL4D","VAL5D","VAL6D","VAL7D","VAL8D","VAL9D","VAL10D","MISSVALS","NEWQUEST","BLANKS"
"1","1","REASON","I",1,45,45,1,"1||4","1||2||4||9","To participate in a research study","To have a clinical evaluation","Both (to participate in a research study and to have a clinical evaluation)","Unknown",,,,,,,"9","Primary reason for coming to ADC:",
        """.strip()

        expected = """
fields["REASON"] = nacc.uds3.Field(name="REASON", typename="Num", position=(45, 45), length=1, inclusive_range=(1, 4), allowable_values=['1', '2', '4', '9'], blanks=[])
        """.strip()

        reader = io.StringIO(a1_ivp_sample)
        reader = csv.DictReader(reader)
        forms = generator.generate_form("", reader)

        fields = generator.fields_to_strings(forms.fields, "")