Ejemplo n.º 1
0
  def setup_foot_row(self):
    row = row_pb2.Row(type='FFOO', row_number=8)
    record_type_cell = cell_pb2.Cell(
        name='RecordType', cell_type=cell_pb2.STRING, string_value=['FFOO'])
    number_of_lines_cell = cell_pb2.Cell(
        name='NumberOfLines', cell_type=cell_pb2.INTEGER, integer_value=[123])

    row.cells.extend([record_type_cell, number_of_lines_cell])
    return row
Ejemplo n.º 2
0
  def get_cell_object(self, cell_validator, cell_parsed_data):
    """Parses the cell data to a protocol buffer cell object.

    Args:
      cell_validator: Instance of a subclass of
                      cell_validators.BaseCellValidator.
      cell_parsed_data: The data from the cell, either an integer, float, string
        or boolean.

    Returns:
      A cell_pb2.Cell object.
    """
    cell_proto = cell_pb2.Cell(
        name=cell_validator.cell_name, cell_type=cell_validator.get_cell_type())
    if not isinstance(cell_parsed_data, list):
      cell_parsed_data = [cell_parsed_data]
    if cell_proto.cell_type == cell_pb2.STRING:
      cell_proto.string_value.extend(cell_parsed_data)
    elif cell_proto.cell_type == cell_pb2.INTEGER:
      cell_proto.integer_value.extend(cell_parsed_data)
    elif cell_proto.cell_type == cell_pb2.DECIMAL:
      cell_proto.decimal_value.extend(cell_parsed_data)
    elif cell_proto.cell_type == cell_pb2.BOOLEAN:
      cell_proto.boolean_value.extend(cell_parsed_data)
    return cell_proto
Ejemplo n.º 3
0
 def test_get_cell_object(self):
   cell_validator = cell_validators.StringValidator('ServiceDescription',
                                                    False, False)
   cell = cell_pb2.Cell()
   cell.name = 'ServiceDescription'
   cell.cell_type = cell_pb2.STRING
   cell.string_value.append('yt')
   parser = self._get_file_parser()
   self.assertEqual(parser.get_cell_object(cell_validator, 'yt'), cell)