def setUp(self): self.file_descriptor = FileDescriptor( [ DetailRowDescriptor([ CharColumn('row_type', 1), CharColumn('name', 60), RightCharColumn('right_name', 60), PositiveIntegerColumn('positive_interger', 9), PositiveDecimalColumn('positive_decimal', 9), DateTimeColumn('datetime'), DateColumn('date'), TimeColumn('time'), ]) ], HeaderRowDescriptor([ CharColumn('row_type', 1), CharColumn('filetype', 5), CharColumn('fill', 157), ]), FooterRowDescriptor([ CharColumn('row_type', 1), PositiveIntegerColumn('detail_count', 4), PositiveIntegerColumn('row_count', 4), CharColumn('fill', 154), ]), ) with open('/src/tests/assets/example01.json') as f: self.example01_json = f.read() with open('/src/tests/assets/example01.md') as f: self.example01_markdown = f.read()
def test_constructor_set_attr(self): t = CharColumn("type", 1) fd = FileDescriptor([DetailRowDescriptor([t])], HeaderRowDescriptor([t]), FooterRowDescriptor([t])) self.assertIsInstance(fd, FileDescriptor) self.assertIsInstance(fd.header, HeaderRowDescriptor) self.assertIsInstance(fd.footer, FooterRowDescriptor) self.assertIsInstance(fd.details, list)
def test_constructor_all_right(self): f = CharColumn("type", 1) self.assertIsInstance(FileDescriptor([DetailRowDescriptor([f])]), FileDescriptor) self.assertIsInstance(FileDescriptor([DetailRowDescriptor([f])], HeaderRowDescriptor([f])), FileDescriptor) self.assertIsInstance(FileDescriptor([DetailRowDescriptor([f])], HeaderRowDescriptor([f]), FooterRowDescriptor([f])), FileDescriptor)
def setUp(self): self.file_descriptor = FileDescriptor( [ DetailRowDescriptor([ CharColumn('row_type', 1), CharColumn('name', 60), RightCharColumn('right_name', 60), PositiveIntegerColumn('positive_interger', 9), PositiveDecimalColumn('positive_decimal', 9), DateTimeColumn('datetime'), DateColumn('date'), TimeColumn('time'), ]) ], HeaderRowDescriptor([ CharColumn('row_type', 1), CharColumn('filetype', 3), CharColumn('fill', 159), ]), FooterRowDescriptor([ CharColumn('row_type', 1), PositiveIntegerColumn('detail_count', 4), PositiveIntegerColumn('row_count', 4), CharColumn('fill', 154), ]), ) with open('/src/tests/assets/example01.json') as f: self.example01_json = f.read() with open('/src/tests/assets/example01.md') as f: self.example01_markdown = f.read() with open('/src/tests/assets/example01_wrong_line_size.fwf') as f: self.example01_wrong_line_size = f.read() with open('/src/tests/assets/example01_are_right.fwf') as f: self.example01_are_right = f.read() with open('/src/tests/assets/example01_are_right_win.fwf') as f: self.example01_are_right_win = f.read() self.example01_are_right_lst = [ "1FWF " " \n", "2KELSON DA COSTA MEDEIROS " " KELSON DA COSTA MEDEIROS123456789123456789200102282359200102282359\n", "2KELSON DA COSTA MEDEIROS " " KELSON DA COSTA MEDEIROS000000000000000000000000000000000000000000\n", "900020003 " " \n" ] self.example01_are_right_expected = [{ 'row_type': '1', 'filetype': 'FWF', 'fill': '' }, { 'row_type': '2', 'name': 'KELSON DA COSTA MEDEIROS', 'right_name': 'KELSON DA COSTA MEDEIROS', 'positive_interger': 123456789, 'positive_decimal': 1234567.89, 'datetime': datetime.datetime(228, 1, 20, 23, 59), 'date': datetime.date(228, 1, 20), 'time': datetime.time(23, 59) }, { 'row_type': '2', 'name': 'KELSON DA COSTA MEDEIROS', 'right_name': 'KELSON DA COSTA MEDEIROS', 'positive_interger': 0, 'positive_decimal': 0.0, 'datetime': None, 'date': None, 'time': None }, { 'row_type': '9', 'detail_count': 2, 'row_count': 3, 'fill': '' }]
def test_constructor_set_attr(self): rd = FooterRowDescriptor([CharColumn("type", 1), CharColumn("name", 10)]) self.assertIsInstance(rd.columns, list) self.assertEqual(2, len(rd.columns))
def test_constructor_all_right(self): self.assertIsInstance(FooterRowDescriptor([CharColumn("type", 1)]), FooterRowDescriptor)
RightCharColumn("right_name", 60), PositiveIntegerColumn("positive_interger", 9), PositiveDecimalColumn("positive_decimal", 9, 2), DateTimeColumn("datetime", "%d%m%Y%H%M"), DateColumn("date", "%d%m%Y"), TimeColumn("datetime", "%H%M") ]) ], HeaderRowDescriptor([ CharColumn("row_type", 1), CharColumn("filetype", 3), CharColumn("fill", 159) ]), FooterRowDescriptor([ CharColumn("row_type", 1), PositiveIntegerColumn("detail_count", 4), PositiveIntegerColumn("row_count", 4), CharColumn("fill", 154) ])) FWF_EXPECTED = [{ 'row_type': '1', 'filetype': 'FWF', 'fill': '' }, { 'row_type': '2', 'name': 'KELSON DA COSTA MEDEIROS', 'right_name': 'KELSON DA COSTA MEDEIROS', 'positive_interger': 123456789, 'positive_decimal': 1234567.89, 'datetime': datetime.time(23, 59), 'date': datetime.date(228, 1, 20) }, {