def config(): s1 = StepConfig("some.StepClass", "Step1", {"woo": "hoo"}, []) s2 = StepConfig("some.other.StepClass", "Step2", {"yee": "haw"}, []) return StepConfig("some.PipelineClass", "Pipeline", { "foo": "bar", "baz": 42 }, [s1, s2])
def test_step_config_equality(config): other = StepConfig(config.class_name, config.name, config.parameters, config.steps) assert config == other other = StepConfig("some.other.pipeline.Name", config.name, config.parameters, config.steps) assert config != other other = StepConfig(config.class_name, "Hildegaard", config.parameters, config.steps) assert config != other other = StepConfig(config.class_name, config.name, {"foo": "foz"}, config.steps) assert config != other other = StepConfig(config.class_name, config.name, config.parameters, [config.steps[0]]) assert config != other assert config != object()
def test_step_from_commandline_par_precedence(command_line_pars, command_line_config_pars, reference_pars, expected_pars, tmp_path, monkeypatch): args = [] class_name = "jwst.stpipe.tests.steps.WithDefaultsStep" config_name = "WithDefaultsStep" reference_type = f"pars-{config_name.lower()}" input_path = join(dirname(__file__), "data", "science.fits") if command_line_config_pars: command_line_config_path = tmp_path / "with_defaults_step.cfg" config = ConfigObj(str(command_line_config_path)) config["class"] = class_name config["name"] = config_name for key, value in command_line_config_pars.items(): config[key] = value config.write() args.append(str(command_line_config_path.absolute())) else: args.append(class_name) args.append(input_path) if command_line_pars: for key, value in command_line_pars.items(): args.append(f"--{key}={value}") reference_file_map = {} if reference_pars: reference_path = tmp_path / f"{reference_type}.asdf" reference_config = StepConfig(class_name, config_name, reference_pars, []) with reference_config.to_asdf() as af: af.write_to(reference_path) reference_file_map[reference_type] = str(reference_path) def mock_get_reference_file(dataset, reference_file_type, observatory=None, asn_exptypes=None): if reference_file_type in reference_file_map: return reference_file_map[reference_file_type] else: raise CrdsLookupError(f"Error determining best reference for '{reference_file_type}' = \ Unknown reference type '{reference_file_type}'") monkeypatch.setattr(crds_client, "get_reference_file", mock_get_reference_file) step = Step.from_cmdline(args) for key, value in expected_pars.items(): assert getattr(step, key) == value
@pytest.mark.parametrize( 'step_obj, expected', [ ( MakeListStep(par1=0., par2='from args'), StepConfig( 'jwst.stpipe.tests.steps.MakeListStep', 'MakeListStep', { 'pre_hooks': [], 'post_hooks': [], 'output_ext': '.fits', 'output_use_model': False, 'output_use_index': True, 'save_results': False, 'skip': False, 'search_output_file': True, 'input_dir': '', 'par1': 0.0, 'par2': 'from args', 'par3': False, }, [] ), ), ] ) def test_export_config(step_obj, expected, tmp_path): """Test retrieving of configuration parameters""" config_path = tmp_path / "config.asdf"