diff --git a/lib/cdist/test/emulator/__init__.py b/lib/cdist/test/emulator/__init__.py index 386969e5..91150334 100644 --- a/lib/cdist/test/emulator/__init__.py +++ b/lib/cdist/test/emulator/__init__.py @@ -37,6 +37,7 @@ class EmulatorTestCase(test.CdistTestCase): os.environ = os.environ.copy() self.temp_dir = self.mkdtemp() handle, self.script = self.mkstemp(dir=self.temp_dir) + os.close(handle) self.target_host = 'localhost' out_path = self.temp_dir self.local = local.Local(self.target_host, local_base_path, out_path) diff --git a/lib/cdist/test/exec/local.py b/lib/cdist/test/exec/local.py index d73aa079..e6f2c2b0 100644 --- a/lib/cdist/test/exec/local.py +++ b/lib/cdist/test/exec/local.py @@ -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): diff --git a/lib/cdist/test/exec/remote.py b/lib/cdist/test/exec/remote.py index 92b68d06..e111a302 100644 --- a/lib/cdist/test/exec/remote.py +++ b/lib/cdist/test/exec/remote.py @@ -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) diff --git a/lib/cdist/test/manifest/__init__.py b/lib/cdist/test/manifest/__init__.py index 00789aec..2383adf7 100644 --- a/lib/cdist/test/manifest/__init__.py +++ b/lib/cdist/test/manifest/__init__.py @@ -61,6 +61,7 @@ class ManifestTestCase(test.CdistTestCase): def test_initial_manifest_environment(self): initial_manifest = os.path.join(self.local.manifest_path, "dump_environment") handle, output_file = self.mkstemp(dir=self.temp_dir) + os.close(handle) os.environ['__cdist_test_out'] = output_file self.manifest.run_initial_manifest(initial_manifest) @@ -81,6 +82,7 @@ class ManifestTestCase(test.CdistTestCase): cdist_type = core.Type(self.local.type_path, '__dump_environment') cdist_object = core.Object(cdist_type, self.local.object_path, 'whatever') handle, output_file = self.mkstemp(dir=self.temp_dir) + os.close(handle) os.environ['__cdist_test_out'] = output_file self.manifest.run_type_manifest(cdist_object) diff --git a/lib/cdist/test/util/__init__.py b/lib/cdist/test/util/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/util/fsproperty.py b/lib/cdist/test/util/fsproperty.py new file mode 100644 index 00000000..e69de29b