示例#1
0
    def testEnterCategory(self):
        context = QgsReadWriteContext()
        context.pushMessage('msg0', Qgis.Critical)
        with QgsReadWriteContext.enterCategory(context, 'cat1'):
            context.pushMessage('msg1', Qgis.Warning)
            with QgsReadWriteContext.enterCategory(context, 'cat2', "detail2"):
                context.pushMessage('msg2')
            context.pushMessage('msg3')
        context.pushMessage('msg4')

        messages = context.takeMessages()

        self.assertEqual(messages[0].message(), 'msg0')
        self.assertEqual(messages[0].level(), Qgis.Critical)
        self.assertEqual(messages[0].categories(), [])

        self.assertEqual(messages[1].message(), 'msg1')
        self.assertEqual(messages[1].level(), Qgis.Warning)
        self.assertEqual(messages[1].categories(), ['cat1'])

        self.assertEqual(messages[2].message(), 'msg2')
        self.assertEqual(messages[2].categories(), ['cat1', 'cat2 :: detail2'])

        self.assertEqual(messages[3].message(), 'msg3')
        self.assertEqual(messages[3].categories(), ['cat1'])

        self.assertEqual(messages[4].message(), 'msg4')
        self.assertEqual(messages[4].categories(), [])
示例#2
0
    def testEnterCategory(self):
        context = QgsReadWriteContext()
        context.pushMessage('msg0', Qgis.Critical)
        with QgsReadWriteContext.enterCategory(context, 'cat1'):
            context.pushMessage('msg1', Qgis.Warning)
            with QgsReadWriteContext.enterCategory(context, 'cat2', "detail2"):
                context.pushMessage('msg2')
            context.pushMessage('msg3')
        context.pushMessage('msg4')

        messages = context.takeMessages()

        self.assertEqual(messages[0].message(), 'msg0')
        self.assertEqual(messages[0].level(), Qgis.Critical)
        self.assertEqual(messages[0].categories(), [])

        self.assertEqual(messages[1].message(), 'msg1')
        self.assertEqual(messages[1].level(), Qgis.Warning)
        self.assertEqual(messages[1].categories(), ['cat1'])

        self.assertEqual(messages[2].message(), 'msg2')
        self.assertEqual(messages[2].categories(), ['cat1', 'cat2 :: detail2'])

        self.assertEqual(messages[3].message(), 'msg3')
        self.assertEqual(messages[3].categories(), ['cat1'])

        self.assertEqual(messages[4].message(), 'msg4')
        self.assertEqual(messages[4].categories(), [])
示例#3
0
    def test_replacements(self):
        manager = QgsApplication.fontManager()
        format = QgsTextFormat()
        font = QFont('original family')
        format.setFont(font)

        self.assertEqual(format.font().family(), 'original family')

        doc = QDomDocument()
        context = QgsReadWriteContext()
        elem = format.writeXml(doc, context)
        parent = doc.createElement("settings")
        parent.appendChild(elem)
        t2 = QgsTextFormat()
        t2.readXml(parent, context)
        self.assertFalse(t2.fontFound())
        self.assertEqual(context.takeMessages()[0].message(),
                         'Font “original family” not available on system')

        # with a font replacement in place
        test_font = getTestFont()
        manager.addFontFamilyReplacement('original Family', test_font.family())

        t3 = QgsTextFormat()
        t3.readXml(parent, context)
        self.assertTrue(t3.fontFound())
        self.assertEqual(t3.font().family(), 'QGIS Vera Sans')