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())
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')
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)
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())
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')
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())
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')
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')