summaryrefslogtreecommitdiff
path: root/tests/testutils.py
diff options
context:
space:
mode:
authorJason Erickson <jerickso@stickpeople.com>2011-02-11 17:40:23 -0700
committerJason Erickson <jerickso@stickpeople.com>2011-02-11 17:40:23 -0700
commite3095edad3a83d9352b58586641c212f50acbc94 (patch)
treeb5f8232e9d53fc05b8ca659a3fde254137de4034 /tests/testutils.py
parented4274602728f22d90ce683a444d164e4fc8b9fe (diff)
downloadpsycopg2-e3095edad3a83d9352b58586641c212f50acbc94.tar.gz
Python 3 conversion failure on Windows
Windows is not able to create a tempfile with NamedTemporaryFile and then open it with a second file handle without closing the first one. Added code to close the handle, and keep the file around a little longer so it can be reopened and rewritten to again.
Diffstat (limited to 'tests/testutils.py')
-rw-r--r--tests/testutils.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/testutils.py b/tests/testutils.py
index 98297fc..8942945 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -1,4 +1,5 @@
# testutils.py - utility module for psycopg2 testing.
+
#
# Copyright (C) 2010-2011 Daniele Varrazzo <daniele.varrazzo@gmail.com>
#
@@ -190,21 +191,24 @@ def script_to_py3(script):
return script
import tempfile
- f = tempfile.NamedTemporaryFile(suffix=".py")
+ f = tempfile.NamedTemporaryFile(suffix=".py", delete=False)
f.write(script.encode())
f.flush()
+ filename = f.name
+ f.close()
# 2to3 is way too chatty
import logging
logging.basicConfig(filename=os.devnull)
from lib2to3.main import main
- if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', f.name]):
+ if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', filename]):
raise Exception('py3 conversion failed')
- f2 = open(f.name)
+ f2 = open(filename)
try:
return f2.read()
finally:
f2.close()
+ os.remove(filename)