Skip to content

Commit 2da8543

Browse files
author
Marco Hugentobler
committed
Added python test for composer html
1 parent f2d3164 commit 2da8543

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

python/core/qgscomposition.sip

+4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ class QgsComposition: QGraphicsScene
155155
/**Deletes current command*/
156156
void cancelCommand();
157157

158+
/**Adds multiframe. The object is owned by QgsComposition until removeMultiFrame is called*/
159+
void addMultiFrame( QgsComposerMultiFrame* multiFrame );
160+
/**Removes multi frame (but does not delete it)*/
161+
void removeMultiFrame( QgsComposerMultiFrame* multiFrame );
158162
/**Adds an arrow item to the graphics scene and advices composer to create a widget for it (through signal)*/
159163
//void addComposerArrow( QgsComposerArrow* arrow );
160164
/**Adds label to the graphics scene and advices composer to create a widget for it (through signal)*/

tests/src/python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
INCLUDE(UsePythonTest)
22
ADD_PYTHON_TEST(PyQGisApp test_qgisapp.py)
3+
ADD_PYTHON_TEST(PyQgsComposerHtml test_qgscomposerhtml.py)
34
ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
45
ADD_PYTHON_TEST(PyQgsGeometry test_qgsgeometry.py)
56
ADD_PYTHON_TEST(PyQgsRasterLayer test_qgsrasterlayer.py)
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

Comments
 (0)