diff --git a/lib/cdist/test/__init__.py b/lib/cdist/test/__init__.py index 2c6abd36..faa9dc2d 100644 --- a/lib/cdist/test/__init__.py +++ b/lib/cdist/test/__init__.py @@ -20,8 +20,19 @@ # import os +import unittest +import tempfile cdist_base_path = os.path.abspath( os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../")) cdist_exec_path = os.path.join(cdist_base_path, "bin/cdist") + + +class CdistTestCase(unittest.TestCase): + + def mkdtemp(self, **kwargs): + return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) + + def mkstemp(self, **kwargs): + return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) diff --git a/lib/cdist/test/code/__init__.py b/lib/cdist/test/code/__init__.py index 68e8a41d..2f061086 100644 --- a/lib/cdist/test/code/__init__.py +++ b/lib/cdist/test/code/__init__.py @@ -20,8 +20,6 @@ # import os -import tempfile -import unittest import shutil import getpass import logging @@ -38,13 +36,7 @@ my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') local_base_path = fixtures -class CodeTestCase(unittest.TestCase): - - def mkdtemp(self, **kwargs): - return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) - - def mkstemp(self, **kwargs): - return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) +class CodeTestCase(test.CdistTestCase): def setUp(self): self.target_host = 'localhost' diff --git a/lib/cdist/test/emulator/__init__.py b/lib/cdist/test/emulator/__init__.py index ccdda265..386969e5 100644 --- a/lib/cdist/test/emulator/__init__.py +++ b/lib/cdist/test/emulator/__init__.py @@ -20,8 +20,6 @@ # import os -import tempfile -import unittest import shutil from cdist import test @@ -32,13 +30,7 @@ from cdist import core local_base_path = test.cdist_base_path -class EmulatorTestCase(unittest.TestCase): - - def mkdtemp(self, **kwargs): - return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) - - def mkstemp(self, **kwargs): - return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) +class EmulatorTestCase(test.CdistTestCase): def setUp(self): self.orig_environ = os.environ diff --git a/lib/cdist/test/exec/local.py b/lib/cdist/test/exec/local.py index f19bf55c..d73aa079 100644 --- a/lib/cdist/test/exec/local.py +++ b/lib/cdist/test/exec/local.py @@ -19,9 +19,7 @@ # # -import unittest import os -import tempfile import getpass import shutil import string @@ -31,6 +29,7 @@ import random #logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s') import cdist +from cdist import test from cdist.exec import local import os.path as op @@ -39,13 +38,7 @@ fixtures = op.join(my_dir, 'fixtures') local_base_path = fixtures -class LocalTestCase(unittest.TestCase): - - def mkdtemp(self, **kwargs): - return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) - - def mkstemp(self, **kwargs): - return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) +class LocalTestCase(test.CdistTestCase): def setUp(self): self.temp_dir = self.mkdtemp() diff --git a/lib/cdist/test/exec/remote.py b/lib/cdist/test/exec/remote.py index f5151156..191cbd43 100644 --- a/lib/cdist/test/exec/remote.py +++ b/lib/cdist/test/exec/remote.py @@ -19,9 +19,7 @@ # # -import unittest import os -import tempfile import getpass import shutil import string @@ -31,13 +29,7 @@ import cdist from cdist.exec import remote -class RemoteTestCase(unittest.TestCase): - - def mkdtemp(self, **kwargs): - return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) - - def mkstemp(self, **kwargs): - return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) +class RemoteTestCase(test.CdistTestCase): def setUp(self): self.temp_dir = self.mkdtemp() diff --git a/lib/cdist/test/explorer/__init__.py b/lib/cdist/test/explorer/__init__.py index 42b83ee8..18815f07 100644 --- a/lib/cdist/test/explorer/__init__.py +++ b/lib/cdist/test/explorer/__init__.py @@ -21,8 +21,6 @@ # import os -import tempfile -import unittest import shutil import getpass import logging @@ -39,13 +37,7 @@ my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') local_base_path = fixtures -class ExplorerClassTestCase(unittest.TestCase): - - def mkdtemp(self, **kwargs): - return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) - - def mkstemp(self, **kwargs): - return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) +class ExplorerClassTestCase(test.CdistTestCase): def setUp(self): self.target_host = 'localhost' diff --git a/lib/cdist/test/manifest/__init__.py b/lib/cdist/test/manifest/__init__.py index 257311d7..00789aec 100644 --- a/lib/cdist/test/manifest/__init__.py +++ b/lib/cdist/test/manifest/__init__.py @@ -19,9 +19,7 @@ # # -import unittest import os -import tempfile import getpass import shutil import string @@ -31,6 +29,7 @@ import io import sys import cdist +from cdist import test from cdist.exec import local from cdist import core from cdist.core import manifest @@ -41,13 +40,7 @@ fixtures = op.join(my_dir, 'fixtures') local_base_path = fixtures -class ManifestTestCase(unittest.TestCase): - - def mkdtemp(self, **kwargs): - return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) - - def mkstemp(self, **kwargs): - return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) +class ManifestTestCase(test.CdistTestCase): def setUp(self): self.orig_environ = os.environ diff --git a/lib/cdist/test/object/__init__.py b/lib/cdist/test/object/__init__.py index ab05c7af..6681c916 100644 --- a/lib/cdist/test/object/__init__.py +++ b/lib/cdist/test/object/__init__.py @@ -20,10 +20,9 @@ # import os -import tempfile -import unittest import shutil +from cdist import test from cdist import core import os.path as op @@ -32,7 +31,7 @@ fixtures = op.join(my_dir, 'fixtures') object_base_path = op.join(fixtures, 'object') type_base_path = op.join(fixtures, 'type') -class ObjectClassTestCase(unittest.TestCase): +class ObjectClassTestCase(test.CdistTestCase): def test_list_object_names(self): object_names = list(core.Object.list_object_names(object_base_path)) @@ -52,7 +51,7 @@ class ObjectClassTestCase(unittest.TestCase): self.assertEqual(objects, objects_expected) -class ObjectIdTestCase(unittest.TestCase): +class ObjectIdTestCase(test.CdistTestCase): def test_object_id_starts_with_slash(self): cdist_type = core.Type(type_base_path, '__third') illegal_object_id = '/object_id/may/not/start/with/slash' @@ -66,7 +65,7 @@ class ObjectIdTestCase(unittest.TestCase): core.Object(cdist_type, object_base_path, illegal_object_id) -class ObjectTestCase(unittest.TestCase): +class ObjectTestCase(test.CdistTestCase): def setUp(self): self.cdist_type = core.Type(type_base_path, '__third') diff --git a/lib/cdist/test/type/__init__.py b/lib/cdist/test/type/__init__.py index dee9d7a6..7bb8654c 100644 --- a/lib/cdist/test/type/__init__.py +++ b/lib/cdist/test/type/__init__.py @@ -20,8 +20,8 @@ # import os -import unittest +from cdist import test from cdist import core import os.path as op @@ -29,7 +29,7 @@ my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -class TypeTestCase(unittest.TestCase): +class TypeTestCase(test.CdistTestCase): def test_list_type_names(self): base_path = op.join(fixtures, 'list_types') @@ -145,11 +145,3 @@ class TypeTestCase(unittest.TestCase): base_path = fixtures cdist_type = core.Type(base_path, '__without_optional_parameters') self.assertEqual(cdist_type.optional_parameters, []) - -''' -suite = unittest.TestLoader().loadTestsFromTestCase(ObjectTestCase) - -def suite(): - tests = [] - return unittest.TestSuite(map(ObjectTestCase, tests)) -'''