close file handles opened with tempfile.mkstemp
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
1e354387f9
commit
d4e715f052
6 changed files with 17 additions and 18 deletions
|
|
@ -68,23 +68,20 @@ class RemoteTestCase(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.remote.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(remote.RemoteScriptError, self.remote.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.remote.run_script(script, return_output=True), "foobar\n")
|
||||
|
||||
def test_mkdir(self):
|
||||
|
|
@ -100,6 +97,7 @@ class RemoteTestCase(test.CdistTestCase):
|
|||
|
||||
def test_transfer_file(self):
|
||||
handle, source = self.mkstemp(dir=self.temp_dir)
|
||||
os.close(handle)
|
||||
target = self.mkdtemp(dir=self.temp_dir)
|
||||
self.remote.transfer(source, target)
|
||||
self.assertTrue(os.path.isfile(target))
|
||||
|
|
@ -108,6 +106,7 @@ class RemoteTestCase(test.CdistTestCase):
|
|||
source = self.mkdtemp(dir=self.temp_dir)
|
||||
# put a file in the directory as payload
|
||||
handle, source_file = self.mkstemp(dir=source)
|
||||
os.close(handle)
|
||||
source_file_name = os.path.split(source_file)[-1]
|
||||
target = self.mkdtemp(dir=self.temp_dir)
|
||||
self.remote.transfer(source, target)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue