|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +''' |
| 3 | +test_qgscomposerhtml.py |
| 4 | + -------------------------------------- |
| 5 | + Date : August 2012 |
| 6 | + Copyright : (C) 2012 by Dr. Horst Düster / Dr. Marco Hugentobler |
| 7 | + email : marco@sourcepole.ch |
| 8 | + *************************************************************************** |
| 9 | + * * |
| 10 | + * This program is free software; you can redistribute it and/or modify * |
| 11 | + * it under the terms of the GNU General Public License as published by * |
| 12 | + * the Free Software Foundation; either version 2 of the License, or * |
| 13 | + * (at your option) any later version. * |
| 14 | + * * |
| 15 | + ***************************************************************************/ |
| 16 | +''' |
| 17 | +import unittest |
| 18 | +from utilities import * |
| 19 | +from PyQt4.QtCore import * |
| 20 | +from PyQt4.QtGui import * |
| 21 | +from qgis.core import * |
| 22 | +from qgscompositionchecker import QgsCompositionChecker |
| 23 | + |
| 24 | +QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp() |
| 25 | + |
| 26 | +class TestQgsComposerMap(unittest.TestCase): |
| 27 | + |
| 28 | + def testCase(self): |
| 29 | + self.mComposition = QgsComposition( None ) |
| 30 | + self.mComposition.setPaperSize( 297, 210 ) #A4 landscape |
| 31 | + self.table() |
| 32 | + self.tableMultiFrame() |
| 33 | + |
| 34 | + def table(self): |
| 35 | + TEST_DATA_DIR = unitTestDataPath() |
| 36 | + htmlItem = QgsComposerHtml( self.mComposition, False ) |
| 37 | + htmlFrame = QgsComposerFrame( self.mComposition, htmlItem, 0, 0, 100, 200 ) |
| 38 | + htmlFrame.setFrameEnabled( True ) |
| 39 | + htmlItem.addFrame( htmlFrame ) |
| 40 | + htmlItem.setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir.separator() + "html_table.html" ) ) ); |
| 41 | + checker = QgsCompositionChecker( ) |
| 42 | + result = checker.testComposition( "Composer html table", self.mComposition, QString( TEST_DATA_DIR + QDir.separator().toAscii() + "control_images" + QDir.separator().toAscii() + "expected_composerhtml" + QDir.separator().toAscii() + "composerhtml_table.png" ) ) |
| 43 | + self.mComposition.removeMultiFrame( htmlItem ) |
| 44 | + del htmlItem |
| 45 | + assert result == True |
| 46 | + |
| 47 | + def tableMultiFrame(self): |
| 48 | + |
| 49 | + assert 1 == 1 # soon... |
| 50 | + ''' |
| 51 | + TEST_DATA_DIR = unitTestDataPath() |
| 52 | + htmlItem = QgsComposerHtml( self.mComposition, False ) |
| 53 | + htmlFrame = QgsComposerFrame( self.mComposition, htmlItem, 10, 10, 100, 50 ) |
| 54 | + htmlItem.addFrame( htmlFrame ) |
| 55 | + htmlItem.setResizeMode( QgsComposerMultiFrame.RepeatUntilFinished ) |
| 56 | + |
| 57 | + htmlItem.setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir.separator() + "html_table.html" ) ) ) |
| 58 | + nFrames = htmlItem.nFrames() |
| 59 | + for i in nFrames: |
| 60 | + htmlItem.frame( i ).setFrameEnabled( True ) |
| 61 | + |
| 62 | + result = True |
| 63 | +
|
| 64 | + #page 1 |
| 65 | + checker1 = QgsCompositionChecker( "Composer html table", self.mComposition, QString( QString( TEST_DATA_DIR ) + QDir.separator() + "control_images" + QDir.separator() + "expected_composerhtml" + QDir.separator() + "composerhtml_table_multiframe1.png" ) ) |
| 66 | + if not checker1.testComposition( 0 ): |
| 67 | + result = False |
| 68 | + |
| 69 | + checker2 = QgsCompositionChecker( "Composer html table", self.mComposition, QString( QString( TEST_DATA_DIR ) + QDir.separator() + "control_images" + QDir.separator() + "expected_composerhtml" + QDir.separator() + "composerhtml_table_multiframe2.png" ) ) |
| 70 | + if not checker2.testComposition( 1 ): |
| 71 | + result = False |
| 72 | + |
| 73 | + checker3 = QgsCompositionChecker( "Composer html table", self.mComposition, QString( QString( TEST_DATA_DIR ) + QDir.separator() + "control_images" + QDir.separator() + "expected_composerhtml" + QDir.separator() + "composerhtml_table_multiframe3.png" ) ) |
| 74 | + if not checker3.testComposition( 2 ): |
| 75 | + result = False |
| 76 | + |
| 77 | + self.mComposition.removeMultiFrame( htmlItem ) |
| 78 | + del htmlItem |
| 79 | + |
| 80 | + assert result == True |
| 81 | + ''' |
| 82 | + |
| 83 | +if __name__ == '__main__': |
| 84 | + unittest.main() |
0 commit comments