Skip to content
Permalink
Browse files

Improve debug output of app startup test

  • Loading branch information
m-kuhn committed Mar 29, 2016
1 parent e133b42 commit a129f190b87c6409ef996adff294c0ce1caa6fca
Showing with 27 additions and 30 deletions.
  1. +27 −30 tests/src/python/test_qgsappstartup.py
@@ -76,50 +76,43 @@ def doTestStartup(self, option='', testDir='', testFile='',
if env is not None:
myenv.update(env)

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

s = 0
ok = True
while not os.path.exists(myTestFile):
p.poll()
if p.returncode is not None:
print('Application has returned: {}'.format(p.returncode))
ok = False
break
raise Exception('Return code: {}, Call: "{}", Env: {}'.format(p.returncode, ' '.join(call), env))
time.sleep(1)
s += 1
if s > timeOut:
print('Timed out waiting for application start')
ok = False
break
raise Exception('Timed out waiting for application start, Call: "{}", Env: {}'.format(' '.join(call), env))

try:
p.terminate()
except OSError as e:
if e.errno != errno.ESRCH:
raise

return ok
raise e

def testOptionsPath(self):
subdir = 'QGIS' # Linux
if sys.platform[:3] == 'dar': # Mac
subdir = 'qgis.org'
ini = os.path.join(subdir, 'QGIS2.ini')
for p in ['test_opts', 'test opts', u'test_optsé€']:
assert self.doTestStartup(option="--optionspath",
testDir=os.path.join(self.TMP_DIR, p),
testFile=ini,
timeOut=270), "options path %s" % p
self.doTestStartup(option="--optionspath",
testDir=os.path.join(self.TMP_DIR, p),
testFile=ini,
timeOut=270)

def testConfigPath(self):
for p in ['test_config', 'test config', u'test_configé€']:
assert self.doTestStartup(option="--configpath",
testDir=os.path.join(self.TMP_DIR, p),
testFile="qgis.db",
timeOut=270), "config path %s" % p
self.doTestStartup(option="--configpath",
testDir=os.path.join(self.TMP_DIR, p),
testFile="qgis.db",
timeOut=270)

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

def testOptionsAsFiles(self):
# verify QGIS accepts filenames that match options after the special option '--'
# '--help' should return immediatly (after displaying the usage hints)
# '-- --help' should not exit but try (and probably fail) to load a layer called '--help'
for t in [(False, ['--help']), (True, ['--', '--help'])]:
assert t[0] == self.doTestStartup(option="--configpath",
testDir=os.path.join(self.TMP_DIR, 'test_optionsAsFiles'),
testFile="qgis.db",
timeOut=270,
additionalArguments=t[1]), "additional arguments: %s" % ' '.join(t[1])
with self.assertRaises(Exception):
self.doTestStartup(option="--configpath",
testDir=os.path.join(self.TMP_DIR, 'test_optionsAsFiles'),
testFile="qgis.db",
timeOut=270,
additionalArguments=['--help']), "additional arguments: %s" % ' '.join(t[1])
self.doTestStartup(option="--configpath",
testDir=os.path.join(self.TMP_DIR, 'test_optionsAsFiles'),
testFile="qgis.db",
timeOut=270,
additionalArguments=['--'], ['--help']), "additional arguments: %s" % ' '.join(t[1])


if __name__ == '__main__':

0 comments on commit a129f19

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