Skip to content

Commit

Permalink
Add unit tests for methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 6, 2021
1 parent dce9c15 commit 5eb2d72
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/src/python/test_qgslayoutexporter.py
Expand Up @@ -25,6 +25,7 @@
QgsProject,
QgsMargins,
QgsLayoutItemShape,
QgsLayoutItemLabel,
QgsLayoutGuide,
QgsRectangle,
QgsLayoutItemPage,
Expand Down Expand Up @@ -1109,6 +1110,42 @@ def testExportReport(self):
page2_path = os.path.join(self.basetestpath, 'test_report_0002.png')
self.assertTrue(self.checkImage('report_page2', 'report_page2', page2_path))

def testRequiresRasterization(self):
"""
Test QgsLayoutExporter.requiresRasterization
"""
l = QgsLayout(QgsProject.instance())
l.initializeDefaults()

# add an item
label = QgsLayoutItemLabel(l)
label.attemptSetSceneRect(QRectF(30, 60, 200, 100))
l.addLayoutItem(label)

self.assertFalse(QgsLayoutExporter.requiresRasterization(l))

# an item with a blend mode will force the whole layout to be rasterized
label.setBlendMode(QPainter.CompositionMode_Overlay)
self.assertTrue(QgsLayoutExporter.requiresRasterization(l))

def testContainsAdvancedEffects(self):
"""
Test QgsLayoutExporter.containsAdvancedEffects
"""
l = QgsLayout(QgsProject.instance())
l.initializeDefaults()

# add an item
label = QgsLayoutItemLabel(l)
label.attemptSetSceneRect(QRectF(30, 60, 200, 100))
l.addLayoutItem(label)

self.assertFalse(QgsLayoutExporter.containsAdvancedEffects(l))

# an item with transparency will force it to be individually rasterized
label.setItemOpacity(0.5)
self.assertTrue(QgsLayoutExporter.containsAdvancedEffects(l))


if __name__ == '__main__':
unittest.main()

0 comments on commit 5eb2d72

Please sign in to comment.