Esempio n. 1
0
 def make_dict(variables, name):
     var_dict = {
         v.name:
         VariableUtils().convert_variable_to_type(v.value, v.type)
         for v in variables
     }
     return indent + name + " = " + str(var_dict)
Esempio n. 2
0
    def createReductionRun(self):
        instrument = InstrumentUtils().get_instrument("valid")
        instrument.save()
        experiment = Experiment(reference_number=1)
        experiment.save()

        reduction_run = ReductionRun(run_number=self.run_number,
                                     instrument=instrument,
                                     experiment=experiment,
                                     run_version=1,
                                     status=StatusUtils().get_queued(),
                                     script=getValidScript('reduce.py'))
        self.run_number += 1
        reduction_run.save()

        variables = InstrumentVariablesUtils().get_variables_for_run(
            reduction_run)
        VariableUtils().save_run_variables(variables, reduction_run)

        return reduction_run
Esempio n. 3
0
    def get_script_and_arguments(reduction_run):
        """
        Fetch the reduction script from the given run and return it as a string,
        along with a dictionary of arguments.
        """
        from reduction_variables.utils import VariableUtils

        script = reduction_run.script

        # pylint:disable=no-member
        run_variables = RunVariable.objects.filter(reduction_run=reduction_run)
        standard_vars, advanced_vars = {}, {}
        for variables in run_variables:
            value = VariableUtils().convert_variable_to_type(variables.value, variables.type)
            if variables.is_advanced:
                advanced_vars[variables.name] = value
            else:
                standard_vars[variables.name] = value

        arguments = {'standard_vars': standard_vars, 'advanced_vars': advanced_vars}

        return script, arguments
    def test_wrap_in_type_syntax_list_text(self):
        result = VariableUtils().wrap_in_type_syntax("this, is, a, list", "list_text")

        self.assertEqual(result, "['this','is','a','list']", "Expecting result to be ['this','is','a','list'] but was %s" % result)
    def test_convert_variable_to_type_number_to_list_text(self):
        result = VariableUtils().convert_variable_to_type(123, "list_text")

        self.assertEqual(result, ['123'], "Expecting result to be ['123'] but was %s" % result)
    def test_get_type_string_boolean_false(self):
        result = VariableUtils().get_type_string(False)

        self.assertEqual(result, "boolean", "Expecting result to be boolean but was %s" % result)
    def test_wrap_in_type_syntax_boolean_true_titlecase(self):
        result = VariableUtils().wrap_in_type_syntax("True", "boolean")

        self.assertEqual(result, "True", "Expecting result to be True but was %s" % result)
    def test_get_type_string_float(self):
        result = VariableUtils().get_type_string(5.5)

        self.assertEqual(result, "number", "Expecting result to be number but was %s" % result)
    def test_get_type_string_list_number_mixed(self):
        result = VariableUtils().get_type_string([1,2.2,3])

        self.assertEqual(result, "list_number", "Expecting result to be list_number but was %s" % result)
Esempio n. 10
0
    def test_wrap_in_type_syntax_non_string_value(self):
        result = VariableUtils().wrap_in_type_syntax(123, "text")

        self.assertEqual(result, "'123'", "Expecting result to be '123' but was %s" % result)
Esempio n. 11
0
    def test_convert_variable_to_type_text_to_boolean_false_titlecase(self):
        result = VariableUtils().convert_variable_to_type("False", "boolean")

        self.assertEqual(result, False, "Expecting result to be False but was %s" % result)
Esempio n. 12
0
    def test_wrap_in_type_syntax_list_number_text(self):
        result = VariableUtils().wrap_in_type_syntax("this, is, a, list", "list_number")

        self.assertEqual(result, "[]", "Expecting result to be [] but was %s" % result)
Esempio n. 13
0
    def test_wrap_in_type_syntax_unknonw_type(self):
        result = VariableUtils().wrap_in_type_syntax("test", "unknown")

        self.assertEqual(result, "test", "Expecting result to be test but was %s" % result)
Esempio n. 14
0
    def test_wrap_in_type_syntax_list_number(self):
        result = VariableUtils().wrap_in_type_syntax("1, 2, 3", "list_number")

        self.assertEqual(result, "[1, 2, 3]", "Expecting result to be [1, 2, 3] but was %s" % result)
Esempio n. 15
0
    def test_wrap_in_type_syntax_list_text_numbers(self):
        result = VariableUtils().wrap_in_type_syntax("1, 2, 3", "list_text")

        self.assertEqual(result, "['1','2','3']", "Expecting result to be ['1','2','3'] but was %s" % result)
Esempio n. 16
0
    def test_wrap_in_type_syntax_list_text_empty(self):
        result = VariableUtils().wrap_in_type_syntax("", "list_text")

        self.assertEqual(result, "[]", "Expecting result to be [] but was %s" % result)
Esempio n. 17
0
    def test_convert_variable_to_type_text_to_list_number_with_float(self):
        result = VariableUtils().convert_variable_to_type("123, 456, 5.5", "list_number")

        self.assertEqual(result, [123, 456, 5.5], "Expecting result to be [123, 456, 5.5] but was %s" % result)
Esempio n. 18
0
    def test_convert_variable_to_type_boolean_to_text(self):
        result = VariableUtils().convert_variable_to_type(True, "text")

        self.assertEqual(result, "True", "Expecting result to be True but was %s" % result)
Esempio n. 19
0
    def test_convert_variable_to_type_text_to_boolean_true_lowercase(self):
        result = VariableUtils().convert_variable_to_type("true", "boolean")

        self.assertEqual(result, True, "Expecting result to be True but was %s" % result)
Esempio n. 20
0
    def test_convert_variable_to_type_number_to_number(self):
        result = VariableUtils().convert_variable_to_type(123, "number")

        self.assertEqual(result, 123, "Expecting result to be 123 but was %s" % result)
Esempio n. 21
0
    def test_convert_variable_to_type_unknown_type(self):
        result = VariableUtils().convert_variable_to_type("test", "unknown")

        self.assertEqual(result, "test", "Expecting result to be test but was %s" % result)
Esempio n. 22
0
    def test_convert_variable_to_type_text_to_number_float(self):
        result = VariableUtils().convert_variable_to_type("1.23", "number")

        self.assertEqual(result, 1.23, "Expecting result to be 1.23 but was %s" % result)
Esempio n. 23
0
    def test_get_type_string_list_text(self):
        result = VariableUtils().get_type_string(["test", "test2"])

        self.assertEqual(result, "list_text", "Expecting result to be list_text but was %s" % result)
Esempio n. 24
0
    def test_convert_variable_to_type_text_to_number_invalid(self):
        result = VariableUtils().convert_variable_to_type("test", "number")

        self.assertEqual(result, None, "Expecting result to be None but was %s" % result)
Esempio n. 25
0
    def test_get_type_string_list_mixed_number_first(self):
        result = VariableUtils().get_type_string([2, "test", 5.5])

        self.assertEqual(result, "list_text", "Expecting result to be list_text but was %s" % result)
Esempio n. 26
0
    def test_wrap_in_type_syntax_number_text(self):
        result = VariableUtils().wrap_in_type_syntax("test", "number")

        self.assertEqual(result, "", "Expecting result to be empty but was %s" % result)
Esempio n. 27
0
    def test_get_type_string_boolean_none(self):
        result = VariableUtils().get_type_string(None)

        self.assertEqual(result, "text", "Expecting result to be text but was %s" % result)
Esempio n. 28
0
    def test_convert_variable_to_type_text_to_list_text_empty(self):
        result = VariableUtils().convert_variable_to_type("", "list_text")

        self.assertEqual(result, [], "Expecting result to be [] but was %s" % result)
Esempio n. 29
0
    def test_convert_variable_to_type_text_to_list_text(self):
        result = VariableUtils().convert_variable_to_type("this, is, a, list", "list_text")

        self.assertEqual(result, ['this', 'is', 'a', 'list'], "Expecting result to be ['this', 'is', 'a', 'list'] but was %s" % result)
Esempio n. 30
0
    def test_wrap_in_type_syntax_boolean_invalid(self):
        result = VariableUtils().wrap_in_type_syntax("test", "boolean")

        self.assertEqual(result, "False", "Expecting result to be False but was %s" % result)