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

ci: add coverage checking to pytest runs #4

Merged
merged 1 commit into from
Jul 10, 2024
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
14 changes: 12 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -33,7 +33,17 @@ jobs:

- name: Test with pytest
run: |
python -m pytest
python -m pytest --cov=cumulus_fhir_support --cov-report=xml

- name: Check coverage report
if: github.ref != 'refs/heads/main'
uses: orgoro/[email protected]
with:
coverageFile: coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
thresholdAll: .99
thresholdNew: 1
thresholdModified: 1

lint:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion cumulus_fhir_support/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from typing import TYPE_CHECKING, Any, Iterable, Optional, Union

if TYPE_CHECKING:
import fsspec
import fsspec # pragma: no cover

PathType = Union[str, pathlib.Path]
ResourceType = Union[str, Iterable[str], None]
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ line-length = 100
tests = [
"ddt",
"pytest",
"pytest-cov",
]
dev = [
"black >= 24, < 25",
Expand Down
6 changes: 6 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ def fake_open(filename, mode, encoding):
mock_fs.ls = fake_ls
mock_fs.open = fake_open

# Missing dir
with self.assert_no_logs():
rows = support.read_multiline_json_from_dir("not-present", "Patient", fsspec_fs=mock_fs)
self.assertEqual([], list(rows))

# Dir exists
with self.assert_no_logs():
rows = support.read_multiline_json_from_dir("folder", "Patient", fsspec_fs=mock_fs)
self.assertEqual(["P2", "P1"], [x["id"] for x in rows])
13 changes: 13 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for schemas.py"""

import unittest
from unittest import mock

import pyarrow

Expand Down Expand Up @@ -219,3 +220,15 @@ def test_contained_resources_empty(self):
self.assertEqual(pyarrow.string(), contained_type.field("id").type)
self.assertEqual(pyarrow.string(), contained_type.field("implicitRules").type)
self.assertEqual(pyarrow.string(), contained_type.field("language").type)

@mock.patch("fhirclient.models.fhirelementfactory.FHIRElementFactory.instantiate")
def test_unexpected_fhir_type(self, mock_instantiate):
"""Verify that we error out if an unknown FHIR type is provided"""
mock_resource = mock.MagicMock()
mock_resource.elementProperties.return_value = [
("fieldBoolean", "fieldBoolean", bool, False, None, False),
("fieldObject", "fieldObject", object, False, None, False),
]
mock_instantiate.return_value = mock_resource
with self.assertRaisesRegex(ValueError, "Unexpected type: <class 'object'>"):
support.pyarrow_schema_from_rows("AllergyIntolerance")
Loading