Skip to content

Commit

Permalink
ci: write xml coverage report to support coveralls (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem authored Oct 20, 2023
1 parent 90a7c58 commit 49ced9e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ at least one test to verify the intended behavior.

To run tests locally, execute the test suite using `pytest` with the following command:
```bash
pytest tests/ --cov elmo -s -v
pytest tests/ --cov --cov-branch -vv
```

For a comprehensive test that mirrors the Continuous Integration (CI) environment across all supported Python
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ allow-direct-references = true

[tool.pytest.ini_options]
pythonpath = "src"

[tool.coverage.run]
omit = [
"tests/*",
]
5 changes: 3 additions & 2 deletions src/elmo/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,7 @@ def query(self, query):

_LOGGER.debug(f"Client | Query parsed successfully: {result}")
return result

if query == q.ALERTS:
elif query == q.ALERTS:
try:
# Check if the response has the expected format
msg = response.json()
Expand All @@ -610,3 +609,5 @@ def query(self, query):
_LOGGER.debug(f"Client | Status retrieved: {new_dict}")

return new_dict
else:
raise QueryNotValid() # pragma: no cover
25 changes: 25 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,31 @@ def test_client_query_error(server, mocker):
client.query(query.SECTORS)


def test_client_query_invalid_response(server, mocker):
"""Should raise ParseError if the response doesn't pass the expected parsing."""
html = """[
{
"Active": true,
"ActivePartial": false,
"Max": false,
"Activable": true,
"ActivablePartial": false,
"Id": 1,
"Index": 0,
"Element": 1,
"CommandId": 0,
"InProgress": false
}
]"""
server.add(responses.POST, "https://example.com/api/areas", body=html, status=200)
client = ElmoClient(base_url="https://example.com", domain="domain")
client._session_id = "test"
mocker.patch.object(client, "_get_descriptions")
# Test
with pytest.raises(ParseError):
client.query(query.SECTORS)


def test_client_get_alerts_status(server):
"""Should query a Elmo system to retrieve alerts status."""
html = """
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ allowlist_externals = pytest
deps =
-e .[dev]
commands =
pytest tests/ --cov elmo -s -v
pytest tests --cov --cov-branch --cov-report=xml -vv

[testenv:lint]
skip_install = true
Expand Down

0 comments on commit 49ced9e

Please sign in to comment.