9 changed files with 341 additions and 98 deletions
			
			
		| @ -0,0 +1,62 @@ | |||
| #!/usr/bin/python | |||
| # -*- coding: utf-8 -*- | |||
| # --------------------------------------------------------------------------------------------------------- | |||
| # Author : Ulrich Carmesin | |||
| # Source : gitea.ucarmesin.de | |||
| # --------------------------------------------------------------------------------------------------------- | |||
| import os | |||
| import basic.program | |||
| import basic.constants as B | |||
| import utils.path_const as P | |||
| 
 | |||
| EXP_KEY_MISSING = "key is missing {}" | |||
| EXP_KEY_DOESNT_EXIST = "key doesnt exist in domain {}" | |||
| 
 | |||
| class Catalog: | |||
|     __instance = None | |||
|     """ | |||
|     in this class there should be managed each defined key-value-pairs | |||
|     the pairs ara loaded from the path testdata/catalog: | |||
|     * initially the csv-file catalog.csv | |||
|     * on demand other csv-files in the path | |||
|     """ | |||
|     def __init__(self): | |||
|         self.catalog = {} | |||
|         Catalog.__instance = self | |||
|         pass | |||
| 
 | |||
|     @staticmethod | |||
|     def getInstance(): | |||
|         if Catalog.__instance == None: | |||
|             return Catalog() | |||
|         return Catalog.__instance | |||
| 
 | |||
|     def getValue(self, domain, key): | |||
|         """ | |||
|         this function gets the value of the domain an key | |||
| 
 | |||
|         :param domain: | |||
|         :param key: | |||
|         :return: | |||
|         """ | |||
|         job = basic.program.Job.getInstance() | |||
|         if not (isinstance(domain, str) and len(domain)): | |||
|             raise Exception(EXP_KEY_MISSING, (domain, key)) | |||
|         if not (isinstance(key, str) and len(key)): | |||
|             raise Exception(EXP_KEY_MISSING, (domain, key)) | |||
| 
 | |||
|         if domain not in self.catalog: | |||
|             self.readDomain(domain) | |||
|         if key not in self.catalog[domain][key]: | |||
|             raise Exception(EXP_KEY_DOESNT_EXIST, (domain, key)) | |||
|         return self.catalog[domain][key] | |||
| 
 | |||
|     def readDomain(self, domain): | |||
|         """ | |||
| 
 | |||
|         :param domain: | |||
|         :return: | |||
|         """ | |||
|         job = basic.program.Job.getInstance() | |||
|         if not (isinstance(domain, str) and len(domain)): | |||
|             raise Exception(EXP_KEY_MISSING, (domain)) | |||
| @ -0,0 +1,50 @@ | |||
| import unittest | |||
| import os | |||
| import inspect | |||
| import utils.path_tool | |||
| import basic.program | |||
| import basic.constants as B | |||
| import test.constants | |||
| import test.testtools | |||
| import utils.path_const as P | |||
| import basic.catalog | |||
| 
 | |||
| HOME_PATH = test.constants.HOME_PATH | |||
| OS_SYSTEM = test.constants.OS_SYSTEM | |||
| 
 | |||
| # here you can select single testfunction for developping the tests | |||
| TEST_FUNCTIONS = ["test_key", "test_rejoinPath", "test_rejoinPath", "test_composePath", "test_composePattern", | |||
|                   "test_extractPath",  "test_extractPattern"] | |||
| #TEST_FUNCTIONS = [ "test_extractPath"] | |||
| 
 | |||
| class MyTestCase(unittest.TestCase): | |||
|     mymsg = "--------------------------------------------------------------" | |||
| 
 | |||
|     def test_class(self): | |||
|         global mymsg | |||
|         actfunction = str(inspect.currentframe().f_code.co_name) | |||
|         cnttest = 0 | |||
|         if actfunction not in TEST_FUNCTIONS: | |||
|             return | |||
|         job = test.testtools.getJob() | |||
|         catalog = basic.catalog.Catalog.getInstance() | |||
|         self.assertIsNotNone(catalog) | |||
|         MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) | |||
| 
 | |||
| 
 | |||
|     def test_key(self): | |||
|         global mymsg | |||
|         actfunction = str(inspect.currentframe().f_code.co_name) | |||
|         cnttest = 0 | |||
|         if actfunction not in TEST_FUNCTIONS: | |||
|             return | |||
|         job = test.testtools.getJob() | |||
|         MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) | |||
| 
 | |||
| 
 | |||
|     def test_zzz(self): | |||
|         print(MyTestCase.mymsg) | |||
| 
 | |||
| 
 | |||
| if __name__ == '__main__': | |||
|     unittest.main() | |||
					Loading…
					
					
				
		Reference in new issue