Skip to content

Commit

Permalink
Measuring size (LOC), size (non-commented LOC), tests, and failed tes…
Browse files Browse the repository at this point in the history
…ts using SonarQube as source would fail with a parse error. Fixes #623.
  • Loading branch information
fniessink committed Sep 25, 2019
1 parent 3693784 commit 45d4e01
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/collector/src/source_collectors/sonarqube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

<!-- The line "## <square-bracket>Unreleased</square-bracket>" is replaced by the ci/release.py script with the new release version and release date. -->

## [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
Expand Down

0 comments on commit 45d4e01

Please sign in to comment.