Skip to content
Permalink
Browse files

Added python test for composer html

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Aug 29, 2012
1 parent f2d3164 commit 2da854368c5b9ab196b8e7cbee0cd2e48291385a
Showing with 89 additions and 0 deletions.
  1. +4 −0 python/core/qgscomposition.sip
  2. +1 −0 tests/src/python/CMakeLists.txt
  3. +84 −0 tests/src/python/test_qgscomposerhtml.py
@@ -155,6 +155,10 @@ class QgsComposition: QGraphicsScene
/**Deletes current command*/
void cancelCommand();

/**Adds multiframe. The object is owned by QgsComposition until removeMultiFrame is called*/
void addMultiFrame( QgsComposerMultiFrame* multiFrame );
/**Removes multi frame (but does not delete it)*/
void removeMultiFrame( QgsComposerMultiFrame* multiFrame );
/**Adds an arrow item to the graphics scene and advices composer to create a widget for it (through signal)*/
//void addComposerArrow( QgsComposerArrow* arrow );
/**Adds label to the graphics scene and advices composer to create a widget for it (through signal)*/
@@ -1,5 +1,6 @@
INCLUDE(UsePythonTest)
ADD_PYTHON_TEST(PyQGisApp test_qgisapp.py)
ADD_PYTHON_TEST(PyQgsComposerHtml test_qgscomposerhtml.py)
ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
ADD_PYTHON_TEST(PyQgsGeometry test_qgsgeometry.py)
ADD_PYTHON_TEST(PyQgsRasterLayer test_qgsrasterlayer.py)
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
'''
test_qgscomposerhtml.py
--------------------------------------
Date : August 2012
Copyright : (C) 2012 by Dr. Horst Düster / Dr. Marco Hugentobler
email : marco@sourcepole.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
'''
import unittest
from utilities import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgscompositionchecker import QgsCompositionChecker

QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()

class TestQgsComposerMap(unittest.TestCase):

def testCase(self):
self.mComposition = QgsComposition( None )
self.mComposition.setPaperSize( 297, 210 ) #A4 landscape
self.table()
self.tableMultiFrame()

def table(self):
TEST_DATA_DIR = unitTestDataPath()
htmlItem = QgsComposerHtml( self.mComposition, False )
htmlFrame = QgsComposerFrame( self.mComposition, htmlItem, 0, 0, 100, 200 )
htmlFrame.setFrameEnabled( True )
htmlItem.addFrame( htmlFrame )
htmlItem.setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir.separator() + "html_table.html" ) ) );
checker = QgsCompositionChecker( )
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" ) )
self.mComposition.removeMultiFrame( htmlItem )
del htmlItem
assert result == True

def tableMultiFrame(self):

assert 1 == 1 # soon...
'''
TEST_DATA_DIR = unitTestDataPath()
htmlItem = QgsComposerHtml( self.mComposition, False )
htmlFrame = QgsComposerFrame( self.mComposition, htmlItem, 10, 10, 100, 50 )
htmlItem.addFrame( htmlFrame )
htmlItem.setResizeMode( QgsComposerMultiFrame.RepeatUntilFinished )
htmlItem.setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir.separator() + "html_table.html" ) ) )
nFrames = htmlItem.nFrames()
for i in nFrames:
htmlItem.frame( i ).setFrameEnabled( True )
result = True
#page 1
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" ) )
if not checker1.testComposition( 0 ):
result = False
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" ) )
if not checker2.testComposition( 1 ):
result = False
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" ) )
if not checker3.testComposition( 2 ):
result = False
self.mComposition.removeMultiFrame( htmlItem )
del htmlItem
assert result == True
'''

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

0 comments on commit 2da8543

Please sign in to comment.
You can’t perform that action at this time.