summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2017-11-23 13:20:42 -0800
committerBob Ippolito <bob@redivi.com>2017-11-23 13:20:42 -0800
commit5b74a43375bb2597b047e546d6cab778100d1861 (patch)
tree7608858cf1362eac7360d50e6a81a0161f21f416
parent61fae0c2dac6a0769a0b6e49320e613e498adc11 (diff)
downloadsimplejson-5b74a43375bb2597b047e546d6cab778100d1861.tar.gz
Workarounds for NamedTemporaryFile issues with Windows for tool tests
-rw-r--r--simplejson/tests/test_tool.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/simplejson/tests/test_tool.py b/simplejson/tests/test_tool.py
index ac2a14c..ebb295b 100644
--- a/simplejson/tests/test_tool.py
+++ b/simplejson/tests/test_tool.py
@@ -63,35 +63,43 @@ class TestTool(unittest.TestCase):
out, err = proc.communicate(data)
self.assertEqual(strip_python_stderr(err), ''.encode())
self.assertEqual(proc.returncode, 0)
- return out
+ return out.decode('utf8').splitlines()
def test_stdin_stdout(self):
self.assertEqual(
self.runTool(data=self.data.encode()),
- self.expect.encode())
+ self.expect.splitlines())
def test_infile_stdout(self):
- with tempfile.NamedTemporaryFile() as infile:
+ infile = tempfile.NamedTemporaryFile(delete=False)
+ try:
infile.write(self.data.encode())
- infile.flush()
+ infile.close()
self.assertEqual(
self.runTool(args=[infile.name]),
- self.expect.encode())
+ self.expect.splitlines())
+ finally:
+ os.unlink(infile.name)
def test_infile_outfile(self):
- with tempfile.NamedTemporaryFile() as infile:
+ infile = tempfile.NamedTemporaryFile(delete=False)
+ try:
infile.write(self.data.encode())
- infile.flush()
+ infile.close()
# outfile will get overwritten by tool, so the delete
# may not work on some platforms. Do it manually.
- outfile = tempfile.NamedTemporaryFile()
+ outfile = tempfile.NamedTemporaryFile(delete=False)
try:
+ outfile.close()
self.assertEqual(
self.runTool(args=[infile.name, outfile.name]),
- ''.encode())
+ [])
with open(outfile.name, 'rb') as f:
- self.assertEqual(f.read(), self.expect.encode())
+ self.assertEqual(
+ f.read().decode('utf8').splitlines(),
+ self.expect.splitlines()
+ )
finally:
- outfile.close()
- if os.path.exists(outfile.name):
- os.unlink(outfile.name)
+ os.unlink(outfile.name)
+ finally:
+ os.unlink(infile.name)