Commit e655f672 authored by nimrod's avatar nimrod
Browse files

Parse output.

The tests aren't the greatest and binary is broken but I think the
parsing works.
parent 8f482983
Loading
Loading
Loading
Loading
Loading
+32 −4
Original line number Diff line number Diff line
@@ -93,8 +93,7 @@ class Check:
    ExitCode = None
    Output = None
    PerfData = []
    LongOutput = None
    AdditionalOutput = None
    AdditionalOutput = []
    stderr = None
    _stdout = None

@@ -107,11 +106,40 @@ class Check:

    def _parse_output(self):
        """Parses the plugin output to get the output, perf data and long
        output. Can be run after the plugin has run and finished
        successfully."""
        output.

        Can only be run after the plugin has run and finished successfully.
        """
        if self.ExitCode is None:
            raise RuntimeError("Check hasn't run yet.")

        lines = self._stdout.splitlines()
        if not lines:
            logging.info("Emptry stdout.")
            return

        if "|" in lines[0]:
            p1, p2 = lines[0].split("|")
            self.Output = p1.strip()
            self.PerfData.append(PerfData(p2))
        else:
            self.Output = lines[0].strip()

        if len(lines) == 1:
            return

        processing_perfdata = False
        for line in lines[1:]:
            if processing_perfdata:
                self.PerfData.append(PerfData(line))
            else:
                if "|" in line:
                    self.AdditionalOutput.append(line.split("|")[0].strip())
                    processing_perfdata = True
                    self.PerfData.append(PerfData(line.split("|")[1]))
                else:
                    self.AdditionalOutput.append(line)

    def run(self, timeout=DEFAULT_TIMEOUT):
        """Run the check (if it's hasn't run yet)."""
        if self.ExitCode is not None:
+2 −1
Original line number Diff line number Diff line
@@ -107,7 +107,8 @@ def test_output_parsing(output):
    )
    with _mock_run(return_value=proc):
        check.run()
        # TODO: validate something.
        assert isinstance(check.Output, str)
        assert len(check.Output.splitlines()) == 1


@pytest.mark.parametrize("line", PERF_DATA)