summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2018-04-24 13:33:04 -0700
committerGitHub <noreply@github.com>2018-04-24 13:33:04 -0700
commit2cd78252932f41a665deaf0ce8f194723c91919c (patch)
tree170414eba64ad855a3e2075781cfbcdf365f4cff
parent729945a655b2c351ad4c91293a494c066f3bb152 (diff)
parent32bc1a74a52c0ac81fd65d3f08a4dd94489bf32e (diff)
downloadsimplejson-2cd78252932f41a665deaf0ce8f194723c91919c.tar.gz
Merge pull request #214 from simplejson/tempfile-py25
Fix tests in Python 2.5.
-rw-r--r--simplejson/tests/test_tool.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/simplejson/tests/test_tool.py b/simplejson/tests/test_tool.py
index ebb295b..914bff8 100644
--- a/simplejson/tests/test_tool.py
+++ b/simplejson/tests/test_tool.py
@@ -21,6 +21,15 @@ except ImportError:
"".encode(),
stderr).strip()
+def open_temp_file():
+ if sys.version_info >= (2, 6):
+ file = tempfile.NamedTemporaryFile(delete=False)
+ filename = file.name
+ else:
+ fd, filename = tempfile.mkstemp()
+ file = os.fdopen(fd, 'w+b')
+ return file, filename
+
class TestTool(unittest.TestCase):
data = """
@@ -71,35 +80,35 @@ class TestTool(unittest.TestCase):
self.expect.splitlines())
def test_infile_stdout(self):
- infile = tempfile.NamedTemporaryFile(delete=False)
+ infile, infile_name = open_temp_file()
try:
infile.write(self.data.encode())
infile.close()
self.assertEqual(
- self.runTool(args=[infile.name]),
+ self.runTool(args=[infile_name]),
self.expect.splitlines())
finally:
- os.unlink(infile.name)
+ os.unlink(infile_name)
def test_infile_outfile(self):
- infile = tempfile.NamedTemporaryFile(delete=False)
+ infile, infile_name = open_temp_file()
try:
infile.write(self.data.encode())
infile.close()
# outfile will get overwritten by tool, so the delete
# may not work on some platforms. Do it manually.
- outfile = tempfile.NamedTemporaryFile(delete=False)
+ outfile, outfile_name = open_temp_file()
try:
outfile.close()
self.assertEqual(
- self.runTool(args=[infile.name, outfile.name]),
+ self.runTool(args=[infile_name, outfile_name]),
[])
- with open(outfile.name, 'rb') as f:
+ with open(outfile_name, 'rb') as f:
self.assertEqual(
f.read().decode('utf8').splitlines(),
self.expect.splitlines()
)
finally:
- os.unlink(outfile.name)
+ os.unlink(outfile_name)
finally:
- os.unlink(infile.name)
+ os.unlink(infile_name)