Exemplo n.º 1
0
    def _to_data_matrix(self):
        from collections import OrderedDict

        data_matrix = []

        for row_idx, row in enumerate(self._ltsv_input_stream):
            if typepy.is_empty_sequence(row):
                continue

            ltsv_record = OrderedDict()
            for col_idx, ltsv_item in enumerate(row.strip().split("\t")):
                try:
                    label, value = ltsv_item.split(":")
                except ValueError:
                    raise DataError(
                        "invalid lstv item found: line={}, col={}, item='{}'".
                        format(row_idx, col_idx, ltsv_item))

                label = label.strip('"')

                try:
                    pv.validate_ltsv_label(label)
                except (pv.NullNameError, pv.InvalidCharError):
                    raise InvalidHeaderNameError(
                        "invalid label found (acceptable chars are [0-9A-Za-z_.-]): "
                        "line={}, col={}, label='{}'".format(
                            row_idx, col_idx, label))

                ltsv_record[label] = value

            data_matrix.append(ltsv_record)

        # using generator to prepare for future enhancement to support
        # iterative load.
        yield data_matrix
Exemplo n.º 2
0
 def test_exception_invalid_char(self, value):
     with pytest.raises(ValidationError) as e:
         validate_ltsv_label(value)
     assert e.value.reason == ErrorReason.INVALID_CHARACTER
Exemplo n.º 3
0
 def test_normal(self, value):
     validate_ltsv_label(value)
Exemplo n.º 4
0
 def test_exception_invalid_char(self, value):
     with pytest.raises(InvalidCharError):
         validate_ltsv_label(value)
Exemplo n.º 5
0
 def test_normal(self, value):
     validate_ltsv_label(value)
Exemplo n.º 6
0
 def test_exception_invalid_char(self, value):
     with pytest.raises(InvalidCharError):
         validate_ltsv_label(value)