Skip to content

Commit d991ebf

Browse files
committedMar 6, 2014
Possible cross-platform fix for app startup unit test
1 parent fc8e05e commit d991ebf

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed
 

‎tests/src/python/test_qgsappstartup.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from PyQt4 import QtCore
1818
import sys
1919
import os
20+
import glob
21+
import re
2022
import time
2123
# import locale
2224
import shutil
@@ -35,6 +37,8 @@ class TestPyQgsAppStartup(unittest.TestCase):
3537
@classmethod
3638
def setUpClass(cls):
3739
cls.TMP_DIR = tempfile.mkdtemp()
40+
# print 'TMP_DIR: ' + cls.TMP_DIR
41+
# subprocess.call(['open', cls.TMP_DIR])
3842

3943
@classmethod
4044
def tearDownClass(cls):
@@ -93,29 +97,32 @@ def testOptionsPath(self):
9397
if sys.platform[:3] == 'dar': # Mac
9498
subdir = 'qgis.org'
9599
ini = os.path.join(subdir, 'QGIS2.ini')
96-
for p in ['test_opts', 'test opts', 'test_optsé€']:
100+
for p in ['test_opts', 'test opts', u'test_optsé€']:
97101
assert self.doTestStartup(option="--optionspath",
98102
testDir=os.path.join(self.TMP_DIR, p),
99103
testFile=ini,
100104
timeOut=5), "options path %s" % p
101105

102106
def testConfigPath(self):
103-
for p in ['test_config', 'test config', 'test_configé€']:
107+
for p in ['test_config', 'test config', u'test_configé€']:
104108
assert self.doTestStartup(option="--configpath",
105109
testDir=os.path.join(self.TMP_DIR, p),
106110
testFile="qgis.db",
107111
timeOut=30), "config path %s" % p
108112

109113
def testPluginPath(self):
110-
for t in ['test_plugins', 'test plugins', 'test_pluginsé€']:
114+
for t in ['test_plugins', 'test plugins', u'test_pluginsé€']:
111115

112116
# get a unicode test dir
113-
testDir = (os.path.join(self.TMP_DIR, t)).decode('utf-8')
117+
testDir = os.path.join(self.TMP_DIR, t)
114118

115119
# copy from testdata
116-
shutil.rmtree(testDir, ignore_errors=True)
117-
shutil.copytree(os.path.join(TEST_DATA_DIR, 'test_plugin_path'),
118-
testDir)
120+
if not os.path.exists(testDir):
121+
os.mkdir(testDir)
122+
test_plug_dir = os.path.join(TEST_DATA_DIR, 'test_plugin_path')
123+
for item in os.listdir(test_plug_dir):
124+
shutil.copytree(os.path.join(test_plug_dir, item),
125+
os.path.join(testDir, item))
119126

120127
# we use here a minimal plugin that writes to 'plugin_started.txt'
121128
# when it is started. if QGIS_PLUGINPATH is correctly parsed, this
@@ -164,13 +171,19 @@ def testPyQgisStartupEnvVar(self):
164171
if os.path.exists(b):
165172
QGIS_BIN = b
166173
break
167-
b = os.path.abspath(os.path.join(d, 'QGIS.app/Contents/MacOS/QGIS'))
168-
if os.path.exists(b):
169-
QGIS_BIN = b
170-
break
174+
if sys.platform[:3] == 'dar': # Mac
175+
# QGIS.app may be QGIS_x.x-dev.app for nightlies
176+
# internal binary will match, minus the '.app'
177+
found = False
178+
for app_path in glob.glob(d + '/QGIS*.app'):
179+
m = re.search('/(QGIS(_\d\.\d-dev)?)\.app', app_path)
180+
if m:
181+
QGIS_BIN = app_path + '/Contents/MacOS/' + m.group(1)
182+
found = True
183+
break
184+
if found:
185+
break
171186

172-
print ''
173-
print 'QGIS_BIN: ', QGIS_BIN
174-
assert 'qgis' in QGIS_BIN.lower() and os.path.exists(QGIS_BIN), \
175-
'QGIS binary not found, skipping test suite'
187+
print '\nQGIS_BIN: ', QGIS_BIN
188+
assert QGIS_BIN, 'QGIS binary not found, skipping test suite'
176189
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.