Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measuring size (LOC), size (non-commented LOC), tests, and failed tes… #625

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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