Skip to content

Commit

Permalink
Make tests covered by codecov (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Jul 19, 2023
1 parent 59fc71b commit 7b5f02f
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 54 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
with:
envs: |
- linux: py39-oldestdeps-cov
coverage: codecov
- linux: py39
- linux: py310
- linux: py311
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

- Clean up the ``rdm_open`` function. [#233]

- Include tests in coverage and turn testing warnings into errors. [#238]

0.16.1 (2023-06-27)
===================

Expand Down
17 changes: 4 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,14 @@ text_file_format = 'rst'
addopts = '--color=yes --doctest-rst'
testpaths = ['tests']
filterwarnings = [
# This error replaces pytest-openfiles
"error::ResourceWarning",
"error::pytest.PytestUnraisableExceptionWarning",
"error",
"ignore:numpy.ndarray size changed:RuntimeWarning",
]
env = [
"ROMAN_VALIDATE=true",
"ROMAN_STRICT_VALIDATION=true",
]

[tool.coverage.run]
omit = [
'roman_datamodels/pyproject.toml',
'roman_datamodels/tests',
# And list these again for running against installed version
'*/roman_datamodels/pyproject.toml',
'*/roman_datamodels/tests',
'*/roman_datamodels/src/roman_datamodels/mktest.py',
]

[tool.coverage.report]
exclude_lines = [
# Have to re-enable the standard pragma
Expand All @@ -100,6 +89,8 @@ exclude_lines = [
# Don't complain about script hooks
'def main\(.*\):',
'if __name__ == \(.*\):',
# Don't complain if non-runnable code isn't run
'pass\n',
]

[tool.isort]
Expand Down
31 changes: 0 additions & 31 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,9 @@
import pytest
import yaml

from roman_datamodels import datamodels
from roman_datamodels import maker_utils as utils

MANIFEST = yaml.safe_load(asdf.get_config().resource_manager["asdf://stsci.edu/datamodels/roman/manifests/datamodels-1.0"])


@pytest.fixture(scope="session")
def manifest():
return MANIFEST


@pytest.fixture(name="set_up_list_of_l2_files")
def set_up_list_of_l2_files(tmp_path, request):
# generate a list of n filepaths and files to be read later on by ModelContainer
marker = request.node.get_closest_marker("set_up_list_of_l2_files_data")
number_of_files_to_create = marker.args[0]
type_of_returned_object = marker.args[1]

result_list = []
for i in range(number_of_files_to_create):
filepath = tmp_path / f"test_model_container_input_as_list_of_filepaths_{i:02}.asdf"
# create L2 file using filepath
utils.mk_level2_image(filepath=filepath)
if type_of_returned_object == "asdf":
# append filepath to filepath list
result_list.append(str(filepath))
elif type_of_returned_object == "datamodel":
# parse ASDF file as RDM
datamodel = datamodels.open(str(filepath))
# append datamodel to datamodel list
result_list.append(datamodel)

return result_list


def pytest_configure(config):
config.addinivalue_line("markers", "set_up_list_of_l2_files_data(number_of_files_to_create, type_of_returned_object): ")
6 changes: 1 addition & 5 deletions tests/test_maker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_no_extra_fields(node_class, manifest):
schema_keys = set()
subschemas = [schema]
if "allOf" in schema:
subschemas.extend(schema["allOf"])
subschemas.extend(schema["allOf"]) # pragma: no cover
for subschema in subschemas:
schema_keys.update(subschema.get("properties", {}).keys())

Expand Down Expand Up @@ -138,15 +138,11 @@ def mutate_value(value):
Generate a mutated value for a given value.
Note:
- Time is a special case because it's constructor is picky.
- Pure lists need to be preserved.
- TaggedScalarNodes need their type preserved.
"""
if isinstance(value, Time):
return value + 1 * u.day

if isinstance(value, list):
return [mock.MagicMock()]

if isinstance(value, stnode.TaggedScalarNode):
return value.__class__(mutate_value(value.__class__.__bases__[0](value)))

Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_reference_file_model_base(tmp_path):
if item == EXPECTED_COMMON_REFERENCE:
found_common = True
if not found_common:
raise ValueError("Reference schema does not include ref_common")
raise ValueError("Reference schema does not include ref_common") # pragma: no cover


# Flat tests
Expand Down Expand Up @@ -690,7 +690,7 @@ def test_ramp_from_science_raw():
assert_node_equal(ramp_value, raw_value)

else:
raise ValueError(f"Unexpected type {type(ramp_value)}, {key}")
raise ValueError(f"Unexpected type {type(ramp_value)}, {key}") # pragma: no cover


@pytest.mark.parametrize("model", datamodels.MODEL_REGISTRY.values())
Expand Down
2 changes: 0 additions & 2 deletions tests/test_stnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def test_copy(node_class):


@pytest.mark.parametrize("node_class", datamodels.MODEL_REGISTRY.keys())
@pytest.mark.filterwarnings("ignore:ERFA function.*")
@pytest.mark.filterwarnings("ignore:This function assumes shape is 2D")
@pytest.mark.filterwarnings("ignore:Input shape must be 5D")
def test_deepcopy_model(node_class):
Expand Down Expand Up @@ -85,7 +84,6 @@ def test_wfi_mode():


@pytest.mark.parametrize("node_class", stnode.NODE_CLASSES)
@pytest.mark.filterwarnings("ignore:ERFA function.*")
@pytest.mark.filterwarnings("ignore:This function assumes shape is 2D")
@pytest.mark.filterwarnings("ignore:Input shape must be 5D")
def test_serialization(node_class, tmp_path):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ commands =
pytest \
warnings: -W error \
xdist: -n auto \
cov: --cov=roman_datamodels --cov-config pyproject.toml --cov-report term-missing --cov-report xml \
cov: --cov=roman_datamodels --cov=tests --cov-config pyproject.toml --cov-report term-missing --cov-report xml \
{posargs}

[testenv:build-docs]
Expand Down

0 comments on commit 7b5f02f

Please sign in to comment.