From 45d4e01dbe592eab206989aa37d621af80979969 Mon Sep 17 00:00:00 2001 From: Frank Niessink Date: Wed, 25 Sep 2019 11:35:08 +0200 Subject: [PATCH] Measuring size (LOC), size (non-commented LOC), tests, and failed tests using SonarQube as source would fail with a parse error. Fixes #623. --- .../src/source_collectors/sonarqube.py | 3 +- .../source_collectors_tests/test_sonarqube.py | 33 +++++++++++++++++++ docs/CHANGELOG.md | 6 ++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/components/collector/src/source_collectors/sonarqube.py b/components/collector/src/source_collectors/sonarqube.py index 8af6168c03..4d476ec43b 100644 --- a/components/collector/src/source_collectors/sonarqube.py +++ b/components/collector/src/source_collectors/sonarqube.py @@ -127,7 +127,8 @@ def _parse_source_responses_value(self, responses: List[requests.Response]) -> V return str(self.__get_metrics(responses)[self.metricKeys.split(",")[0]]) def _parse_source_responses_total(self, responses: List[requests.Response]) -> Value: - return str(self.__get_metrics(responses)[self.metricKeys.split(",")[1]]) + return str(self.__get_metrics(responses)[self.metricKeys.split(",")[1]]) \ + if "," in self.metricKeys else super()._parse_source_responses_total(responses) @staticmethod def __get_metrics(responses: List[requests.Response]) -> Dict[str, int]: diff --git a/components/collector/tests/unittests/source_collectors_tests/test_sonarqube.py b/components/collector/tests/unittests/source_collectors_tests/test_sonarqube.py index 28899bbccc..8054a5888d 100644 --- a/components/collector/tests/unittests/source_collectors_tests/test_sonarqube.py +++ b/components/collector/tests/unittests/source_collectors_tests/test_sonarqube.py @@ -106,3 +106,36 @@ def test_suppressed_violations(self): ], response) self.assert_value("2", response) + + def test_loc(self): + """Test that the number of lines of code is returned.""" + json = dict(component=dict(measures=[dict(metric="lines", value="1234")])) + metric = dict(type="loc", addition="sum", sources=self.sources) + response = self.collect(metric, get_request_json_return_value=json) + self.assert_value("1234", response) + self.assert_total("100", response) + + def test_ncloc(self): + """Test that the number of non-commented lines of code is returned.""" + json = dict(component=dict(measures=[dict(metric="ncloc", value="999")])) + metric = dict(type="ncloc", addition="sum", sources=self.sources) + response = self.collect(metric, get_request_json_return_value=json) + self.assert_value("999", response) + self.assert_total("100", response) + + def test_nr_of_tests(self): + """Test that the number of tests is returned.""" + json = dict(component=dict(measures=[dict(metric="tests", value="123")])) + metric = dict(type="tests", addition="sum", sources=self.sources) + response = self.collect(metric, get_request_json_return_value=json) + self.assert_value("123", response) + self.assert_total("100", response) + + def test_failed_tests(self): + """Test that the number of failed tests is returned.""" + json = dict(component=dict(measures=[dict(metric="test_failures", value="13")])) + metric = dict(type="failed_tests", addition="sum", sources=self.sources) + response = self.collect(metric, get_request_json_return_value=json) + self.assert_value("13", response) + self.assert_total("100", response) + diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ec3892a15c..7db778230f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. +## [Unreleased] + +### Fixed + +- Measuring size (LOC), size (non-commented LOC), tests, and failed tests using SonarQube as source would fail with a parse error. Fixes [#623](https://github.com/ICTU/quality-time/issues/623). + ## [0.10.0] - [2019-09-22] ### Added