示例#1
0
    def testConstructors(self):
        # empty
        block = QgsTextBlock()
        self.assertEqual(len(block), 0)

        # single fragment block
        fragment = QgsTextFragment('ludicrous gibs!')
        block = QgsTextBlock(fragment)
        self.assertEqual(len(block), 1)
        self.assertEqual(block[0].text(), fragment.text())
示例#2
0
    def testAt(self):
        doc = QgsTextDocument()
        self.assertEqual(len(doc), 0)

        block = QgsTextBlock()
        block.append(QgsTextFragment('a'))
        doc.append(block)
        block = QgsTextBlock()
        block.append(QgsTextFragment('b'))
        doc.append(block)
        self.assertEqual(len(doc), 2)

        self.assertEqual(doc.at(0)[0].text(), 'a')
        self.assertEqual(doc.at(1)[0].text(), 'b')
        with self.assertRaises(KeyError):
            doc.at(2)
        with self.assertRaises(KeyError):
            doc.at(-1)

        self.assertEqual(doc[0][0].text(), 'a')
        self.assertEqual(doc[1][0].text(), 'b')
        with self.assertRaises(IndexError):
            _ = doc[2]

        self.assertEqual(doc[-1][0].text(), 'b')
        self.assertEqual(doc[-2][0].text(), 'a')
示例#3
0
    def testAppend(self):
        doc = QgsTextDocument()
        self.assertEqual(len(doc), 0)

        block = QgsTextBlock()
        doc.append(block)
        self.assertEqual(len(doc), 1)
        self.assertEqual(len(doc[0]), 0)
示例#4
0
    def testClear(self):
        block = QgsTextBlock()
        block.append(QgsTextFragment('a'))
        block.append(QgsTextFragment('b'))
        self.assertEqual(len(block), 2)
        self.assertFalse(block.empty())

        block.clear()
        self.assertEqual(len(block), 0)
        self.assertTrue(block.empty())
示例#5
0
    def testAt(self):
        block = QgsTextBlock()
        block.append(QgsTextFragment('a'))
        block.append(QgsTextFragment('b'))
        self.assertEqual(len(block), 2)

        self.assertEqual(block.at(0).text(), 'a')
        self.assertEqual(block.at(1).text(), 'b')
        with self.assertRaises(KeyError):
            block.at(2)
        with self.assertRaises(KeyError):
            block.at(-1)

        self.assertEqual(block[0].text(), 'a')
        self.assertEqual(block[1].text(), 'b')
        with self.assertRaises(IndexError):
            _ = block[2]

        self.assertEqual(block[-1].text(), 'b')
        self.assertEqual(block[-2].text(), 'a')
示例#6
0
    def testConstructors(self):
        # empty
        doc = QgsTextDocument()
        self.assertEqual(len(doc), 0)

        # single block document
        block = QgsTextBlock()
        doc = QgsTextDocument(block)
        self.assertEqual(len(doc), 1)
        self.assertEqual(len(doc[0]), 0)

        # single fragment document
        fragment = QgsTextFragment('ludicrous gibs!')
        doc = QgsTextDocument(fragment)
        self.assertEqual(len(doc), 1)
        self.assertEqual(len(doc[0]), 1)
        self.assertEqual(doc[0][0].text(), fragment.text())
示例#7
0
    def testAppend(self):
        block = QgsTextBlock()
        self.assertEqual(len(block), 0)

        frag = QgsTextFragment('a')
        block.append(frag)
        self.assertEqual(len(block), 1)
        self.assertEqual(block[0].text(), 'a')
        frag = QgsTextFragment('b')
        block.append(frag)
        self.assertEqual(len(block), 2)
        self.assertEqual(block[0].text(), 'a')
        self.assertEqual(block[1].text(), 'b')

        self.assertEqual(block.toPlainText(), 'ab')
示例#8
0
 def testCapitalize(self):
     fragment = QgsTextFragment('ludicrous gibs!')
     block = QgsTextBlock(fragment)
     block.append(QgsTextFragment('another part'))
     block.applyCapitalization(QgsStringUtils.TitleCase)
     self.assertEqual(block.toPlainText(), 'Ludicrous Gibs!Another Part')