def test_out_of_bound(self): """ test zerofill() out of bound """ self.assertTrue(zerofill(1000, 0) == "1000") self.assertTrue(zerofill(1000, 1) == "1000") self.assertTrue(zerofill(1000, 2) == "1000") self.assertTrue(zerofill(1000, 3) == "1000")
def test_zerofill(self): """ Test zerofill() """ self.assertTrue(zerofill(1, 1) == "1") self.assertTrue(zerofill(1, 2) == "01") self.assertTrue(zerofill(1, 3) == "001") self.assertTrue(zerofill(1, 4) == "0001")
def _set_data_start(self): """ Set the start data index """ header_size = self.NUMBER_RECORD_HEADER * self.ZERO_FILL + 1 index_size = len(self._index[0]) * len(self._index) size = + header_size + index_size self._data_start = zerofill(size)
def _build_data(self): """ Build the file index and data """ current_position = 0 index = [] for key in self._raw_data: index.append(str(key[0])) index_data = self.FIELD_DELIMITER.join( [str(key[0]), zerofill(current_position), zerofill(len('|'.join(key)))]) data = str(key[0]) + self.FIELD_DELIMITER + \ DataFile.FIELD_DELIMITER.join(key[1:]) self._index_data.append(index_data) self._data.append(data) current_position += len(data) self._index = self.FIELD_DELIMITER.join(index)
def _get_header(self): """ Get the file header :return string """ number_record = len(self._index.split(self.FIELD_DELIMITER)) index_length = len(self._index) index_list = self._index.split(self.FIELD_DELIMITER) index_start = zerofill(self.NUMBER_RECORD_HEADER * self.ZERO_FILL) data_length = len(''.join(self._index_data)) return "%s" * self.NUMBER_RECORD_HEADER % ( zerofill(number_record), zerofill(index_length), zerofill(index_start), zerofill(data_length), zerofill(min(index_list)), zerofill(max(index_list)) )