m.addModelParameter(QgsProcessingParameterString('string'), string_param_1) string_param_2 = QgsProcessingModelParameter('string2') m.addModelParameter(QgsProcessingParameterString('string2'), string_param_2) num_param = QgsProcessingModelParameter('number') m.addModelParameter(QgsProcessingParameterNumber('number'), num_param) table_field_param = QgsProcessingModelParameter('field') m.addModelParameter(QgsProcessingParameterField('field'), table_field_param) file_param = QgsProcessingModelParameter('file') m.addModelParameter(QgsProcessingParameterFile('file'), file_param) dlg = ModelerParametersDialog(m, m) # test single types self.assertEqual(set(p.parameterName() for p in dlg.getAvailableValuesOfType(QgsProcessingParameterNumber)), set(['number'])) self.assertEqual(set(p.parameterName() for p in dlg.getAvailableValuesOfType(QgsProcessingParameterField)), set(['field'])) self.assertEqual(set(p.parameterName() for p in dlg.getAvailableValuesOfType(QgsProcessingParameterFile)), set(['file'])) # test multiple types self.assertEqual(set(p.parameterName() for p in dlg.getAvailableValuesOfType([QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterFile])), set(['string', 'string2', 'number', 'file'])) if __name__ == '__main__': unittest.main()
'outline_width': '1' }) sym_layer.setSubSymbol(fill_sym) sym.changeSymbolLayer(0, sym_layer) rendered_layers = [self.lines_layer] self.mapsettings.setLayers(rendered_layers) renderchecker = QgsMultiRenderChecker() ms = self.mapsettings ms.setExtent(QgsRectangle(-119, 17, -82, 50)) renderchecker.setMapSettings(ms) renderchecker.setControlName('expected_arrowsymbollayer_4') self.assertTrue(renderchecker.runTest('arrowsymbollayer_4')) def testColors(self): """ Test colors, need to make sure colors are passed/retrieved from subsymbol """ sym_layer = QgsArrowSymbolLayer.create() sym_layer.setColor(QColor(150, 50, 100)) self.assertEqual(sym_layer.color(), QColor(150, 50, 100)) self.assertEqual(sym_layer.subSymbol().color(), QColor(150, 50, 100)) sym_layer.subSymbol().setColor(QColor(250, 150, 200)) self.assertEqual(sym_layer.subSymbol().color(), QColor(250, 150, 200)) self.assertEqual(sym_layer.color(), QColor(250, 150, 200)) if __name__ == '__main__': unittest.main()
self.line_symbol.startRender(context) self.line_symbol.renderFeature(f, context) self.line_symbol.stopRender(context) elif geom.type() == QGis.Point: self.marker_symbol.startRender(context) self.marker_symbol.renderFeature(f, context) self.marker_symbol.stopRender(context) painter.end() return image def imageCheck(self, name, reference_image, image): self.report += "<h2>Render {}</h2>\n".format(name) temp_dir = QDir.tempPath() + '/' file_name = temp_dir + 'symbol_' + name + ".png" image.save(file_name, "PNG") checker = QgsRenderChecker() checker.setControlPathPrefix("symbolv2") checker.setControlName("expected_" + reference_image) checker.setRenderedImage(file_name) checker.setColorTolerance(2) result = checker.compareImages(name, 20) self.report += checker.report() print self.report return result if __name__ == '__main__': unittest.main()# -*- coding: utf-8 -*-
class TestQgsTextEditWidget(unittest.TestCase): VALUEMAP_NULL_TEXT = "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}" @classmethod def setUpClass(cls): QgsEditorWidgetRegistry.initEditors() def createLayerWithOnePoint(self): self.layer = QgsVectorLayer( "Point?field=fldtxt:string&field=fldint:integer", "addfeat", "memory") pr = self.layer.dataProvider() f = QgsFeature() f.setAttributes(["test", 123]) f.setGeometry(QgsGeometry.fromPoint(QgsPoint(100, 200))) assert pr.addFeatures([f]) assert self.layer.pendingFeatureCount() == 1 return self.layer def doAttributeTest(self, idx, expected): reg = QgsEditorWidgetRegistry.instance() configWdg = reg.createConfigWidget('TextEdit', self.layer, idx, None) config = configWdg.config() editwidget = reg.create('TextEdit', self.layer, idx, config, None, None) editwidget.setValue('value') assert editwidget.value() == expected[0] editwidget.setValue(123) assert editwidget.value() == expected[1] editwidget.setValue(None) assert editwidget.value() == expected[2] editwidget.setValue(NULL) assert editwidget.value() == expected[3] def test_SetValue(self): self.createLayerWithOnePoint() self.doAttributeTest(0, ['value', '123', NULL, NULL]) self.doAttributeTest(1, [NULL, 123, NULL, NULL]) def testStringWithMaxLen(self): """ tests that text edit wrappers correctly handle string fields with a maximum length """ layer = QgsVectorLayer("none?field=fldint:integer", "layer", "memory") assert layer.isValid() layer.dataProvider().addAttributes([ QgsField('max', QVariant.String, 'string', 10), QgsField('nomax', QVariant.String, 'string', 0) ]) layer.updateFields() QgsProject.instance().addMapLayer(layer) reg = QgsEditorWidgetRegistry.instance() config = {'IsMultiline': 'True'} # first test for field without character limit editor = QTextEdit() editor.setPlainText('this_is_a_long_string') w = reg.create('TextEdit', layer, 2, config, editor, None) self.assertEqual(w.value(), 'this_is_a_long_string') # next test for field with character limit editor = QTextEdit() editor.setPlainText('this_is_a_long_string') w = reg.create('TextEdit', layer, 1, config, editor, None) self.assertEqual(w.value(), 'this_is_a_') QgsProject.instance().removeAllMapLayers() def test_ValueMap_set_get(self): layer = QgsVectorLayer("none?field=number:integer", "layer", "memory") assert layer.isValid() QgsProject.instance().addMapLayer(layer) reg = QgsEditorWidgetRegistry.instance() configWdg = reg.createConfigWidget('ValueMap', layer, 0, None) config = { 'map': { 'two': '2', 'twoandhalf': '2.5', 'NULL text': 'NULL', 'nothing': self.VALUEMAP_NULL_TEXT } } # Set a configuration containing values and NULL and check if it # is returned intact. configWdg.setConfig(config) self.assertEqual(configWdg.config(), config) QgsProject.instance().removeAllMapLayers() unittest.main()