Beispiel #1
0
def test_combine_dicts_empty_current():
    """
    Test: The default is properly used as both "current" and "default"
    When: `current` is empty
    """
    default_test = {"test_var": 123}
    expected = {"test_var": {"current": 123, "default": 123}}
    assert _combine_dicts({}, default_test) == expected
Beispiel #2
0
def test_combine_dicts():
    """
    Test: combine dicts works as expected - returns a dict with current and default
    When: dicts with matching variables are passed in
    """
    current_test = {"test_var": 123}
    default_test = {"test_var": 654}
    expected = {"test_var": {"current": 123, "default": 654}}
    assert _combine_dicts(current_test, default_test) == expected
def submit_runs(request, instrument=None):
    """
    Handles run submission request
    """
    LOGGER.info('Submitting runs')
    # pylint:disable=no-member
    instrument = Instrument.objects.prefetch_related('reduction_runs').get(
        name=instrument)
    if request.method == 'GET':
        processing_status = Status.get_processing()
        queued_status = Status.get_queued()

        # pylint:disable=no-member
        runs_for_instrument = instrument.reduction_runs.all()
        last_run = instrument.get_last_for_rerun(runs_for_instrument)

        kwargs = ReductionRunUtils.make_kwargs_from_runvariables(last_run)
        standard_vars = kwargs["standard_vars"]
        advanced_vars = kwargs["advanced_vars"]

        try:
            default_variables = VariableUtils.get_default_variables(instrument)
        except (FileNotFoundError, ImportError, SyntaxError) as err:
            return {"message": str(err)}

        final_standard = _combine_dicts(standard_vars,
                                        default_variables["standard_vars"])
        final_advanced = _combine_dicts(advanced_vars,
                                        default_variables["advanced_vars"])

        # pylint:disable=no-member
        context_dictionary = {
            'instrument': instrument,
            'last_instrument_run': last_run,
            'processing': runs_for_instrument.filter(status=processing_status),
            'queued': runs_for_instrument.filter(status=queued_status),
            'standard_variables': final_standard,
            'advanced_variables': final_advanced,
        }

        return context_dictionary
Beispiel #4
0
def test_combine_dicts_current_more_vars():
    """
    Test: Value is None when current variables has a variable that's not in the defaults
    When: the current_variables dict has a variable that is not matching
    """
    current_test = {"test_var": 123, "not_in_defaults": "test"}
    default_test = {"test_var": 123}
    expected = {
        "test_var": {
            "current": 123,
            "default": 123
        },
        "not_in_defaults": {
            "current": "test",
            "default": None
        }
    }
    assert _combine_dicts(current_test, default_test) == expected
def configure_new_runs_get(instrument_name,
                           start=0,
                           end=0,
                           experiment_reference=0):
    """
    GET for the configure new runs page
    """
    instrument = Instrument.objects.get(name__iexact=instrument_name)

    editing = (start > 0 or experiment_reference > 0)

    last_run = instrument.get_last_for_rerun()

    run_variables = ReductionRunUtils.make_kwargs_from_runvariables(last_run)
    standard_vars = run_variables["standard_vars"]
    advanced_vars = run_variables["advanced_vars"]

    # if a specific start is provided, include vars upcoming for the specific start
    filter_kwargs = {"start_run__gte": start if start else last_run.run_number}
    if end:
        # if an end run is provided - don't show variables outside the [start-end) range
        filter_kwargs["start_run__lt"] = end

    upcoming_variables = instrument.instrumentvariable_set.filter(
        **filter_kwargs)
    if experiment_reference:
        upcoming_experiment_variables = instrument.instrumentvariable_set.filter(
            experiment_reference=experiment_reference)
    else:
        upcoming_experiment_variables = []

    # Updates the variables values. Experiment variables are chained second
    # so they values will overwrite any changes from the run variables
    for upcoming_var in chain(upcoming_variables,
                              upcoming_experiment_variables):
        name = upcoming_var.name
        if name in standard_vars or not upcoming_var.is_advanced:
            standard_vars[name] = upcoming_var
        elif name in advanced_vars or upcoming_var.is_advanced:
            advanced_vars[name] = upcoming_var

    # Unique, comma-joined list of all start runs belonging to the upcoming variables.
    # This seems to be used to prevent submission if trying to resubmit variables for already
    # configured future run numbers - check the checkForConflicts function
    # This should probably be done by the POST method anyway.. so remove it when
    if upcoming_variables:
        upcoming_run_variables = ','.join(
            {str(var.start_run)
             for var in upcoming_variables})
    else:
        upcoming_run_variables = ""

    try:
        reduce_vars_variables = VariableUtils.get_default_variables(instrument)
    except (FileNotFoundError, ImportError, SyntaxError) as err:
        return {"message": str(err)}

    final_standard = _combine_dicts(standard_vars,
                                    reduce_vars_variables["standard_vars"])
    final_advanced = _combine_dicts(advanced_vars,
                                    reduce_vars_variables["advanced_vars"])
    run_start = start if start else last_run.run_number + 1

    context_dictionary = {
        'instrument':
        instrument,
        'last_instrument_run':
        last_run,
        'processing':
        ReductionRun.objects.filter(instrument=instrument,
                                    status=Status.get_processing()),
        'queued':
        ReductionRun.objects.filter(instrument=instrument,
                                    status=Status.get_queued()),
        'standard_variables':
        final_standard,
        'advanced_variables':
        final_advanced,
        'run_start':
        run_start,
        # used to determine whether the current form is for an experiment reference
        'current_experiment_reference':
        experiment_reference,
        # used to create the link to an experiment reference form, using this number
        'submit_for_experiment_reference':
        last_run.experiment.reference_number,
        'minimum_run_start':
        run_start,
        'minimum_run_end':
        run_start + 1,
        'upcoming_run_variables':
        upcoming_run_variables,
        'editing':
        editing,
        'tracks_script':
        '',
    }

    return context_dictionary