Ejemplo n.º 1
0
def test_step_config_from_legacy_asdf(config):
    parameters = {
        "class": config.class_name,
        "name": config.name,
    }
    parameters.update(config.parameters)

    steps = {}
    for step in config.steps:
        # The older config files don't include "name" or "class"
        # for the child steps.
        steps[step.name] = step.parameters

    parameters["steps"] = steps

    asdf_file = asdf.AsdfFile(
        {"parameters": parameters},
        custom_schema="http://stsci.edu/schemas/stpipe/step_config-0.1.0")

    # We lose the step class names so the configs won't be equal:
    legacy_config = StepConfig.from_asdf(asdf_file)
    assert legacy_config.name == config.name
    assert legacy_config.class_name == config.class_name
    assert legacy_config.parameters == config.parameters
    assert len(legacy_config.steps) == len(config.steps)
    for legacy_step, step in zip(legacy_config.steps, config.steps):
        assert legacy_step.name == step.name
        assert legacy_step.class_name is None
        assert legacy_step.parameters == step.parameters
        assert legacy_step.steps == step.steps
Ejemplo n.º 2
0
def test_saving_pars(tmpdir):
    """Save the step parameters from the commandline"""
    cfg_path = t_path(join('steps', 'jwst_generic_pars-makeliststep_0002.asdf'))
    saved_path = tmpdir.join('savepars.asdf')
    step = Step.from_cmdline([
        cfg_path,
        '--save-parameters',
        str(saved_path)
    ])
    assert saved_path.check()

    with asdf.open(t_path(join('steps', 'jwst_generic_pars-makeliststep_0002.asdf'))) as af:
        original_config = StepConfig.from_asdf(af)
        original_config.parameters["par3"] = False

    with asdf.open(str(saved_path)) as af:
        config = StepConfig.from_asdf(af)
        assert config.parameters == original_config.parameters

    step.closeout()
Ejemplo n.º 3
0
def test_export_config(step_obj, expected, tmp_path):
    """Test retrieving of configuration parameters"""
    config_path = tmp_path / "config.asdf"
    step_obj.export_config(config_path)

    with asdf.open(config_path) as af:
        # StepConfig has an __eq__ implementation but we can't use it
        # due to differences between asdf 2.7 and 2.8 in serializing None
        # values.  This can be simplified once the minimum asdf requirement
        # is changed to >= 2.8.
        # assert StepConfig.from_asdf(af) == expected
        config = StepConfig.from_asdf(af)
        assert config.class_name == expected.class_name
        assert config.name == expected.name
        assert config.steps == expected.steps
        parameters = set(expected.parameters.keys()).union(set(config.parameters.keys()))
        for parameter in parameters:
            assert config.parameters.get(parameter) == expected.parameters.get(parameter)
Ejemplo n.º 4
0
def test_step_config_from_asdf(config):
    asdf_file = config.to_asdf()
    assert StepConfig.from_asdf(asdf_file) == config

    with pytest.raises(asdf.ValidationError):
        StepConfig.from_asdf(asdf.AsdfFile())