def setUp(self) -> None:
     self.file_rows = [
         FileRow({'name': 'Aaron'}),
         FileRow({'age': '40'}),
         FileRow({'dob': '06/12/1980'})
     ]
     self.file_instance = FileInstance('file_name', self.file_rows)
 def setUp(self) -> None:
     self.file_name = 'file_name'
     self.file_rows = [
         FileRow({'name': 'Dominic'}),
         FileRow({
             'age': '44',
             'dob': '11/11/1977'
         })
     ]
 def test_five(self):
     file_rows = [
         FileRow({}),
         FileRow({}),
         FileRow({}),
         FileRow({}),
         FileRow({})
     ]
     self.assertTrue(len(FileInstance('', file_rows)) == 5)
 def setUp(self) -> None:
     self.row = FileRow({
         'name': 'Xander',
         'age': '6',
         'addr': '123 Main St',
         'dob': '11/22/63'
     })
 def test_five(self):
     row = FileRow({
         'key1': 'value',
         'key2': 'value',
         'key3': 'value',
         'key4': 'value',
         'key5': 'value'
     })
     self.assertEqual(5, len(row))
Exemplo n.º 6
0
 def process_fixed_line(self, line):
     record = {}
     for field_def in self.file_definition.field_definitions:
         end_position = field_def.start_position + field_def.field_length
         if end_position > len(line.rstrip()):
             raise IndexError(
                 f'field {field_def.field_name} extends past the end of line'
             )
         record[field_def.field_name] = line[
             field_def.start_position:end_position].rstrip()
     return FileRow(record)
Exemplo n.º 7
0
    def process_file_records(self, file: IO):
        tree = fromstring(''.join(file.readlines()))

        file_rows = []
        for item in tree.findall(
                f'./{self.file_definition.record_element_name}'):
            record = {}
            for field_def in self.file_definition.field_definitions:
                record[field_def.field_name] = item.find(
                    f'{field_def.field_name}').text
            file_rows.append(FileRow(record))

        return file_rows
Exemplo n.º 8
0
    def process_delimited_line(self, line):
        fields = [
            field.rstrip()
            for field in line.split(self.file_definition.delimiter)
        ]
        record = {}

        field_count = len(self.file_definition.field_definitions)
        if field_count != len(fields):
            raise OSError('File records do not match file definition')

        for i in range(0, field_count):
            record[self.file_definition.field_definitions[i].field_name] = \
                fields[self.file_definition.field_definitions[i].position_in_row]
        return FileRow(record)
 def setUp(self) -> None:
     self.file_rows = [
         FileRow({'name': 'John'}),
         FileRow({'name': 'Joe'}),
         FileRow({'name': 'Jeff'}),
         FileRow({'name': 'Adam'}),
         FileRow({'name': 'Alex'}),
         FileRow({'name': 'Steve'})
     ]
     self.file_instance = FileInstance('', self.file_rows)
 def setUp(self) -> None:
     self.file_row = FileRow({'name': 'Alex', 'age': '27'})
     self.file_instance = FileInstance('file_name', [self.file_row])
 def test_empty_dict(self):
     file_row = FileRow({})
     self.assertTrue(len(file_row.fields) == 0)
 def test_negative_contains(self):
     self.assertFalse(FileRow({'name': 'Jeff'}) in self.file_instance)
 def test_one(self):
     row = FileRow({'key': 'value'})
     self.assertEqual(1, len(row))
 def test_zero(self):
     row = FileRow({})
     self.assertEqual(0, len(row))
 def test_different_file_rows(self):
     self.assertFalse(
         FileInstance(self.file_name, self.file_rows) == FileInstance(
             self.file_name, [FileRow({})]))
 def test_positive_not_contains(self):
     self.assertTrue(FileRow({'name': 'Jeff'}) not in self.file_instance)
 def test_file_name_and_file_rows(self):
     file_row = FileRow({'name': 'John'})
     file_instance = FileInstance('file_name', [file_row])
     self.assertEqual('file_name', file_instance.file_name)
     self.assertTrue(len(file_instance.file_rows) == 1)
     self.assertEqual([file_row], file_instance.file_rows)
 def test_one(self):
     file_row = FileRow({})
     self.assertTrue(len(FileInstance('', [file_row])) == 1)
 def test_none(self):
     file_row = FileRow(None)
     self.assertTrue(file_row.fields is None)
 def setUp(self) -> None:
     self.file_row = FileRow({'name': 'Aaron', 'age': '26'})
 def test_non_empty_dict(self):
     file_row = FileRow({'key': 'value'})
     self.assertTrue(len(file_row.fields) == 1)
     self.assertEqual('value', file_row.fields['key'])