Skip to content
Permalink
Browse files

Add some functions to Python unit test utilities

  • Loading branch information
dakcarto committed Mar 6, 2014
1 parent b4f6813 commit a49b9a7a454f76e2640fd5a8b1872bff2d67362e
Showing with 37 additions and 2 deletions.
  1. +3 −2 tests/src/python/qgis_local_server.py
  2. +34 −0 tests/src/python/utilities.py
@@ -26,6 +26,7 @@

from utilities import (
unitTestDataPath,
getExecutablePath,
openInBrowserTab
)

@@ -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
@@ -13,6 +13,8 @@

import os
import sys
import platform
import tempfile
import qgis
from PyQt4 import QtGui, QtCore
from qgis.core import (QgsApplication,
@@ -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()

0 comments on commit a49b9a7

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