def test_param_line(self): # Test creating a parameter from a description line param = Parameters.create_parameter_from_line('QgsProcessingParameterNumber|R_PERCTL_MIN|Percentiles Range for RED max|QgsProcessingParameterNumber.Integer|1|False|1|99') self.assertIsInstance(param, QgsProcessingParameterNumber) self.assertEqual(param.name(), 'R_PERCTL_MIN') self.assertEqual(param.description(), 'Percentiles Range for RED max') self.assertEqual(param.dataType(), QgsProcessingParameterNumber.Integer) self.assertFalse(param.flags() & QgsProcessingParameterDefinition.FlagOptional) self.assertEqual(param.minimum(), 1) self.assertEqual(param.maximum(), 99) # Test SagaImageOutputParam line param = Parameters.create_parameter_from_line('SagaImageOutput|RGB|Output RGB') self.assertIsInstance(param, SagaImageOutputParam) self.assertEqual(param.name(), 'RGB') self.assertEqual(param.description(), 'Output RGB') self.assertEqual(param.defaultFileExtension(), 'tif') self.assertEqual(param.supportedOutputRasterLayerExtensions(), ['tif'])
def defineCharacteristicsFromFile(self): with open(self.description_file, encoding="utf-8") as lines: line = lines.readline().strip('\n').strip() self._name = line if '|' in self._name: tokens = self._name.split('|') self._name = tokens[0] # cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console self.cmdname = tokens[1] else: self.cmdname = self._name self._display_name = self.tr(str(self._name)) self._name = decoratedAlgorithmName(self._name) self._display_name = self.tr(str(self._name)) self._name = self._name.lower() validChars = \ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:' self._name = ''.join(c for c in self._name if c in validChars) line = lines.readline().strip('\n').strip() if line == '##known_issues': self.known_issues = True line = lines.readline().strip('\n').strip() self.undecorated_group = line self._group = self.tr(decoratedGroupName(self.undecorated_group)) validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:' grpName = decoratedGroupName(self.undecorated_group).lower() self._groupId = ''.join(c for c in grpName if c in validChars) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcoded_strings.append(line[len('Hardcoded|'):]) elif Parameters.is_parameter_line(line): self.params.append( Parameters.create_parameter_from_line(line)) elif line.startswith('AllowUnmatching'): self.allow_nonmatching_grid_extents = True else: pass # TODO # self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip()
def defineCharacteristicsFromFile(self): with open(self.description_file, encoding="utf-8") as lines: line = lines.readline().strip('\n').strip() self._name = line if '|' in self._name: tokens = self._name.split('|') self._name = tokens[0] # cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console self.cmdname = tokens[1] else: self.cmdname = self._name self._display_name = self.tr(str(self._name)) self._name = decoratedAlgorithmName(self._name) self._display_name = self.tr(str(self._name)) self._name = self._name.lower() validChars = \ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:' self._name = ''.join(c for c in self._name if c in validChars) line = lines.readline().strip('\n').strip() if line == '##known_issues': self.known_issues = True line = lines.readline().strip('\n').strip() self.undecorated_group = line self._group = self.tr(decoratedGroupName(self.undecorated_group)) validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:' grpName = decoratedGroupName(self.undecorated_group).lower() self._groupId = ''.join(c for c in grpName if c in validChars) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcoded_strings.append(line[len('Hardcoded|'):]) elif Parameters.is_parameter_line(line): self.params.append(Parameters.create_parameter_from_line(line)) elif line.startswith('AllowUnmatching'): self.allow_nonmatching_grid_extents = True else: pass # TODO #self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip()