Skip to content

Commit

Permalink
Add more complete tests of roman and jwst datamodels
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Nov 29, 2024
1 parent db7e3df commit 633dcea
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 17 deletions.
31 changes: 31 additions & 0 deletions tests/test_jwst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Integration tests with JWST pipeline
"""

from inspect import getmembers, isclass

import pytest

from stpipe.protocols import DataModel

datamodels = pytest.importorskip("stdatamodels.jwst.datamodels")


def test_jwst_datamodel():

Check warning on line 14 in tests/test_jwst.py

View check run for this annotation

Codecov / codecov/patch

tests/test_jwst.py#L14

Added line #L14 was not covered by tests
"""Smoke test to ensure the JWST datamodels work with the DataModel protocol."""
jwst_datamodel = pytest.importorskip("stdatamodels.jwst.datamodels")
image_model = jwst_datamodel.ImageModel()
assert isinstance(image_model, DataModel)

Check warning on line 18 in tests/test_jwst.py

View check run for this annotation

Codecov / codecov/patch

tests/test_jwst.py#L16-L18

Added lines #L16 - L18 were not covered by tests


@pytest.mark.parametrize(

Check warning on line 21 in tests/test_jwst.py

View check run for this annotation

Codecov / codecov/patch

tests/test_jwst.py#L21

Added line #L21 was not covered by tests
"model",
[
model[1]
for model in getmembers(datamodels, isclass)
if issubclass(model[1], datamodels.JwstDataModel)
],
)
def test_datamodel(model):

Check warning on line 29 in tests/test_jwst.py

View check run for this annotation

Codecov / codecov/patch

tests/test_jwst.py#L29

Added line #L29 was not covered by tests
"""Test that all JWST datamodels work with the DataModel protocol."""
assert isinstance(model(), DataModel)

Check warning on line 31 in tests/test_jwst.py

View check run for this annotation

Codecov / codecov/patch

tests/test_jwst.py#L31

Added line #L31 was not covered by tests
17 changes: 0 additions & 17 deletions tests/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,9 @@
Test that the DataModel interface of the protocol works properly
"""

import pytest

from stpipe.protocols import DataModel


def test_roman_datamodel():
roman_datamodels = pytest.importorskip("roman_datamodels.datamodels")
from roman_datamodels.maker_utils import mk_level2_image

roman_image_tree = mk_level2_image()
image_model = roman_datamodels.ImageModel(roman_image_tree)
assert isinstance(image_model, DataModel)


def test_jwst_datamodel():
jwst_datamodel = pytest.importorskip("stdatamodels.jwst.datamodels")
image_model = jwst_datamodel.ImageModel()
assert isinstance(image_model, DataModel)


class GoodDataModel:
def __init__(self):
pass
Expand Down
35 changes: 35 additions & 0 deletions tests/test_roman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Integration tests with Roman pipeline
"""

from inspect import getmembers, isclass

import pytest

from stpipe.protocols import DataModel

datamodels = pytest.importorskip("roman_datamodels.datamodels")


def test_roman_datamodel():

Check warning on line 14 in tests/test_roman.py

View check run for this annotation

Codecov / codecov/patch

tests/test_roman.py#L14

Added line #L14 was not covered by tests
"""Smoke test to ensure the Roman datamodels work with the DataModel protocol."""
roman_datamodels = pytest.importorskip("roman_datamodels.datamodels")
from roman_datamodels.maker_utils import mk_level2_image

Check warning on line 17 in tests/test_roman.py

View check run for this annotation

Codecov / codecov/patch

tests/test_roman.py#L16-L17

Added lines #L16 - L17 were not covered by tests

roman_image_tree = mk_level2_image()
image_model = roman_datamodels.ImageModel(roman_image_tree)
assert isinstance(image_model, DataModel)

Check warning on line 21 in tests/test_roman.py

View check run for this annotation

Codecov / codecov/patch

tests/test_roman.py#L19-L21

Added lines #L19 - L21 were not covered by tests


@pytest.mark.parametrize(

Check warning on line 24 in tests/test_roman.py

View check run for this annotation

Codecov / codecov/patch

tests/test_roman.py#L24

Added line #L24 was not covered by tests
"model",
[
model[1]
for model in getmembers(datamodels, isclass)
if model[1] != datamodels.DataModel
and issubclass(model[1], datamodels.DataModel)
],
)
def test_datamodel(model):

Check warning on line 33 in tests/test_roman.py

View check run for this annotation

Codecov / codecov/patch

tests/test_roman.py#L33

Added line #L33 was not covered by tests
"""Test that all Roman datamodels work with the DataModel protocol."""
assert isinstance(model(), DataModel)

Check warning on line 35 in tests/test_roman.py

View check run for this annotation

Codecov / codecov/patch

tests/test_roman.py#L35

Added line #L35 was not covered by tests

0 comments on commit 633dcea

Please sign in to comment.