1
+ # -*- coding: utf-8 -*-
2
+ """QGIS Unit tests for QgsComposerPicture.
3
+
4
+ .. note:: This program is free software; you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation; either version 2 of the License, or
7
+ (at your option) any later version.
8
+ """
9
+ __author__ = '(C) 2015 by Nyall Dawson'
10
+ __date__ = '02/07/2015'
11
+ __copyright__ = 'Copyright 2015, The QGIS Project'
12
+ # This will get replaced with a git SHA1 when you do a git archive
13
+ __revision__ = '$Format:%H$'
14
+
15
+ import qgis
16
+ import os
17
+ import sys
18
+ import SocketServer
19
+ import threading
20
+ import SimpleHTTPServer
21
+ from PyQt4 .QtGui import QPainter , QColor
22
+ from PyQt4 .QtCore import QRectF , QCoreApplication
23
+
24
+ from qgis .core import (QgsComposerPicture ,
25
+ QgsComposition ,
26
+ QgsMapSettings
27
+ )
28
+ from utilities import (unitTestDataPath ,
29
+ getQgisTestApp ,
30
+ TestCase ,
31
+ unittest
32
+ )
33
+ from qgscompositionchecker import QgsCompositionChecker
34
+
35
+ QGISAPP , CANVAS , IFACE , PARENT = getQgisTestApp ()
36
+ TEST_DATA_DIR = unitTestDataPath ()
37
+
38
+ class TestQgsComposerPicture (TestCase ):
39
+
40
+ @classmethod
41
+ def setUpClass (cls ):
42
+ # Bring up a simple HTTP server, for remote picture tests
43
+ os .chdir ( unitTestDataPath () + '' )
Collapse comment Comment on line R43
Hi nyaal... just reading code to learn :)
what does it means +'',
bye
Code has comments. Press enter to view.
44
+ handler = SimpleHTTPServer .SimpleHTTPRequestHandler
45
+
46
+ cls .httpd = SocketServer .TCPServer (('localhost' , 0 ), handler )
47
+ cls .port = cls .httpd .server_address [1 ]
48
+
49
+ cls .httpd_thread = threading .Thread ( target = cls .httpd .serve_forever )
50
+ cls .httpd_thread .setDaemon ( True )
51
+ cls .httpd_thread .start ()
52
+
53
+ def __init__ (self , methodName ):
54
+ """Run once on class initialisation."""
55
+ unittest .TestCase .__init__ (self , methodName )
56
+
57
+ TEST_DATA_DIR = unitTestDataPath ()
58
+ self .pngImage = TEST_DATA_DIR + "/sample_image.png" ;
59
+
60
+ # create composition
61
+ self .mapSettings = QgsMapSettings ()
62
+ self .composition = QgsComposition (self .mapSettings )
63
+ self .composition .setPaperSize (297 , 210 )
64
+
65
+ self .composerPicture = QgsComposerPicture ( self .composition )
66
+ self .composerPicture .setPicturePath ( self .pngImage )
67
+ self .composerPicture .setSceneRect ( QRectF ( 70 , 70 , 100 , 100 ) )
68
+ self .composerPicture .setFrameEnabled ( True )
69
+ self .composition .addComposerPicture (self .composerPicture )
70
+
71
+ def testResizeZoom (self ):
72
+ """Test picture resize zoom mode."""
73
+ self .composerPicture .setResizeMode ( QgsComposerPicture .Zoom )
74
+
75
+ checker = QgsCompositionChecker ('composerpicture_resize_zoom' , self .composition )
76
+ testResult , message = checker .testComposition ()
77
+
78
+ assert testResult , message
79
+
80
+ def testRemoteImage (self ):
81
+ """Test fetching remote picture."""
82
+ self .composerPicture .setPicturePath ( 'http://localhost:' + str ( TestQgsComposerPicture .port ) + '/qgis_local_server/logo.png' )
83
+
84
+ checker = QgsCompositionChecker ('composerpicture_remote' , self .composition )
85
+ testResult , message = checker .testComposition ()
86
+
87
+ self .composerPicture .setPicturePath ( self .pngImage )
88
+ assert testResult , message
89
+
90
+ if __name__ == '__main__' :
91
+ unittest .main ()
0 commit comments