12
12
# This will get replaced with a git SHA1 when you do a git archive
13
13
__revision__ = '$Format:%H$'
14
14
15
- from PyQt4 import QtGui , QtCore
16
- from qgis .core import QgsApplication
15
+ from PyQt4 import QtCore
17
16
import sys
18
17
import os
19
18
import time
20
19
import locale
21
20
import shutil
22
21
import subprocess
22
+ import tempfile
23
23
24
- from utilities import unittest , getQgisTestApp , unitTestDataPath
25
-
26
- QGISAPP , CANVAS , IFACE , PARENT = getQgisTestApp ()
24
+ from utilities import unittest , unitTestDataPath
27
25
28
26
TEST_DATA_DIR = unitTestDataPath ()
29
27
28
+
30
29
class TestPyQgsAppStartup (unittest .TestCase ):
31
30
31
+ TMP_DIR = ''
32
+
33
+ @classmethod
34
+ def setUpClass (cls ):
35
+ cls .TMP_DIR = tempfile .mkdtemp ()
36
+
37
+ @classmethod
38
+ def tearDownClass (cls ):
39
+ shutil .rmtree (cls .TMP_DIR , ignore_errors = True )
40
+
32
41
def doTestOptionsPath (self , option , testDir , testFile , timeOut , env = {}):
33
42
"""Run QGIS with the given option. Wait for testFile to be created. If time runs out, fail.
34
43
"""
35
44
# from unicode to local
36
45
testDir = str (QtCore .QString ( testDir ).toLocal8Bit ())
37
- myTestFile = testDir + "/" + testFile
46
+ if not os .path .exists (testDir ):
47
+ os .mkdir (testDir )
48
+ myTestFile = os .path .join (testDir , testFile )
49
+ # print 'myTestFile: ', myTestFile
38
50
39
51
if os .path .exists ( myTestFile ):
40
52
os .remove ( myTestFile )
@@ -44,7 +56,7 @@ def doTestOptionsPath(self, option, testDir, testFile, timeOut, env = {}):
44
56
myenv .update ( env )
45
57
46
58
p = subprocess .Popen ( [ QGIS_BIN , "--nologo" , option , testDir ], env = myenv )
47
-
59
+
48
60
s = 0
49
61
ok = True
50
62
while not os .path .exists ( myTestFile ):
@@ -55,50 +67,57 @@ def doTestOptionsPath(self, option, testDir, testFile, timeOut, env = {}):
55
67
break
56
68
57
69
p .terminate ()
58
-
59
- # remove testDir
60
- shutil .rmtree ( testDir , ignore_errors = True )
61
70
return ok
62
71
63
72
def testOptionsPath ( self ):
64
- for p in [ 'test_config' , 'test config' , 'test_configé€' ]:
65
- assert self .doTestOptionsPath ( "--optionspath" , (os .getcwd () + '/' + p ).decode ('utf-8' ), "QGIS/QGIS2.ini" , 5 ), "options path %s" % p
73
+ subdir = 'QGIS' # Linux
74
+ if sys .platform [:3 ] == 'dar' : # Mac
75
+ subdir = 'qgis.org'
76
+ ini = os .path .join (subdir , 'QGIS2.ini' )
77
+ for p in [ 'test_opts' , 'test opts' , 'test_optsé€' ]:
78
+ assert self .doTestOptionsPath ( "--optionspath" , os .path .join (self .TMP_DIR , p ), ini , 5 ), "options path %s" % p
66
79
67
80
def testConfigPath ( self ):
68
81
for p in [ 'test_config' , 'test config' , 'test_configé€' ]:
69
- assert self .doTestOptionsPath ( "--configpath" , ( os .getcwd () + '/' + p ). decode ( 'utf-8' ), "qgis.db" , 30 ), "config path %s" % p
82
+ assert self .doTestOptionsPath ( "--configpath" , os .path . join ( self . TMP_DIR , p ), "qgis.db" , 30 ), "config path %s" % p
70
83
71
84
def testPluginPath ( self ):
72
85
for t in ['test_plugins' , 'test plugins' , 'test_pluginsé€' ]:
73
-
86
+
74
87
# get a unicode test dir
75
- testDir = (os .getcwd () + '/' + t ).decode ('utf-8' )
88
+ testDir = (os .path . join ( self . TMP_DIR , t ) ).decode ('utf-8' )
76
89
77
90
# copy from testdata
78
91
shutil .rmtree ( testDir , ignore_errors = True )
79
- shutil .copytree ( TEST_DATA_DIR + '/ test_plugin_path' , testDir )
92
+ shutil .copytree ( os . path . join ( TEST_DATA_DIR , ' test_plugin_path') , testDir )
80
93
81
94
# we use here a minimal plugin that writes to 'plugin_started.txt' when it is started
82
95
# if QGIS_PLUGINPATH is correctly parsed, this plugin is executed and the file is created
83
- assert self .doTestOptionsPath ( "--optionspath" , testDir , "plugin_started.txt" , 10 , { 'QGIS_PLUGINPATH' : str (QtCore .QString (testDir ).toLocal8Bit ()) } )
96
+ assert self .doTestOptionsPath ( "--optionspath" , testDir , "plugin_started.txt" , 10 ,
97
+ { 'QGIS_PLUGINPATH' : str (QtCore .QString (testDir ).toLocal8Bit ()) } )
84
98
85
99
86
100
if __name__ == '__main__' :
87
-
88
101
# look for qgis bin path
89
102
QGIS_BIN = ''
90
103
prefixPath = os .environ ['QGIS_PREFIX_PATH' ]
91
104
# see qgsapplication.cpp:98
92
- for f in [ '' , '/..' , '/bin' , '/../../..' ]:
93
- testDir = prefixPath + f
94
- if os .path .exists ( testDir + '/qgis' ):
95
- QGIS_BIN = testDir + '/qgis'
105
+ for f in ['' , '..' , 'bin' ]:
106
+ d = os .path .join (prefixPath , f )
107
+ b = os .path .abspath (os .path .join (d , 'qgis' ))
108
+ if os .path .exists (b ):
109
+ QGIS_BIN = b
110
+ break
111
+ b = os .path .abspath (os .path .join (d , 'qgis.exe' ))
112
+ if os .path .exists (b ):
113
+ QGIS_BIN = b
96
114
break
97
- if os .path .exists ( testDir + '/qgis.exe' ):
98
- QGIS_BIN = testDir + '/qgis.exe'
115
+ b = os .path .abspath (os .path .join (d , 'QGIS.app/Contents/MacOS/QGIS' ))
116
+ if os .path .exists (b ):
117
+ QGIS_BIN = b
99
118
break
100
-
101
- print 'QGIS_BIN =' , QGIS_BIN
102
119
120
+ print 'QGIS_BIN: ' , QGIS_BIN
121
+ assert 'qgis' in QGIS_BIN .lower () and os .path .exists (QGIS_BIN ), \
122
+ 'QGIS binary not found, skipping test suite'
103
123
unittest .main ()
104
-
0 commit comments