Skip to content
Permalink
Browse files
Merge pull request #898 from dakcarto/test_appstartup_1
[tests] Make app startup test work on Mac
  • Loading branch information
timlinux committed Sep 15, 2013
2 parents 68d12b4 + 8fb9816 commit d22f65810f363e0252211da74106825b847baa9c
Showing with 48 additions and 27 deletions.
  1. +46 −27 tests/src/python/test_qgsappstartup.py
  2. +2 −0 tests/testdata/test_plugin_path/qgis.org/QGIS2.ini
@@ -12,29 +12,41 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4 import QtGui, QtCore
from qgis.core import QgsApplication
from PyQt4 import QtCore
import sys
import os
import time
import locale
import shutil
import subprocess
import tempfile

from utilities import unittest, getQgisTestApp, unitTestDataPath

QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
from utilities import unittest, unitTestDataPath

TEST_DATA_DIR = unitTestDataPath()


class TestPyQgsAppStartup(unittest.TestCase):

TMP_DIR = ''

@classmethod
def setUpClass(cls):
cls.TMP_DIR = tempfile.mkdtemp()

@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.TMP_DIR, ignore_errors=True)

def doTestOptionsPath(self, option, testDir, testFile, timeOut, env = {}):
"""Run QGIS with the given option. Wait for testFile to be created. If time runs out, fail.
"""
# from unicode to local
testDir = str(QtCore.QString( testDir ).toLocal8Bit())
myTestFile = testDir + "/" + testFile
if not os.path.exists(testDir):
os.mkdir(testDir)
myTestFile = os.path.join(testDir, testFile)
# print 'myTestFile: ', myTestFile

if os.path.exists( myTestFile ):
os.remove( myTestFile )
@@ -44,7 +56,7 @@ def doTestOptionsPath(self, option, testDir, testFile, timeOut, env = {}):
myenv.update( env )

p = subprocess.Popen( [ QGIS_BIN, "--nologo", option, testDir ], env = myenv )

s = 0
ok = True
while not os.path.exists( myTestFile ):
@@ -55,50 +67,57 @@ def doTestOptionsPath(self, option, testDir, testFile, timeOut, env = {}):
break

p.terminate()

# remove testDir
shutil.rmtree( testDir, ignore_errors = True )
return ok

def testOptionsPath( self ):
for p in [ 'test_config', 'test config', 'test_configé€' ]:
assert self.doTestOptionsPath( "--optionspath", (os.getcwd() + '/' + p).decode('utf-8'), "QGIS/QGIS2.ini", 5 ), "options path %s" % p
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', 'test_optsé€' ]:
assert self.doTestOptionsPath( "--optionspath", os.path.join(self.TMP_DIR, p), ini, 5 ), "options path %s" % p

def testConfigPath( self ):
for p in [ 'test_config', 'test config', 'test_configé€' ]:
assert self.doTestOptionsPath( "--configpath", (os.getcwd() + '/' + p).decode('utf-8'), "qgis.db", 30 ), "config path %s" % p
assert self.doTestOptionsPath( "--configpath", os.path.join(self.TMP_DIR, p), "qgis.db", 30 ), "config path %s" % p

def testPluginPath( self ):
for t in ['test_plugins', 'test plugins', 'test_pluginsé€' ]:

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

# copy from testdata
shutil.rmtree( testDir, ignore_errors = True )
shutil.copytree( TEST_DATA_DIR + '/test_plugin_path', testDir )
shutil.copytree( os.path.join(TEST_DATA_DIR, 'test_plugin_path'), testDir )

# 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.doTestOptionsPath( "--optionspath", testDir, "plugin_started.txt", 10, { 'QGIS_PLUGINPATH' : str(QtCore.QString(testDir).toLocal8Bit()) } )
assert self.doTestOptionsPath( "--optionspath", testDir, "plugin_started.txt", 10,
{ 'QGIS_PLUGINPATH' : str(QtCore.QString(testDir).toLocal8Bit()) } )


if __name__ == '__main__':

# look for qgis bin path
QGIS_BIN = ''
prefixPath = os.environ['QGIS_PREFIX_PATH']
# see qgsapplication.cpp:98
for f in [ '', '/..', '/bin', '/../../..' ]:
testDir = prefixPath + f
if os.path.exists( testDir + '/qgis' ):
QGIS_BIN = testDir + '/qgis'
for f in ['', '..', 'bin']:
d = os.path.join(prefixPath, f)
b = os.path.abspath(os.path.join(d, 'qgis'))
if os.path.exists(b):
QGIS_BIN = b
break
b = os.path.abspath(os.path.join(d, 'qgis.exe'))
if os.path.exists(b):
QGIS_BIN = b
break
if os.path.exists( testDir + '/qgis.exe' ):
QGIS_BIN = testDir + '/qgis.exe'
b = os.path.abspath(os.path.join(d, 'QGIS.app/Contents/MacOS/QGIS'))
if os.path.exists(b):
QGIS_BIN = b
break

print 'QGIS_BIN =', QGIS_BIN

print 'QGIS_BIN: ', QGIS_BIN
assert 'qgis' in QGIS_BIN.lower() and os.path.exists(QGIS_BIN), \
'QGIS binary not found, skipping test suite'
unittest.main()

@@ -0,0 +1,2 @@
[PythonPlugins]
PluginPathTest=true

0 comments on commit d22f658

Please sign in to comment.