Skip to content

Commit

Permalink
change mocking to cover more code
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Oct 11, 2024
1 parent 8169b2c commit e7fe5e8
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions tests/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest

import stpipe.config_parser as cp
from stpipe import cmdline
from stpipe import cmdline, crds_client
from stpipe.pipeline import Pipeline
from stpipe.step import NoCRDSParametersWarning, Step

Expand Down Expand Up @@ -152,47 +152,57 @@ def config_file_list_arg_step(tmp_path):
def _mock_step_crds(monkeypatch):
"""Mock various crds calls from Step"""

def mock_get_config_from_reference_pipe(dataset, disable=None):
cfg = cp.config_from_dict(
{
"str1": "from crds",
"str2": "from crds",
"str3": "from crds",
"steps": {
"step1": {
"str1": "from crds",
"str2": "from crds",
"str3": "from crds",
class MockModel:
crds_observatory = "jwst"

def get_crds_parameters(self):
return {}

def __enter__(self):
return self

def __exit__(self, *args, **kwargs):
pass

def mock_datamodels_open(*args, **kwargs):
return MockModel()

def mock_get_reference_file(crds_parameters, reftype, crds_observatory):
return reftype

original_load_config = cp.load_config_file

def mock_load_config_file(ref_file):
cfg = {
"pars-simplestep": cp.config_from_dict(
{"str1": "from crds", "str2": "from crds", "str3": "from crds"},
),
"pars-simplepipe": cp.config_from_dict(
{
"str1": "from crds",
"str2": "from crds",
"str3": "from crds",
"steps": {
"step1": {
"str1": "from crds",
"str2": "from crds",
"str3": "from crds",
},
},
},
}
)
cfg._from_crds = True
return cfg

def mock_get_config_from_reference_step(dataset, disable=None):
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):
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
)
monkeypatch.setattr(
SimpleStep, "get_config_from_reference", mock_get_config_from_reference_step
)
monkeypatch.setattr(
ListArgStep,
"get_config_from_reference",
mock_get_config_from_reference_list_arg_step,
)
}
),
"pars-listargstep": cp.config_from_dict(
{"rotation": "15", "pixel_scale": "0.85"}
),
}.get(ref_file, None)
if cfg:
return cfg
return original_load_config(ref_file)

for StepClass in (SimpleStep, SimplePipe, ListArgStep):
monkeypatch.setattr(StepClass, "_datamodels_open", mock_datamodels_open)
monkeypatch.setattr(crds_client, "get_reference_file", mock_get_reference_file)
monkeypatch.setattr(cp, "load_config_file", mock_load_config_file)


# #####
Expand Down

0 comments on commit e7fe5e8

Please sign in to comment.