introduce new cdist.test.CdistTestCase base class which handles common tasks
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								56787617d0
							
						
					
				
			
			
				commit
				
					
						97ab6effa4
					
				
			
		
					 9 changed files with 25 additions and 69 deletions
				
			
		|  | @ -20,8 +20,19 @@ | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import os | import os | ||||||
|  | import unittest | ||||||
|  | import tempfile | ||||||
| 
 | 
 | ||||||
| cdist_base_path = os.path.abspath( | cdist_base_path = os.path.abspath( | ||||||
|     os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../")) |     os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../")) | ||||||
| 
 | 
 | ||||||
| cdist_exec_path = os.path.join(cdist_base_path, "bin/cdist") | 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) | ||||||
|  |  | ||||||
|  | @ -20,8 +20,6 @@ | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import os | import os | ||||||
| import tempfile |  | ||||||
| import unittest |  | ||||||
| import shutil | import shutil | ||||||
| import getpass | import getpass | ||||||
| import logging | import logging | ||||||
|  | @ -38,13 +36,7 @@ my_dir = op.abspath(op.dirname(__file__)) | ||||||
| fixtures = op.join(my_dir, 'fixtures') | fixtures = op.join(my_dir, 'fixtures') | ||||||
| local_base_path = fixtures | local_base_path = fixtures | ||||||
| 
 | 
 | ||||||
| class CodeTestCase(unittest.TestCase): | class CodeTestCase(test.CdistTestCase): | ||||||
| 
 |  | ||||||
|     def mkdtemp(self, **kwargs): |  | ||||||
|         return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 |  | ||||||
|     def mkstemp(self, **kwargs): |  | ||||||
|         return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.target_host = 'localhost' |         self.target_host = 'localhost' | ||||||
|  |  | ||||||
|  | @ -20,8 +20,6 @@ | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import os | import os | ||||||
| import tempfile |  | ||||||
| import unittest |  | ||||||
| import shutil | import shutil | ||||||
| 
 | 
 | ||||||
| from cdist import test | from cdist import test | ||||||
|  | @ -32,13 +30,7 @@ from cdist import core | ||||||
| local_base_path = test.cdist_base_path | local_base_path = test.cdist_base_path | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class EmulatorTestCase(unittest.TestCase): | class EmulatorTestCase(test.CdistTestCase): | ||||||
| 
 |  | ||||||
|     def mkdtemp(self, **kwargs): |  | ||||||
|         return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 |  | ||||||
|     def mkstemp(self, **kwargs): |  | ||||||
|         return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.orig_environ = os.environ |         self.orig_environ = os.environ | ||||||
|  |  | ||||||
|  | @ -19,9 +19,7 @@ | ||||||
| # | # | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import unittest |  | ||||||
| import os | import os | ||||||
| import tempfile |  | ||||||
| import getpass | import getpass | ||||||
| import shutil | import shutil | ||||||
| import string | import string | ||||||
|  | @ -31,6 +29,7 @@ import random | ||||||
| #logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s') | #logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s') | ||||||
| 
 | 
 | ||||||
| import cdist | import cdist | ||||||
|  | from cdist import test | ||||||
| from cdist.exec import local | from cdist.exec import local | ||||||
| 
 | 
 | ||||||
| import os.path as op | import os.path as op | ||||||
|  | @ -39,13 +38,7 @@ fixtures = op.join(my_dir, 'fixtures') | ||||||
| local_base_path = fixtures | local_base_path = fixtures | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class LocalTestCase(unittest.TestCase): | class LocalTestCase(test.CdistTestCase): | ||||||
| 
 |  | ||||||
|     def mkdtemp(self, **kwargs): |  | ||||||
|         return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 |  | ||||||
|     def mkstemp(self, **kwargs): |  | ||||||
|         return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.temp_dir = self.mkdtemp() |         self.temp_dir = self.mkdtemp() | ||||||
|  |  | ||||||
|  | @ -19,9 +19,7 @@ | ||||||
| # | # | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import unittest |  | ||||||
| import os | import os | ||||||
| import tempfile |  | ||||||
| import getpass | import getpass | ||||||
| import shutil | import shutil | ||||||
| import string | import string | ||||||
|  | @ -31,13 +29,7 @@ import cdist | ||||||
| from cdist.exec import remote | from cdist.exec import remote | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class RemoteTestCase(unittest.TestCase): | class RemoteTestCase(test.CdistTestCase): | ||||||
| 
 |  | ||||||
|     def mkdtemp(self, **kwargs): |  | ||||||
|         return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 |  | ||||||
|     def mkstemp(self, **kwargs): |  | ||||||
|         return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.temp_dir = self.mkdtemp() |         self.temp_dir = self.mkdtemp() | ||||||
|  |  | ||||||
|  | @ -21,8 +21,6 @@ | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import os | import os | ||||||
| import tempfile |  | ||||||
| import unittest |  | ||||||
| import shutil | import shutil | ||||||
| import getpass | import getpass | ||||||
| import logging | import logging | ||||||
|  | @ -39,13 +37,7 @@ my_dir = op.abspath(op.dirname(__file__)) | ||||||
| fixtures = op.join(my_dir, 'fixtures') | fixtures = op.join(my_dir, 'fixtures') | ||||||
| local_base_path = fixtures | local_base_path = fixtures | ||||||
| 
 | 
 | ||||||
| class ExplorerClassTestCase(unittest.TestCase): | class ExplorerClassTestCase(test.CdistTestCase): | ||||||
| 
 |  | ||||||
|     def mkdtemp(self, **kwargs): |  | ||||||
|         return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 |  | ||||||
|     def mkstemp(self, **kwargs): |  | ||||||
|         return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.target_host = 'localhost' |         self.target_host = 'localhost' | ||||||
|  |  | ||||||
|  | @ -19,9 +19,7 @@ | ||||||
| # | # | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import unittest |  | ||||||
| import os | import os | ||||||
| import tempfile |  | ||||||
| import getpass | import getpass | ||||||
| import shutil | import shutil | ||||||
| import string | import string | ||||||
|  | @ -31,6 +29,7 @@ import io | ||||||
| import sys | import sys | ||||||
| 
 | 
 | ||||||
| import cdist | import cdist | ||||||
|  | from cdist import test | ||||||
| from cdist.exec import local | from cdist.exec import local | ||||||
| from cdist import core | from cdist import core | ||||||
| from cdist.core import manifest | from cdist.core import manifest | ||||||
|  | @ -41,13 +40,7 @@ fixtures = op.join(my_dir, 'fixtures') | ||||||
| local_base_path = fixtures | local_base_path = fixtures | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ManifestTestCase(unittest.TestCase): | class ManifestTestCase(test.CdistTestCase): | ||||||
| 
 |  | ||||||
|     def mkdtemp(self, **kwargs): |  | ||||||
|         return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 |  | ||||||
|     def mkstemp(self, **kwargs): |  | ||||||
|         return tempfile.mkstemp(prefix='tmp.cdist.test.', **kwargs) |  | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.orig_environ = os.environ |         self.orig_environ = os.environ | ||||||
|  |  | ||||||
|  | @ -20,10 +20,9 @@ | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import os | import os | ||||||
| import tempfile |  | ||||||
| import unittest |  | ||||||
| import shutil | import shutil | ||||||
| 
 | 
 | ||||||
|  | from cdist import test | ||||||
| from cdist import core | from cdist import core | ||||||
| 
 | 
 | ||||||
| import os.path as op | import os.path as op | ||||||
|  | @ -32,7 +31,7 @@ fixtures = op.join(my_dir, 'fixtures') | ||||||
| object_base_path = op.join(fixtures, 'object') | object_base_path = op.join(fixtures, 'object') | ||||||
| type_base_path = op.join(fixtures, 'type') | type_base_path = op.join(fixtures, 'type') | ||||||
| 
 | 
 | ||||||
| class ObjectClassTestCase(unittest.TestCase): | class ObjectClassTestCase(test.CdistTestCase): | ||||||
| 
 | 
 | ||||||
|     def test_list_object_names(self): |     def test_list_object_names(self): | ||||||
|         object_names = list(core.Object.list_object_names(object_base_path)) |         object_names = list(core.Object.list_object_names(object_base_path)) | ||||||
|  | @ -52,7 +51,7 @@ class ObjectClassTestCase(unittest.TestCase): | ||||||
|         self.assertEqual(objects, objects_expected) |         self.assertEqual(objects, objects_expected) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ObjectIdTestCase(unittest.TestCase): | class ObjectIdTestCase(test.CdistTestCase): | ||||||
|     def test_object_id_starts_with_slash(self): |     def test_object_id_starts_with_slash(self): | ||||||
|         cdist_type = core.Type(type_base_path, '__third') |         cdist_type = core.Type(type_base_path, '__third') | ||||||
|         illegal_object_id = '/object_id/may/not/start/with/slash' |         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) |             core.Object(cdist_type, object_base_path, illegal_object_id) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ObjectTestCase(unittest.TestCase): | class ObjectTestCase(test.CdistTestCase): | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.cdist_type = core.Type(type_base_path, '__third') |         self.cdist_type = core.Type(type_base_path, '__third') | ||||||
|  |  | ||||||
|  | @ -20,8 +20,8 @@ | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| import os | import os | ||||||
| import unittest |  | ||||||
| 
 | 
 | ||||||
|  | from cdist import test | ||||||
| from cdist import core | from cdist import core | ||||||
| 
 | 
 | ||||||
| import os.path as op | import os.path as op | ||||||
|  | @ -29,7 +29,7 @@ my_dir = op.abspath(op.dirname(__file__)) | ||||||
| fixtures = op.join(my_dir, 'fixtures') | fixtures = op.join(my_dir, 'fixtures') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TypeTestCase(unittest.TestCase): | class TypeTestCase(test.CdistTestCase): | ||||||
| 
 | 
 | ||||||
|     def test_list_type_names(self): |     def test_list_type_names(self): | ||||||
|         base_path = op.join(fixtures, 'list_types') |         base_path = op.join(fixtures, 'list_types') | ||||||
|  | @ -145,11 +145,3 @@ class TypeTestCase(unittest.TestCase): | ||||||
|         base_path = fixtures |         base_path = fixtures | ||||||
|         cdist_type = core.Type(base_path, '__without_optional_parameters') |         cdist_type = core.Type(base_path, '__without_optional_parameters') | ||||||
|         self.assertEqual(cdist_type.optional_parameters, []) |         self.assertEqual(cdist_type.optional_parameters, []) | ||||||
| 
 |  | ||||||
| ''' |  | ||||||
| suite = unittest.TestLoader().loadTestsFromTestCase(ObjectTestCase) |  | ||||||
| 
 |  | ||||||
| def suite(): |  | ||||||
|     tests = [] |  | ||||||
|     return unittest.TestSuite(map(ObjectTestCase, tests)) |  | ||||||
| ''' |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue