diff --git a/basic/constants.py b/basic/constants.py index ab9b56e..b47cfb3 100644 --- a/basic/constants.py +++ b/basic/constants.py @@ -18,7 +18,7 @@ The constants desribes the keywords of the main datastructures, these are * test-specification with testdata - stored in external testdata-folder * the internal datastructure """ - +import os # ------------------------------------------------------------- # values and keywords @@ -30,6 +30,7 @@ SVAL_NULL = "null" # ------------------------------------------------------------- # parameter with arguments +PAR_PROGRAM = 'program' PAR_PROJ = 'project' """ definition of the project which will be tested """ PAR_APP = 'application' @@ -40,6 +41,8 @@ PAR_VAR = 'variant' """ definition of a variant dataflow especially the channel """ PAR_REL = 'release' """ definition of the release of the application which will be tested """ +PAR_BASEDIR = 'basedir' +PAR_DIRNAME = 'dirname' PAR_TSDIR = 'tsdir' """ definition of the directory of the testsuite for summaries of the testcases """ PAR_TCDIR = 'tcdir' @@ -58,6 +61,7 @@ PAR_FCT = 'function' PAR_TOOL = 'tool' PAR_STEP = 'step' PAR_DESCRIPT = 'desription' +PAR_STRING = 'parstring' """ """ PAR_TESTCASE = "testcase" PAR_TESTCASES = "testcases" @@ -254,3 +258,17 @@ EXP_NO_BASIS_FILE = "basis file cant be found" EXCEPT_NOT_IMPLEMENT = "method is not implemented" EXCEPT_NOT_INITIALIZED = "class is not initialized" + +home = os.getcwd() +prgdir = "" +if home[-4:] == "test": + home = home[0:-5] +if home[-10:] == "components": + home = home[0:-11] +if home[-9:] == "program": + prgdir = home[-6:] + home = home[0:-7] +elif home[-7:] == "program": + prgdir = home[-7:] + home = home[0:-8] +HOME_PATH = home diff --git a/basic/message.py b/basic/message.py index 6ed6144..ffa769b 100644 --- a/basic/message.py +++ b/basic/message.py @@ -32,7 +32,7 @@ MTEXT_MSG = "msg" MTEXT_INFO = "info" MTEXT_DEBUG = "debug" MTEXT_TRACE = "trace" -LIST_MTEXT = [MTEXT_FATAL, MTEXT_ERROR, MTEXT_WARN, MTEXT_MSG, MTEXT_INFO, MTEXT_DEBUG, MTEXT_TRACE] +LIST_MTEXT = [MTEXT_FATAL, MTEXT_ERROR, MTEXT_WARN, MTEXT_MSG, MTEXT_INFO, MTEXT_DEBUG, MTEXT_TRACE, MTEXT_TRACE] LIMIT_FATAL = 2 LIMIT_ERROR = 4 @@ -127,10 +127,10 @@ class Message: "debug": "0", # wird nur in debug ausgegeben, wenn log-level hoechstens auf eingestelltem job-level steht "trace": "0", # wird nur in debug ausgegeben, wenn log-level hoechstens auf eingestelltem job-level steht """ - def __init__(self, job, level, logTime, componente): - # (self, componente, out, level): + def __init__(self, job, level, logTime, compName=None): + # (self, compName, out, level): self.job = job - self.componente = componente # dezantrales Logsystem + self.compName = compName # dezentrales Logsystem verify = LIMIT_DEBUG self.rc = RC_INFO if isinstance(level, str): @@ -144,18 +144,16 @@ class Message: self.level = LIMIT_DEBUG else: self.level = level - self.openDebug(job, logTime, componente) - self.openLog(job, logTime, componente) + self.openDebug(job, logTime, compName) + self.openLog(job, logTime, compName) self.topmessage = "" - print("message initialisiert mit level " + str(self.level)) - - def openDebug(self, job, logTime, componente): + def openDebug(self, job, logTime, compName): path = job.conf[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG] if not os.path.exists(path): os.mkdir(path) logTime = logTime[0:11] + "0000" - if componente is None: + if compName is None: if hasattr(job.m, "debugpath"): self.debugpath = job.m.debugpath self.debugfile = job.m.debugfile @@ -163,13 +161,13 @@ class Message: else: self.debugpath = os.path.join(path, "debug_"+logTime+".txt") else: - self.debugpath = os.path.join(path, "debug_" + componente.name + "_" + logTime + ".txt") + self.debugpath = os.path.join(path, "debug_" + compName + "_" + logTime + ".txt") if os.path.exists(self.debugpath): self.debugfile = open(self.debugpath, "a") else: self.debugfile = open(self.debugpath, "w") - def openLog(self, job, logTime, componente): + def openLog(self, job, logTime, compName): if not hasattr(job, "par"): return pathPattern = job.programDef["logpath"] @@ -177,7 +175,7 @@ class Message: parent = os.path.dirname(path) if not os.path.exists(parent): os.makedirs(parent) - if componente is None: + if compName is None: self.logpath = path self.logfile = open(path, "w") else: @@ -207,23 +205,43 @@ class Message: self.logfile.close() self.debugfile.close() + def getLogLevel(self, tool="", comp=None): + """ + gets the decreasing level depending on tool and component + if these arguments matches with a job-parameter the level decreases + :param tool: + :param comp: + :return: + """ + out = 0 + job = self.job + if comp is not None and hasattr(job.par, "component") and comp.name in getattr(job.par, "component"): + out += 2 + if tool != "" and hasattr(job.par, "tool") and tool in getattr(job.par, "tool"): + out += 2 + return out + def setRc(self, rc, text): - job = self.job #basic.program.Job.getInstance() - if (int(rc) > self.rc): + if (int(rc) > self.rc) or (self.topmessage == ""): self.rc = rc - # TODO quickfix - self.topmessage = ": " + text - elif (int(rc) == self.rc): - self.topmessage = ": " + text - - def isRc(self, rc): - rcId = 0 # int(int(self.CONST_ERRTYP[rc]) / 4 - RC_OFFSET) - print("< < < isRc " + str(self.rc) + " <=? " + str(rcId)) - if self.rc <= int(rcId): - print("return True") + i = rc * -1 + 3 + if i < 0: return + self.topmessage = LIST_MTEXT[i].upper() + ": " + text + + def isRc(self, returnCode): + """ + prueft, ob der gesetzte ReturnCode mit dem angefragten ReturnCode vereinbar ist + Beispiel: gesetzt WARN, angefragt ERROR ist OK=True, anders herum: KO=False + :param returnCode: + :return: + """ + if isinstance(returnCode, int): + rcId = returnCode + else: + rcId = ( LIST_MTEXT.index(returnCode.lower()) - 3 ) * (-1) + if self.rc <= int(rcId) or rcId < 0: return True else: - print("return False") return False def getFinalRc(self): @@ -379,7 +397,7 @@ class Message: """ eigentliche Schreibroutine: hierin wird debug-Level beruecksichtgigt""" if (args["mlevel"] + args["mprio"] > int(self.level)): return - elif (self.componente is None): # and self.logfile.closed == False: + elif (self.compName is None): # and self.logfile.closed == False: try: self.logfile.write(args["mtext"] + "\n") except: diff --git a/basic/program.py b/basic/program.py index 2a9d4a3..6524c13 100644 --- a/basic/program.py +++ b/basic/program.py @@ -30,6 +30,8 @@ import tools.job_tool LIMIT_INFO = 16 #basic.message.LIMIT_INFO LIMIT_DEBUG = 12 #basic.message.LIMIT_DEBUG +TOOL_NAME = "job_tool" + CTLG_NAME = "programs" CTLG_PARDEF = "pardef" CTLG_PARSOURCE = "pfilesource" @@ -102,12 +104,9 @@ def createJob(pprg="", pgran="", papp="", penv="", ptstamp="", pmode=""): path = T.DATA_PATH + "/workspace/" job = basic.program.Job(prgname) - # job.conf[B.SUBJECT_PATH]["components"] = T.COMP_PATH args = {"application": app, "environment": env, "modus": mode, gran + "time": tstamp, gran + "dir": path, "step": 1} - print(str(args)) - # "usecase": "TST001", "tstime": "2022-03-17_17-28"} job.par.setParameterArgs(job, args) return job @@ -190,7 +189,6 @@ class Job: # - job.conf with basis config # - job.par with parameter-args or cli-args # - job.msg - print("################# init Job ## " + program + " #################") # logtime muss unique sein denn logDateien und Verzeichnisse muessen eindeutig sein logTime = tools.date_tool.getActdate(tools.date_tool.F_LOG) while logTime <= Job.__logtime: @@ -212,8 +210,6 @@ class Job: self.programDef = catalog.getValue(self, CTLG_NAME, program, "") try: path = tools.config_tool.getConfigPath(self, P.KEY_BASIC, B.BASIS_FILE) - print("comps.basispath "+path) - # conf = self.readConfiguration(path) self.conf = self.getConfiguration(path) except: print("FATAL: config-file could not be loaded") @@ -257,19 +253,6 @@ class Job: conf[k] = v return conf - def murks(self, par, program): - self.par = par - dirpath = self.par.getDirParameter() - setGlobal() - if dirpath is not None: - tools.path_tool.extractPath(dirpath[0], dirpath[1]) - if program == "unit": # no job will be started - self.start = datetime.now() - logTime = self.start.strftime("%Y%m%d_%H%M%S") - self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None) - print("prog-50 " + str(self.par.basedir)) - - def setProgram(self, program): self.program = program basedir = self.programDef[CTLG_BASEDIR] @@ -284,16 +267,13 @@ class Job: if not hasattr(self.par, self.programDef[B.PAR_DIRNAME]): setattr(self.par, self.programDef[B.PAR_DIRNAME], tools.path_tool.compose_path(self, "{"+basedir+"}", None)) - print(parstring) self.par.setParameterLoaded(self) def startJob(self): self.start = datetime.now() - print("prog-68 " + str(self.par.basedir)) logTime = self.start.strftime("%Y%m%d_%H%M%S") self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None) - print("prog-68 " + str(self.m.rc)) tools.job_tool.startJobProcesses(self) self.par.setParameterLoaded(self) self.m.logInfo("# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ") @@ -349,10 +329,8 @@ class Job: if len(str(self.programDef[CTLG_PARSOURCE])) < 2: return None parpath = tools.path_tool.compose_path(self, self.programDef[CTLG_PARSOURCE], None) - print("parpath "+parpath) if not os.path.join(parpath): return None - print("parpath "+parpath) doc = tools.file_tool.readFileDict(self, parpath, None) for k in doc.keys(): output[k] = copy.deepcopy(doc[k]) @@ -389,7 +367,6 @@ class Job: :return: """ if hasattr(self.par, parameter): - print (parameter + " in Parameter") if getattr(self.par, parameter).find(elem) >= 0: return True return False @@ -433,11 +410,8 @@ class Job: def getTraceLevel(self, elem): return self.getMessageLevel("trace", elem) def debug(self, prio, text): - #print("job.debug "+str(prio)+" "+text) if hasattr(self, "m"): self.m.debug(prio, text) - else: - print(text) def getConfiguration(job, path): conf = {} @@ -466,9 +440,7 @@ class Parameter: + dirname of work-folder either from dir-parameter or composed from single parameter comparison with a parameter-file from the work-folder """ - print ("class Parameter") def __init__ (self, job, args=None): - print ("# init Parameter for " + job.program) self.program = job.program if args is not None and isinstance(args, dict): self.setParameterArgs(job, args) @@ -476,7 +448,6 @@ class Parameter: self.setParameter(job) self.basedir = job.programDef[B.PAR_BASEDIR] job.basedir = job.programDef[B.PAR_BASEDIR] - print (f"# Parameter initialisiert {self.program} mit basedir {self.basedir}") job.par = self # Parameter aus Verzeichnis extraieren bzw. Verzeichnis aus Parameter erstellen if not hasattr(self, job.programDef[B.PAR_DIRNAME]): @@ -494,7 +465,6 @@ class Parameter: print (f"Parameter initialisiert {self.program}") pardef = self.programDef[CTLG_PARDEF] for p in pardef.split(","): - print(p) if len(p) > 1 and not hasattr(self, p): job.m.setFatal("Parameter " + p + " is not set!") @@ -517,8 +487,6 @@ class Parameter: 12. funktion -- schraenkt Verarbeitung auf parametriserte Funktionen ein 13. tool -- schraenkt Protokollierung/Verarbeitung auf parametriserte Tools ein """ - # args = str(sys.argv) - # print ("Job-Programm %s : " % args) parser = argparse.ArgumentParser() parser.add_argument('-a', '--'+B.SUBJECT_APPS, required=True, action='store') parser.add_argument('-e', '--'+B.PAR_ENV, required=True, action='store') @@ -552,7 +520,6 @@ class Parameter: def setParameterArgs(self, job, args): - print("setParArgs " + str(type(args))) self.parstring = "python " + self.program if "dict" in str(type(args)): for k in args: @@ -562,8 +529,6 @@ class Parameter: if getattr(args, k) is not None: self.setJobAttr(k , getattr(args, k)) dirpath = self.getDirParameter() - #if dirpath is not None: - # tools.path_tool.extractPath(job, dirpath[0], dirpath[1]) if hasattr(self, "application") and B.SUBJECT_APPS in job.conf \ and getattr(self, "application") in job.conf[B.SUBJECT_APPS]: if B.ATTR_APPS_PROJECT in job.conf[B.SUBJECT_APPS][self.application]: @@ -573,10 +538,8 @@ class Parameter: def setParameterLoaded(self, job): #job = Job.getInstance() - print("setParLoaded "+job.program) readedPar = job.loadParameter() if readedPar is not None: - print(str(readedPar)) for k in readedPar["par"].keys(): if not hasattr(self, k): self.setJobAttr(k, readedPar["par"][k]) diff --git a/catalog/programs.csv b/catalog/programs.csv index 30eafe5..c9e517f 100644 --- a/catalog/programs.csv +++ b/catalog/programs.csv @@ -1,21 +1,21 @@ -_key;name;;;;;;;;;;;; -table:programs;name;objtype;objname;time;env;app;variant;pardef;pfilesource;pfiletarget;basedir;loglevel;logpath -;test_executer;tp,ts,tc;m;m;m;m;o;;;;{objtype}base;info;{job.par.wsdir}/{log}/log_{job.start}.txt -;init_testsuite;ts;m;o;m;m;o;;envparfile;tsparfile;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt -;execute_testsuite;ts;m;m;m;m;o;;tsparfile;tsparfile;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt -;collect_testsuite;ts;m;m;m;m;o;;tsparfile;tsparfile;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt -;finish_testsuite;ts;m;m;m;m;o;;tsparfile;tsparfile;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt -;unzip_testsuite;ts;m;m;m;m;o;;;;;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt -;init_testcase;tc;m;o;m;m;o;;tsparfile;tcparfile;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt -;exec_testcase;tc;m;m;m;m;o;;tcparfile;tcparfile;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt -;collect_testcase;tc;m;m;m;m;o;;tcparfile;tcparfile;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt -;compare_testcase;tc;m;m;m;m;o;;tcparfile;tcparfile;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt -;check_environment;env;;;m;;o;;;envparfile;envbase;info;{job.par.envdir}/{log}/log_{job.start}.txt -;check_specification;tp,ts,tc;o;;;;;;;;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt -;check_configuration;ws;o;;;o;;;;;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt -;make_workspace;ws;;;_;;;;;;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt -;unit_tester;ws;o;;d;;;;;;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt -;declare_expection;ts,tc;m;m;m;m;o;;;;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt -;clean_workspace;ws;o ;;_;;;;;;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt -;start_dialog;ws;input;;input;input;input;;;;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt -;web_start;ws;;;;;;;;;wsbase;warn;{job.par.wsdir}/{log}/log_{job.start}.txt +_key;name;;;;;;;;;;;;; +table:programs;name;objtype;objname;time;env;app;variant;pardef;pfilesource;pfiletarget;dirname;basedir;loglevel;logpath +;test_executer;tp,ts,tc;m;m;m;m;o;;;;{objtype}dir;{objtype}base;info;{job.par.wsdir}/{log}/log_{job.start}.txt +;init_testsuite;ts;m;o;m;m;o;;envparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt +;execute_testsuite;ts;m;m;m;m;o;;tsparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt +;collect_testsuite;ts;m;m;m;m;o;;tsparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt +;finish_testsuite;ts;m;m;m;m;o;;tsparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt +;unzip_testsuite;ts;m;m;m;m;o;;;;;;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt +;init_testcase;tc;m;o;m;m;o;;tsparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt +;exec_testcase;tc;m;m;m;m;o;;tcparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt +;collect_testcase;tc;m;m;m;m;o;;tcparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt +;compare_testcase;tc;m;m;m;m;o;;tcparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt +;check_environment;env;;;m;;o;;;envparfile;envdir;envbase;info;{job.par.envdir}/{log}/log_{job.start}.txt +;check_specification;tp,ts,tc;o;;;;;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt +;check_configuration;ws;o;;;o;;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt +;make_workspace;ws;;;_;;;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt +;unit_tester;ws;o;;d;;;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt +;declare_expection;ts,tc;m;m;m;m;o;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt +;clean_workspace;ws;o ;;_;;;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt +;start_dialog;ws;input;;input;input;input;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt +;web_start;ws;;;;;;;;;wsdir;wsbase;warn;{job.par.wsdir}/{log}/log_{job.start}.txt diff --git a/test/test_03path.py b/test/test_03path.py index 9b06268..b2bc436 100644 --- a/test/test_03path.py +++ b/test/test_03path.py @@ -23,10 +23,10 @@ class MyTestCase(unittest.TestCase): def setTestPaths(self, job): # here you can overwrite your workspace-configuration in order to get stable unittests - job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_HOME] = "home/unittest" - job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA] = "home/unittest/tdata" - job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV] = "home/unittest/env" - job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV] = "home/unittest/archiv" + job.conf[B.SUBJECT_PATH][B.ATTR_PATH_HOME] = "home/unittest" + job.conf[B.SUBJECT_PATH][B.ATTR_PATH_TDATA] = "home/unittest/tdata" + job.conf[B.SUBJECT_PATH][B.ATTR_PATH_ENV] = "home/unittest/env" + job.conf[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV] = "home/unittest/archiv" pass def setPathConfig(self, pt): @@ -86,11 +86,11 @@ class MyTestCase(unittest.TestCase): self.setPathConfig(pt) # tests path = utils.path_tool.composePath(job, P.P_ENVBASE, None) - self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path) + self.assertIn(job.conf[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path) self.assertIn(getattr(job.par, B.PAR_ENV), path) cnttest += 2 path = utils.path_tool.composePath(job, P.P_TCLOG, None) - self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], path) + self.assertIn(job.conf[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], path) self.assertIn(getattr(job.par, B.PAR_TESTCASE), path) cnttest += 2 MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) @@ -110,7 +110,7 @@ class MyTestCase(unittest.TestCase): self.setPathConfig(pt) # tests path = utils.path_tool.composePattern(job, "{"+P.P_ENVBASE+"}", None) - self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path) + self.assertIn(job.conf[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path) self.assertIn(getattr(job.par, B.PAR_ENV), path) cnttest += 2 MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) diff --git a/test/test_08value.py b/test/test_08value.py index e69de29..191d74c 100644 --- a/test/test_08value.py +++ b/test/test_08value.py @@ -0,0 +1,69 @@ +import unittest +import os +import inspect +import tools.value_tool +import basic.program +import basic.constants as B +import test.constants +import test.testtools + +HOME_PATH = test.constants.HOME_PATH +DATA_PATH = test.constants.DATA_PATH +OS_SYSTEM = test.constants.OS_SYSTEM + +# here you can select single testfunction for developping the tests +TEST_FUNCTIONS = ["test_01key", "test_10pattern"] +TEST_FUNCTIONS = ["test_10pattern"] +verbose = True +job = None + + +class MyTestCase(unittest.TestCase): + mymsg = "--------------------------------------------------------------" + + def test_01key(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + res = tools.value_tool.get_key_value(job, "job.par." + B.PAR_ENV, None) + self.assertEqual(res, test.testtools.DEFAULT_ENV) + cnttest += 1 + for p in [B.ATTR_PATH_ARCHIV, B.ATTR_PATH_ENV]: + res = tools.value_tool.get_key_value(job, "job.conf." + p, None) + if verbose: print("assertIn "+p+": "+res+" -- "+HOME_PATH) + self.assertIn(HOME_PATH, res) + cnttest += 1 + res = tools.value_tool.get_key_value(job, "job.program", None) + self.assertIn("unit_tester", res) + res = tools.value_tool.get_key_value(job, "ctlg.programs.unit_tester.dirname", None) + self.assertIn("wsdir", res) + MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) + + def test_10pattern(self): + global mymsg + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + job = test.testtools.getJob() + res = tools.value_tool.compose_pattern(job, "wsdir", None) + self.assertEqual(res, os.path.join(B.HOME_PATH, "workspace")) + cnttest += 1 + setattr(job.par, "wsdir", res) + res = tools.value_tool.compose_string(job, "{job.par.wsdir}/{log}/{job.program}_{job.start}.txt", None) + regex = os.path.join(B.HOME_PATH, "workspace", "log", "unit_tester_\d{8}_\d{6}.txt") + self.assertRegex(res, regex) + cnttest += 1 + # "{job.par.wsdir}/{log}/{job.program}_{job.start}.txt" + MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) + + def test_zzz(self): + if verbose: print(MyTestCase.mymsg) + + +if __name__ == '__main__': + unittest.main() + job.stopJob() diff --git a/test/test_11message.py b/test/test_11message.py index 22b0824..4b34f3c 100644 --- a/test/test_11message.py +++ b/test/test_11message.py @@ -1,20 +1,18 @@ import unittest import os import inspect -import shutil import tools.path_tool import basic.program -from basic.componentHandling import ComponentManager import test.constants import basic.constants as B -import test.constants as T import basic.componentHandling import tools.file_tool import basic.message HOME_PATH = test.constants.HOME_PATH PYTHON_CMD = "python" -TEST_FUNCTIONS = ["test_00init", "test_05loginigArgs", "test_10set", "test_11log", "test_20close"] +TEST_FUNCTIONS = ["test_00init", "test_04logLevel", "test_05loginigArgs", "test_10set", "test_11log", "test_20close"] +#TEST_FUNCTIONS = ["test_00init", "test_04logLevel"] PROGRAM_NAME = "clean_workspace" NOT_TO_LOG = ["xx1xx", "xx4xx"] @@ -45,15 +43,43 @@ class MyTestCase(unittest.TestCase): tmsg = basic.message.TempMessage(job, tlogTime) print(str(tmsg.__dict__)) self.checkSimpleMessage(tmsg, "debug", tlogTime) + cnttest += 3 self.assertEqual(basic.message.LIMIT_DEBUG, getattr(tmsg, "level")) setattr(job, "m", tmsg) msg = basic.message.Message(job, "trace", tlogTime, None) setattr(job, "m", msg) print(str(msg.__dict__)) self.checkSimpleMessage(msg, "debug", tlogTime) + cnttest += 3 self.checkSimpleMessage(msg, "log", tlogTime) + cnttest += 3 self.assertEqual(basic.message.LIMIT_TRACE, getattr(msg, "level")) + cnttest += 3 msgObject = msg # + jobObject = job + MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) + + def test_04logLevel(self): + global mymsg + global msgObject + global jobObject + actfunction = str(inspect.currentframe().f_code.co_name) + cnttest = 0 + if actfunction not in TEST_FUNCTIONS: + return + res = msgObject.getLogLevel() + self.assertEqual(0, res) + res = msgObject.getLogLevel("msg_tool") + self.assertEqual(0, res) + setattr(jobObject.par, "tool", "job_tool") + res = msgObject.getLogLevel("msg_tool") + self.assertEqual(0, res) + setattr(jobObject.par, "tool", "msg_tool") + res = msgObject.getLogLevel("msg_tool") + self.assertEqual(2, res) + cnttest += 4 + MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) + def test_05loginigArgs(self): global mymsg @@ -73,6 +99,8 @@ class MyTestCase(unittest.TestCase): self.assertEqual(res["mlevel"], 12) self.assertEqual(res["mprio"], 0) self.assertEqual(res["mtext"], "ERROR: text") + cnttest += 9 + MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) def test_10set(self): global mymsg @@ -83,16 +111,30 @@ class MyTestCase(unittest.TestCase): print("test_set "+str(msgObject.__dict__)) msgObject.setMsg("yy1yy result-msg") self.assertEqual(basic.message.RC_MSG, msgObject.getFinalRc()) + self.assertEqual(msgObject.topmessage, "MSG: yy1yy result-msg") + self.assertEqual(True, msgObject.isRc(basic.message.RC_MSG)) + self.assertEqual(True, msgObject.isRc(basic.message.MTEXT_MSG)) + self.assertEqual(True, msgObject.isRc(basic.message.MTEXT_INFO)) + self.assertEqual(True, msgObject.isRc(basic.message.RC_WARN)) + self.assertEqual(True, msgObject.isRc(basic.message.MTEXT_WARN)) msgObject.setWarn("yy2yy warn-msg") self.assertEqual(basic.message.RC_WARN, msgObject.getFinalRc()) + self.assertEqual("WARN: yy2yy warn-msg", msgObject.topmessage) + self.assertEqual(False, msgObject.isRc(basic.message.RC_MSG)) msgObject.setError("yy3yy error-msg") self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc()) + self.assertEqual("ERROR: yy3yy error-msg", msgObject.topmessage) msgObject.setWarn("yy4yy warn-msg") self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc()) + self.assertEqual("ERROR: yy3yy error-msg", msgObject.topmessage) msgObject.setError("yy5yy error-msg") self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc()) + self.assertEqual("ERROR: yy3yy error-msg", msgObject.topmessage) msgObject.setFatal("yy6yy fatal-msg") self.assertEqual(basic.message.RC_FATAL, msgObject.getFinalRc()) + self.assertEqual("FATAL: yy6yy fatal-msg", msgObject.topmessage) + cnttest += 6 + MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) def test_11log(self): @@ -161,5 +203,8 @@ class MyTestCase(unittest.TestCase): self.assertIn(x, msg.__dict__) self.assertIn(logTime, getattr(msg, "debugpath")) + def test_zzz(self): + print(MyTestCase.mymsg) + if __name__ == '__main__': unittest.main() diff --git a/test/testtools.py b/test/testtools.py index 3dd6d1e..9bdbd8a 100644 --- a/test/testtools.py +++ b/test/testtools.py @@ -74,12 +74,12 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""): path = DEFAULT_ARCHIV_DIR + "/TC0001/" + tstamp elif gran == "ts": path = DEFAULT_ARCHIV_DIR + "/testlauf/TST001_" + tstamp - #job.conf.confs[B.SUBJECT_PATH]["components"] = T.COMP_PATH + #job.conf[B.SUBJECT_PATH]["components"] = T.COMP_PATH args = {"application": app, "environment": env, "modus": mode, gran+"time": tstamp, gran+"dir": path, "step": 2} # "usecase": "TST001", "tstime": "2022-03-17_17-28"} - job = basic.program.Job("unit", args) + job = basic.program.Job("unit_tester", "", args) return job diff --git a/tools/path_tool.py b/tools/path_tool.py index ca13464..03c46c9 100644 --- a/tools/path_tool.py +++ b/tools/path_tool.py @@ -51,9 +51,6 @@ def getBasisConfigPath(): def getActualJsonPath(job): username = getpass.getuser() path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG], username+"Job.json") - print("------ path "+path) - #if os.path.exists(path): - # return path return path @@ -155,7 +152,6 @@ def extractPath(job, pathtyp, path): :param path: the concrete path - it should be the directory in the parameter of the job :return: """ - #job = basic.program.Job.getInstance() patterlist = extractPattern(job, pathtyp) verbose = False work = path @@ -166,7 +162,6 @@ def extractPath(job, pathtyp, path): delim = p[0] key = p[1] val = p[2] - nextdelim = "" if i >= len(patterlist) - 1: nextdelim = "" else: diff --git a/tools/value_tool.py b/tools/value_tool.py index 851a8d4..1c0fa05 100644 --- a/tools/value_tool.py +++ b/tools/value_tool.py @@ -5,16 +5,13 @@ # Source : gitea.ucarmesin.de # --------------------------------------------------------------------------------------------------------- """ In diesem Modul werden alle Funktionen zusammengefasst zur Generierung und Ermittlung von pathsn """ -import os.path -import sys -import basic.program import tools.config_tool import re import basic.constants as B import tools.path_const as P import tools.date_tool import objects.catalog -import getpass + TOOL_NAME = "value_tool" DOM_JOB = "job" @@ -51,7 +48,6 @@ def get_key_value(job, key, comp=None): :param comp: :return: """ - #job = basic.program.Job.getInstance() try: verify = job.getDebugLevel(TOOL_NAME)-4 except: @@ -128,7 +124,7 @@ def compose_string(job, pattern, comp): verify = job.getDebugLevel(TOOL_NAME) except: verify = False - verbose = not False + verbose = False max=5 l = re.findall('\{.*?\}', pattern) #job.debug(verify, l)