Skip to content
Permalink
Browse files

Fix some errors when using python3 tempfile

  • Loading branch information
nyalldawson committed Sep 5, 2016
1 parent eba6101 commit 766ae97d356ed7ae201cd419f907e371b5b4bfe0
@@ -26,7 +26,8 @@
from utilities import (
unitTestDataPath,
getExecutablePath,
openInBrowserTab
openInBrowserTab,
getTempfilePath
)

# allow import error to be raised if qgis is not on sys.path
@@ -422,10 +423,10 @@ def get_capabilities(self, params, browser=False):
res = urllib.urlopen(url)
xml = res.read()
if browser:
tmp = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
tmp.write(xml)
url = tmp.name
tmp.close()
tmp_name = getTempfilePath('html')
with open(tmp_name, 'wt') as temp_html:
temp_html.write(xml)
url = tmp_name
openInBrowserTab(url)
return False, ''

@@ -513,10 +514,9 @@ def get_map(self, params, browser=False):
and tmp_png.info().getmaintype() == 'image'
and tmp_png.info().getheader('Content-Type') == 'image/png'):

tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
filepath = tmp.name
tmp.write(tmp_png.read())
tmp.close()
filepath = getTempfilePath('png')
with open(filepath, 'wb') as temp_image:
temp_image.write(tmp_png.read())
success = True
else:
raise ServerProcessError(
@@ -43,7 +43,7 @@
unittest
)

from utilities import openInBrowserTab
from utilities import openInBrowserTab, getTempfilePath

start_app()
MAPSERV = getLocalServer()
@@ -171,10 +171,10 @@ def run_suite(module, tests):
report += '\n<h3>{0}</h3>\n{1}'.format(k, v)
report += '</body></html>'

tmp = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
tmp.write(report)
tmp.close()
openInBrowserTab('file://' + tmp.name)
tmp_name = getTempfilePath("html")
with open(tmp_name, 'wb') as temp_file:
temp_file.write(report)
openInBrowserTab('file://' + tmp_name)

return res

@@ -469,10 +469,10 @@ def runSuite(module, tests):
report += '\n<h3>{0}</h3>\n{1}'.format(k, v)
report += '</body></html>'

tmp = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
tmp.write(report)
tmp.close()
openInBrowserTab('file://' + tmp.name)
tmp_name = getTempfilePath('html')
with open(tmp_name, 'wt') as report_file:
report_file.write(report)
openInBrowserTab('file://' + tmp_name)

return res

0 comments on commit 766ae97

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