def test_install_zipped_font(self): manager = QgsFontManager() with tempfile.TemporaryDirectory() as user_font_dir: manager.addUserFontDirectory(user_font_dir) spy_installed = QSignalSpy(manager.fontDownloaded) spy_failed = QSignalSpy(manager.fontDownloadErrorOccurred) manager.downloadAndInstallFont(QUrl.fromLocalFile('xxxx')) spy_failed.wait() self.assertEqual(len(spy_failed), 1) self.assertEqual(len(spy_installed), 0) manager.downloadAndInstallFont( QUrl.fromLocalFile(unitTestDataPath() + '/zipped_font.zip')) spy_installed.wait() self.assertEqual(len(spy_failed), 1) self.assertEqual(len(spy_installed), 1) self.assertEqual(spy_installed[0][0], ['Fresca']) self.assertTrue( spy_installed[0][1].startswith('Copyright (c) 2011')) self.assertTrue( os.path.exists( os.path.join(user_font_dir, 'Fresca-Regular.ttf'))) self.assertEqual(manager.userFontToFamilyMap(), { os.path.join(user_font_dir, 'Fresca-Regular.ttf'): ['Fresca'] })
def test_install_font(self): manager = QgsFontManager() with tempfile.TemporaryDirectory() as user_font_dir: manager.addUserFontDirectory(user_font_dir) spy_installed = QSignalSpy(manager.fontDownloaded) spy_failed = QSignalSpy(manager.fontDownloadErrorOccurred) manager.downloadAndInstallFont(QUrl.fromLocalFile('xxxx')) spy_failed.wait() self.assertEqual(len(spy_failed), 1) self.assertEqual(len(spy_installed), 0) manager.downloadAndInstallFont( QUrl.fromLocalFile(unitTestDataPath() + '/fascinate.ttf')) spy_installed.wait() self.assertEqual(len(spy_failed), 1) self.assertEqual(len(spy_installed), 1) self.assertEqual(spy_installed[0][0], ['Fascinate']) self.assertTrue( os.path.exists(os.path.join(user_font_dir, 'Fascinate'))) self.assertEqual( manager.userFontToFamilyMap(), {os.path.join(user_font_dir, 'Fascinate'): ['Fascinate']}) manager.removeUserFont(os.path.join(user_font_dir, 'Fascinate')) self.assertFalse(manager.userFontToFamilyMap()) self.assertFalse( os.path.exists(os.path.join(user_font_dir, 'Fascinate')))
def testFetchLimit(self): layer = createLayer() w = QgsFeaturePickerWidget() w.setAllowNull(False) w.setFetchLimit(20) w.setLayer(layer) spy = QSignalSpy(w.featureChanged) spy.wait() self.assertEqual(w.findChild(QComboBox).model().rowCount(), 20)
def testSetFeature(self): layer = createLayer() w = QgsFeaturePickerWidget() w.setLayer(layer) w.setFeature(2) spy = QSignalSpy(w.currentFeatureChanged) spy.wait() self.assertEqual(w.findChild(QComboBox).lineEdit().text(), "test2") self.assertTrue(w.feature().geometry().equals( QgsGeometry.fromPointXY(QgsPointXY(200, 200))))
def testFeaturesCount(self): self.assertTrue(self.vl.renderer().legendSymbolItems()) signal_spy = QSignalSpy(self.vl.symbolFeatureCountMapChanged) self.vl.countSymbolFeatures() signal_spy.wait() self.assertEqual(len(signal_spy), 1) self.assertEqual( self.vl.featureCount( self.vl.renderer().legendSymbolItems()[0].ruleKey()), 5)
def testLineEdit(self): layer = createLayer(True) w = QgsFeaturePickerWidget() w.setAllowNull(False) w.setFetchLimit(20) w.setLayer(layer) spy = QSignalSpy(w.featureChanged) spy.wait() w.findChild(QComboBox).lineEdit().clear() QTest.keyClicks(w.findChild(QComboBox).lineEdit(), "test99") spy.wait() self.assertEqual(w.feature().id(), 99)
def testSetAllowNull(self): layer = createLayer() w = QgsFeaturePickerWidget() w.setLayer(layer) w.setAllowNull(True) spy = QSignalSpy(w.featureChanged) spy.wait() self.assertEqual( w.findChild(QComboBox).lineEdit().text(), QgsApplication.nullRepresentation()) w.setAllowNull(False) spy.wait() self.assertEqual(w.findChild(QComboBox).lineEdit().text(), "test1")
def test_query(self): """ Test querying sublayers using the task """ task = QgsProviderSublayerTask(uri=unitTestDataPath() + '/mixed_types.TAB') def completed(): completed.results = task.results() completed.results = None task.taskCompleted.connect(completed) spy = QSignalSpy(task.taskCompleted) QgsApplication.taskManager().addTask(task) if completed.results is None: spy.wait() self.assertEqual(completed.results[0].layerNumber(), 0) self.assertEqual(completed.results[0].name(), "mixed_types") self.assertEqual(completed.results[0].description(), "") self.assertEqual(completed.results[0].uri(), "{}/mixed_types.TAB|geometrytype=Point".format(unitTestDataPath())) self.assertEqual(completed.results[0].providerKey(), "ogr") self.assertEqual(completed.results[0].type(), QgsMapLayerType.VectorLayer) self.assertEqual(completed.results[0].featureCount(), 4) self.assertEqual(completed.results[0].wkbType(), QgsWkbTypes.Point) self.assertEqual(completed.results[0].geometryColumnName(), '') self.assertEqual(completed.results[1].layerNumber(), 0) self.assertEqual(completed.results[1].name(), "mixed_types") self.assertEqual(completed.results[1].description(), "") self.assertEqual(completed.results[1].uri(), "{}/mixed_types.TAB|geometrytype=LineString".format(unitTestDataPath())) self.assertEqual(completed.results[1].providerKey(), "ogr") self.assertEqual(completed.results[1].type(), QgsMapLayerType.VectorLayer) self.assertEqual(completed.results[1].featureCount(), 4) self.assertEqual(completed.results[1].wkbType(), QgsWkbTypes.LineString) self.assertEqual(completed.results[1].geometryColumnName(), '') self.assertEqual(completed.results[2].layerNumber(), 0) self.assertEqual(completed.results[2].name(), "mixed_types") self.assertEqual(completed.results[2].description(), "") self.assertEqual(completed.results[2].uri(), "{}/mixed_types.TAB|geometrytype=Polygon".format(unitTestDataPath())) self.assertEqual(completed.results[2].providerKey(), "ogr") self.assertEqual(completed.results[2].type(), QgsMapLayerType.VectorLayer) self.assertEqual(completed.results[2].featureCount(), 3) self.assertEqual(completed.results[2].wkbType(), QgsWkbTypes.Polygon) self.assertEqual(completed.results[2].geometryColumnName(), '')