Beispiel #1
0
 def test_can_read_fixed_rows(self):
     cid_path = dev_test.path_to_test_cid('customers_fixed.ods')
     customer_cid = interface.Cid(cid_path)
     fixed_path = dev_test.path_to_test_data('valid_customers_fixed.txt')
     field_names_and_lengths = interface.field_names_and_lengths(customer_cid)
     rows = list(rowio.fixed_rows(fixed_path, customer_cid.data_format.encoding, field_names_and_lengths))
     self.assertNotEqual(0, len(rows))
     for row_index in range(len(rows) - 1):
         row = rows[row_index]
         next_row = rows[row_index + 1]
         self.assertNotEqual(0, len(row))
         self.assertEqual(len(row), len(next_row))
Beispiel #2
0
 def _raw_rows(self):
     data_format = self.cid.data_format
     format = data_format.format
     if format == data.FORMAT_EXCEL:
         return rowio.excel_rows(self._source_data_stream_or_path, data_format.sheet)
     elif format == data.FORMAT_DELIMITED:
         return rowio.delimited_rows(self._source_data_stream_or_path, data_format)
     elif format == data.FORMAT_FIXED:
         return rowio.fixed_rows(
             self._source_data_stream_or_path, data_format.encoding, interface.field_names_and_lengths(self.cid),
             data_format.line_delimiter)
     elif format == data.FORMAT_ODS:
         return rowio.ods_rows(self._source_data_stream_or_path, data_format.sheet)
     else:
         assert False, 'format=%r' % format
Beispiel #3
0
 def _raw_rows(self):
     data_format = self.cid.data_format
     format = data_format.format
     if format == data.FORMAT_EXCEL:
         return rowio.excel_rows(self._source_data_stream_or_path, data_format.sheet)
     elif format == data.FORMAT_DELIMITED:
         return rowio.delimited_rows(self._source_data_stream_or_path, data_format)
     elif format == data.FORMAT_FIXED:
         return rowio.fixed_rows(
             self._source_data_stream_or_path, data_format.encoding, interface.field_names_and_lengths(self.cid),
             data_format.line_delimiter)
     elif format == data.FORMAT_ODS:
         return rowio.ods_rows(self._source_data_stream_or_path, data_format.sheet)
     else:
         assert False, 'format=%r' % format
Beispiel #4
0
    def __init__(self, cid_or_path, target):
        assert cid_or_path is not None
        assert target is not None

        super(Writer, self).__init__(cid_or_path)

        data_format = cid_or_path.data_format
        assert self.cid.data_format.is_valid
        self._header = data_format.header
        self._delegated_writer = None
        if data_format.format == data.FORMAT_DELIMITED:
            self._delegated_writer = rowio.DelimitedRowWriter(target, data_format)
        elif data_format.format == data.FORMAT_FIXED:
            self._field_names_and_lengths = interface.field_names_and_lengths(self.cid)
            self._delegated_writer = rowio.FixedRowWriter(target, data_format, self._field_names_and_lengths)
        else:
            raise NotImplementedError('data_format=%r' % data_format.format)
Beispiel #5
0
    def __init__(self, cid_or_path, target):
        assert cid_or_path is not None
        assert target is not None

        super(Writer, self).__init__(cid_or_path)

        data_format = cid_or_path.data_format
        assert self.cid.data_format.is_valid
        self._header = data_format.header
        self._delegated_writer = None
        if data_format.format == data.FORMAT_DELIMITED:
            self._delegated_writer = rowio.DelimitedRowWriter(target, data_format)
        elif data_format.format == data.FORMAT_FIXED:
            self._field_names_and_lengths = interface.field_names_and_lengths(self.cid)
            self._delegated_writer = rowio.FixedRowWriter(target, data_format, self._field_names_and_lengths)
        else:
            raise NotImplementedError('data_format=%r' % data_format.format)