Skip to content

Commit

Permalink
Fix some errors when using python3 tempfile
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 5, 2016
1 parent eba6101 commit 766ae97
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions tests/src/python/qgis_local_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, ''

Expand Down Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions tests/src/python/test_qgis_local_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
unittest
)

from utilities import openInBrowserTab
from utilities import openInBrowserTab, getTempfilePath

start_app()
MAPSERV = getLocalServer()
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_qgspallabeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 766ae97

Please sign in to comment.