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)