Skip to content

Commit a129f19

Browse files
committed
Improve debug output of app startup test
1 parent e133b42 commit a129f19

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

tests/src/python/test_qgsappstartup.py

+27-30
Original file line numberDiff line numberDiff line change
@@ -76,50 +76,43 @@ def doTestStartup(self, option='', testDir='', testFile='',
7676
if env is not None:
7777
myenv.update(env)
7878

79-
p = subprocess.Popen(
80-
[QGIS_BIN, "--nologo", plugins, customize, option, testDir] + additionalArguments,
81-
env=myenv)
79+
call = [QGIS_BIN, "--nologo", plugins, customize, option, testDir] + additionalArguments
80+
p = subprocess.Popen(call, env=myenv)
8281

8382
s = 0
8483
ok = True
8584
while not os.path.exists(myTestFile):
8685
p.poll()
8786
if p.returncode is not None:
88-
print('Application has returned: {}'.format(p.returncode))
89-
ok = False
90-
break
87+
raise Exception('Return code: {}, Call: "{}", Env: {}'.format(p.returncode, ' '.join(call), env))
9188
time.sleep(1)
9289
s += 1
9390
if s > timeOut:
94-
print('Timed out waiting for application start')
95-
ok = False
96-
break
91+
raise Exception('Timed out waiting for application start, Call: "{}", Env: {}'.format(' '.join(call), env))
9792

9893
try:
9994
p.terminate()
10095
except OSError as e:
10196
if e.errno != errno.ESRCH:
102-
raise
103-
104-
return ok
97+
raise e
10598

10699
def testOptionsPath(self):
107100
subdir = 'QGIS' # Linux
108101
if sys.platform[:3] == 'dar': # Mac
109102
subdir = 'qgis.org'
110103
ini = os.path.join(subdir, 'QGIS2.ini')
111104
for p in ['test_opts', 'test opts', u'test_optsé€']:
112-
assert self.doTestStartup(option="--optionspath",
113-
testDir=os.path.join(self.TMP_DIR, p),
114-
testFile=ini,
115-
timeOut=270), "options path %s" % p
105+
self.doTestStartup(option="--optionspath",
106+
testDir=os.path.join(self.TMP_DIR, p),
107+
testFile=ini,
108+
timeOut=270)
116109

117110
def testConfigPath(self):
118111
for p in ['test_config', 'test config', u'test_configé€']:
119-
assert self.doTestStartup(option="--configpath",
120-
testDir=os.path.join(self.TMP_DIR, p),
121-
testFile="qgis.db",
122-
timeOut=270), "config path %s" % p
112+
self.doTestStartup(option="--configpath",
113+
testDir=os.path.join(self.TMP_DIR, p),
114+
testFile="qgis.db",
115+
timeOut=270)
123116

124117
def testPluginPath(self):
125118
for t in ['test_plugins', 'test plugins', u'test_pluginsé€']:
@@ -138,7 +131,7 @@ def testPluginPath(self):
138131
# we use here a minimal plugin that writes to 'plugin_started.txt'
139132
# when it is started. if QGIS_PLUGINPATH is correctly parsed, this
140133
# plugin is executed and the file is created
141-
assert self.doTestStartup(
134+
self.doTestStartup(
142135
option="--optionspath",
143136
testDir=testDir,
144137
testFile="plugin_started.txt",
@@ -160,22 +153,26 @@ def testPyQgisStartupEnvVar(self):
160153
f = open(testmod, 'w')
161154
f.writelines(testcode)
162155
f.close()
163-
msg = 'Creation of test file by executing PYQGIS_STARTUP file failed'
164-
assert self.doTestStartup(
156+
self.doTestStartup(
165157
testFile=testfilepath,
166158
timeOut=270,
167-
env={'PYQGIS_STARTUP': testmod}), msg
159+
env={'PYQGIS_STARTUP': testmod})
168160

169161
def testOptionsAsFiles(self):
170162
# verify QGIS accepts filenames that match options after the special option '--'
171163
# '--help' should return immediatly (after displaying the usage hints)
172164
# '-- --help' should not exit but try (and probably fail) to load a layer called '--help'
173-
for t in [(False, ['--help']), (True, ['--', '--help'])]:
174-
assert t[0] == self.doTestStartup(option="--configpath",
175-
testDir=os.path.join(self.TMP_DIR, 'test_optionsAsFiles'),
176-
testFile="qgis.db",
177-
timeOut=270,
178-
additionalArguments=t[1]), "additional arguments: %s" % ' '.join(t[1])
165+
with self.assertRaises(Exception):
166+
self.doTestStartup(option="--configpath",
167+
testDir=os.path.join(self.TMP_DIR, 'test_optionsAsFiles'),
168+
testFile="qgis.db",
169+
timeOut=270,
170+
additionalArguments=['--help']), "additional arguments: %s" % ' '.join(t[1])
171+
self.doTestStartup(option="--configpath",
172+
testDir=os.path.join(self.TMP_DIR, 'test_optionsAsFiles'),
173+
testFile="qgis.db",
174+
timeOut=270,
175+
additionalArguments=['--'], ['--help']), "additional arguments: %s" % ' '.join(t[1])
179176

180177

181178
if __name__ == '__main__':

0 commit comments

Comments
 (0)