Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add some functions to Python unit test utilities
  • Loading branch information
dakcarto committed Mar 6, 2014
1 parent b4f6813 commit a49b9a7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/src/python/qgis_local_server.py
Expand Up @@ -26,6 +26,7 @@

from utilities import (
unitTestDataPath,
getExecutablePath,
openInBrowserTab
)

Expand Down Expand Up @@ -268,8 +269,8 @@ def __init__(self, fcgi_bin):

chkd = ''
for fcgi, web in servers:
fcgi_path = self._exe_path(fcgi)
web_path = self._exe_path(web)
fcgi_path = getExecutablePath(fcgi)
web_path = getExecutablePath(web)
if fcgi_path and web_path:
self._fcgiserv_path = fcgi_path
self._webserv_path = web_path
Expand Down
34 changes: 34 additions & 0 deletions tests/src/python/utilities.py
Expand Up @@ -13,6 +13,8 @@

import os
import sys
import platform
import tempfile
import qgis
from PyQt4 import QtGui, QtCore
from qgis.core import (QgsApplication,
Expand Down Expand Up @@ -222,6 +224,38 @@ def compareWkt(a, b, tol=0.000001):
return True


def getTempfilePath(sufx='png'):
"""
:returns: Path to empty tempfile ending in defined suffix
Caller should delete tempfile if not used
"""
tmp = tempfile.NamedTemporaryFile(
suffix=".{0}".format(sufx), delete=False)
filepath = tmp.name
tmp.close()
return filepath


def getExecutablePath(exe):
"""
:param exe: Name of executable, e.g. lighttpd
:returns: Path to executable
"""
exe_exts = []
if (platform.system().lower().startswith('win') and
"PATHEXT" in os.environ):
exe_exts = os.environ["PATHEXT"].split(os.pathsep)

for path in os.environ["PATH"].split(os.pathsep):
exe_path = os.path.join(path, exe)
if os.path.exists(exe_path):
return exe_path
for ext in exe_exts:
if os.path.exists(exe_path + ext):
return exe_path
return ''


def getTestFontFamily():
return QgsFontUtils.standardTestFontFamily()

Expand Down

0 comments on commit a49b9a7

Please sign in to comment.