-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for exposure pipeline input/output
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pytest | ||
import roman_datamodels.datamodels as rdm | ||
import roman_datamodels.maker_utils as mk | ||
|
||
from romancal.associations.asn_from_list import asn_from_list | ||
from romancal.datamodels.library import ModelLibrary | ||
from romancal.pipeline import ExposurePipeline | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def input_value(request, tmp_path): | ||
match request.param: | ||
case "datamodel_fn": | ||
model = mk.mk_datamodel(rdm.RampModel) | ||
fn = tmp_path / "model.asdf" | ||
model.save(fn) | ||
return fn | ||
case "datamodel": | ||
return mk.mk_datamodel(rdm.RampModel) | ||
case "asn_fn": | ||
model = mk.mk_datamodel(rdm.RampModel) | ||
model.meta.filename = "foo.asdf" | ||
model.save(tmp_path / model.meta.filename) | ||
asn = asn_from_list([model.meta.filename], product_name="foo_out") | ||
base_fn, contents = asn.dump(format="json") | ||
asn_filename = tmp_path / base_fn | ||
with open(asn_filename, "w") as f: | ||
f.write(contents) | ||
return asn_filename | ||
case "library": | ||
return ModelLibrary([mk.mk_datamodel(rdm.RampModel)]) | ||
case value: | ||
raise Exception(f"Invalid parametrization: {value}") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input_value, expected_output_type", | ||
[ | ||
("datamodel_fn", rdm.DataModel), | ||
("datamodel", rdm.DataModel), | ||
("asn_fn", ModelLibrary), | ||
("library", ModelLibrary), | ||
], | ||
indirect=["input_value"], | ||
) | ||
def test_input_to_output(input_value, expected_output_type): | ||
""" | ||
Test that for a particular input_value (as parametrized indirectly | ||
through the input_value fixtrue) the output is the expected type. | ||
""" | ||
pipeline = ExposurePipeline() | ||
# don't fetch references | ||
pipeline.prefetch_references = False | ||
# skip all steps | ||
[setattr(getattr(pipeline, k), "skip", True) for k in pipeline.step_defs] | ||
output_value = pipeline(input_value) | ||
assert isinstance(output_value, expected_output_type) |