close file handles opened with tempfile.mkstemp

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-10-21 15:26:27 +02:00
commit d4e715f052
6 changed files with 17 additions and 18 deletions

View file

@ -90,23 +90,20 @@ class LocalTestCase(test.CdistTestCase):
def test_run_script_success(self):
handle, script = self.mkstemp(dir=self.temp_dir)
fd = open(script, "w")
fd.writelines(["#!/bin/sh\n", "/bin/true"])
fd.close()
with os.fdopen(handle, "w") as fd:
fd.writelines(["#!/bin/sh\n", "/bin/true"])
self.local.run_script(script)
def test_run_script_fail(self):
handle, script = self.mkstemp(dir=self.temp_dir)
fd = open(script, "w")
fd.writelines(["#!/bin/sh\n", "/bin/false"])
fd.close()
with os.fdopen(handle, "w") as fd:
fd.writelines(["#!/bin/sh\n", "/bin/false"])
self.assertRaises(local.LocalScriptError, self.local.run_script, script)
def test_run_script_get_output(self):
handle, script = self.mkstemp(dir=self.temp_dir)
fd = open(script, "w")
fd.writelines(["#!/bin/sh\n", "echo foobar"])
fd.close()
with os.fdopen(handle, "w") as fd:
fd.writelines(["#!/bin/sh\n", "echo foobar"])
self.assertEqual(self.local.run_script(script, return_output=True), "foobar\n")
def test_mkdir(self):