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 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) | ||||
|  |  | |||
|  | @ -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' | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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() | ||||
|  |  | |||
|  | @ -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() | ||||
|  |  | |||
|  | @ -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' | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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') | ||||
|  |  | |||
|  | @ -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)) | ||||
| ''' | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue