Exemplo n.º 1
0
 def test_is_valid_r_variable(self):
     """
     Test for strings to check if they are valid R variables.
     """
     self.assertFalse(RUtils.is_valid_r_variable("var_name%"))
     self.assertFalse(RUtils.is_valid_r_variable("2var_name"))
     self.assertFalse(RUtils.is_valid_r_variable(".2var_name"))
     self.assertFalse(RUtils.is_valid_r_variable("_var_name"))
     self.assertTrue(RUtils.is_valid_r_variable("var_name2."))
     self.assertTrue(RUtils.is_valid_r_variable(".var_name"))
     self.assertTrue(RUtils.is_valid_r_variable("var.name"))
Exemplo n.º 2
0
    def process_parameter_line(self, line):
        """
        Processes a single script line representing a parameter
        """
        value, _ = self.split_tokens(line)
        description = RUtils.create_descriptive_name(value)

        if not RUtils.is_valid_r_variable(value):
            self.error = self.tr(
                'This script has a syntax error in variable name.\n'
                '"{1}" is not a valid variable name in R.'
                'Problem with line: {0}').format(line, value)

        output = create_output_from_string(line)
        if output is not None:
            output.setName(value)
            output.setDescription(description)
            if issubclass(output.__class__, QgsProcessingOutputDefinition):
                self.addOutput(output)
                self.save_output_values = True
            else:
                # destination type parameter
                self.addParameter(output)
        else:
            line = RUtils.upgrade_parameter_line(line)

            # this is necessary to remove the otherwise unknown keyword
            line = line.replace("enum literal", "enum")

            # this is annoying, but required to work around a bug in early 3.8.0 versions
            try:
                param = getParameterFromString(line, context="")
            except TypeError:
                param = getParameterFromString(line)

            # set help parameter
            if Qgis.QGIS_VERSION_INT >= 31600:
                if self.descriptions is not None:
                    param.setHelp(self.descriptions.get(param.name()))

            if param is not None:
                self.addParameter(param)
            else:
                self.error = self.tr('This script has a syntax error.\n'
                                     'Problem with line: {0}').format(line)
Exemplo n.º 3
0
    def process_parameter_line(self, line):
        """
        Processes a single script line representing a parameter
        """
        value, _ = self.split_tokens(line)
        description = RUtils.create_descriptive_name(value)

        if not RUtils.is_valid_r_variable(value):
            self.add_error_message(
                self.tr('This script has a syntax error in variable name.\n'
                        '"{1}" is not a valid variable name in R.'
                        'Problem with line: {0}').format(line, value))

        output = create_output_from_string(line)
        if output is not None:
            output.setName(value)
            output.setDescription(description)
            if issubclass(output.__class__, QgsProcessingOutputDefinition):
                self.addOutput(output)
                self.save_output_values = True
            else:
                # destination type parameter
                self.addParameter(output)
        else:
            param = create_parameter_from_string(line)

            if param is not None:
                # set help parameter
                if Qgis.QGIS_VERSION_INT >= 31600:
                    if self.descriptions is not None:
                        param.setHelp(self.descriptions.get(param.name()))

                self.addParameter(param)
            else:
                self.add_error_message(
                    self.tr('This script has a syntax error.\n'
                            'Problem with line: {0}').format(line))