Skip to content

Commit

Permalink
add tests that call and run for a step build from crds doesn't warn
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Oct 11, 2024
1 parent 61bd710 commit 7e250ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/stpipe/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
from .utilities import _not_set



class NoCRDSParametersWarning(UserWarning):
"""
Warning shown when a Step with CRDS parameters
is run without fetching those parameters.
"""

pass


Expand All @@ -55,7 +55,7 @@ def _warn_missing_crds_pars(step):
"CRDS parameters use "
"Step.from_config_section(Step.build_config(input)[0]) or "
"use Step.call which will create and use the instance in one method.",
NoCRDSParametersWarning
NoCRDSParametersWarning,
)


Expand Down
30 changes: 27 additions & 3 deletions tests/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import re
import warnings
from typing import ClassVar

import asdf
Expand Down Expand Up @@ -152,7 +153,7 @@ def _mock_step_crds(monkeypatch):
"""Mock various crds calls from Step"""

def mock_get_config_from_reference_pipe(dataset, disable=None):
return cp.config_from_dict(
cfg = cp.config_from_dict(
{
"str1": "from crds",
"str2": "from crds",
Expand All @@ -166,14 +167,20 @@ def mock_get_config_from_reference_pipe(dataset, disable=None):
},
}
)
cfg._from_crds = True
return cfg

def mock_get_config_from_reference_step(dataset, disable=None):
return cp.config_from_dict(
cfg = cp.config_from_dict(
{"str1": "from crds", "str2": "from crds", "str3": "from crds"}
)
cfg._from_crds = True
return cfg

def mock_get_config_from_reference_list_arg_step(dataset, disable=None):
return cp.config_from_dict({"rotation": "15", "pixel_scale": "0.85"})
cfg = cp.config_from_dict({"rotation": "15", "pixel_scale": "0.85"})
cfg._from_crds = True
return cfg

monkeypatch.setattr(
SimplePipe, "get_config_from_reference", mock_get_config_from_reference_pipe
Expand Down Expand Up @@ -425,3 +432,20 @@ def test_warning_for_missing_crds_pars(StepClass):
s._warn_on_missing_crds_steppars = True
with pytest.warns(NoCRDSParametersWarning):
s.run()


@pytest.mark.parametrize("StepClass", (SimpleStep, SimplePipe))
def test_no_warning_for_call(StepClass, _mock_step_crds, monkeypatch):
monkeypatch.setattr(StepClass, "_warn_on_missing_crds_steppars", True)
with warnings.catch_warnings():
warnings.simplefilter("error")
StepClass.call("foo")


@pytest.mark.parametrize("StepClass", (SimpleStep, SimplePipe))
def test_no_warning_for_build_config(StepClass, _mock_step_crds, monkeypatch):
s = StepClass.from_config_section(StepClass.build_config("foo")[0])
s._warn_on_missing_crds_steppars = True
with warnings.catch_warnings():
warnings.simplefilter("error")
s.run()

0 comments on commit 7e250ef

Please sign in to comment.