Browse Source

refactor prg-msg

refactor
Ulrich 2 years ago
parent
commit
db40fd5fa6
  1. 20
      basic/constants.py
  2. 72
      basic/message.py
  3. 41
      basic/program.py
  4. 42
      catalog/programs.csv
  5. 14
      test/test_03path.py
  6. 69
      test/test_08value.py
  7. 53
      test/test_11message.py
  8. 4
      test/testtools.py
  9. 5
      tools/path_tool.py
  10. 8
      tools/value_tool.py

20
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 * test-specification with testdata - stored in external testdata-folder
* the internal datastructure * the internal datastructure
""" """
import os
# ------------------------------------------------------------- # -------------------------------------------------------------
# values and keywords # values and keywords
@ -30,6 +30,7 @@ SVAL_NULL = "null"
# ------------------------------------------------------------- # -------------------------------------------------------------
# parameter with arguments # parameter with arguments
PAR_PROGRAM = 'program'
PAR_PROJ = 'project' PAR_PROJ = 'project'
""" definition of the project which will be tested """ """ definition of the project which will be tested """
PAR_APP = 'application' PAR_APP = 'application'
@ -40,6 +41,8 @@ PAR_VAR = 'variant'
""" definition of a variant dataflow especially the channel """ """ definition of a variant dataflow especially the channel """
PAR_REL = 'release' PAR_REL = 'release'
""" definition of the release of the application which will be tested """ """ definition of the release of the application which will be tested """
PAR_BASEDIR = 'basedir'
PAR_DIRNAME = 'dirname'
PAR_TSDIR = 'tsdir' PAR_TSDIR = 'tsdir'
""" definition of the directory of the testsuite for summaries of the testcases """ """ definition of the directory of the testsuite for summaries of the testcases """
PAR_TCDIR = 'tcdir' PAR_TCDIR = 'tcdir'
@ -58,6 +61,7 @@ PAR_FCT = 'function'
PAR_TOOL = 'tool' PAR_TOOL = 'tool'
PAR_STEP = 'step' PAR_STEP = 'step'
PAR_DESCRIPT = 'desription' PAR_DESCRIPT = 'desription'
PAR_STRING = 'parstring'
""" """ """ """
PAR_TESTCASE = "testcase" PAR_TESTCASE = "testcase"
PAR_TESTCASES = "testcases" 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_IMPLEMENT = "method is not implemented"
EXCEPT_NOT_INITIALIZED = "class is not initialized" 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

72
basic/message.py

@ -32,7 +32,7 @@ MTEXT_MSG = "msg"
MTEXT_INFO = "info" MTEXT_INFO = "info"
MTEXT_DEBUG = "debug" MTEXT_DEBUG = "debug"
MTEXT_TRACE = "trace" 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_FATAL = 2
LIMIT_ERROR = 4 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 "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 "trace": "0", # wird nur in debug ausgegeben, wenn log-level hoechstens auf eingestelltem job-level steht
""" """
def __init__(self, job, level, logTime, componente): def __init__(self, job, level, logTime, compName=None):
# (self, componente, out, level): # (self, compName, out, level):
self.job = job self.job = job
self.componente = componente # dezantrales Logsystem self.compName = compName # dezentrales Logsystem
verify = LIMIT_DEBUG verify = LIMIT_DEBUG
self.rc = RC_INFO self.rc = RC_INFO
if isinstance(level, str): if isinstance(level, str):
@ -144,18 +144,16 @@ class Message:
self.level = LIMIT_DEBUG self.level = LIMIT_DEBUG
else: else:
self.level = level self.level = level
self.openDebug(job, logTime, componente) self.openDebug(job, logTime, compName)
self.openLog(job, logTime, componente) self.openLog(job, logTime, compName)
self.topmessage = "" 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] path = job.conf[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG]
if not os.path.exists(path): if not os.path.exists(path):
os.mkdir(path) os.mkdir(path)
logTime = logTime[0:11] + "0000" logTime = logTime[0:11] + "0000"
if componente is None: if compName is None:
if hasattr(job.m, "debugpath"): if hasattr(job.m, "debugpath"):
self.debugpath = job.m.debugpath self.debugpath = job.m.debugpath
self.debugfile = job.m.debugfile self.debugfile = job.m.debugfile
@ -163,13 +161,13 @@ class Message:
else: else:
self.debugpath = os.path.join(path, "debug_"+logTime+".txt") self.debugpath = os.path.join(path, "debug_"+logTime+".txt")
else: 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): if os.path.exists(self.debugpath):
self.debugfile = open(self.debugpath, "a") self.debugfile = open(self.debugpath, "a")
else: else:
self.debugfile = open(self.debugpath, "w") self.debugfile = open(self.debugpath, "w")
def openLog(self, job, logTime, componente): def openLog(self, job, logTime, compName):
if not hasattr(job, "par"): if not hasattr(job, "par"):
return return
pathPattern = job.programDef["logpath"] pathPattern = job.programDef["logpath"]
@ -177,7 +175,7 @@ class Message:
parent = os.path.dirname(path) parent = os.path.dirname(path)
if not os.path.exists(parent): if not os.path.exists(parent):
os.makedirs(parent) os.makedirs(parent)
if componente is None: if compName is None:
self.logpath = path self.logpath = path
self.logfile = open(path, "w") self.logfile = open(path, "w")
else: else:
@ -207,23 +205,43 @@ class Message:
self.logfile.close() self.logfile.close()
self.debugfile.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): def setRc(self, rc, text):
job = self.job #basic.program.Job.getInstance() if (int(rc) > self.rc) or (self.topmessage == ""):
if (int(rc) > self.rc):
self.rc = rc self.rc = rc
# TODO quickfix i = rc * -1 + 3
self.topmessage = ": " + text if i < 0: return
elif (int(rc) == self.rc): self.topmessage = LIST_MTEXT[i].upper() + ": " + text
self.topmessage = ": " + text
def isRc(self, returnCode):
def isRc(self, rc): """
rcId = 0 # int(int(self.CONST_ERRTYP[rc]) / 4 - RC_OFFSET) prueft, ob der gesetzte ReturnCode mit dem angefragten ReturnCode vereinbar ist
print("< < < isRc " + str(self.rc) + " <=? " + str(rcId)) Beispiel: gesetzt WARN, angefragt ERROR ist OK=True, anders herum: KO=False
if self.rc <= int(rcId): :param returnCode:
print("return True") :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 return True
else: else:
print("return False")
return False return False
def getFinalRc(self): def getFinalRc(self):
@ -379,7 +397,7 @@ class Message:
""" eigentliche Schreibroutine: hierin wird debug-Level beruecksichtgigt""" """ eigentliche Schreibroutine: hierin wird debug-Level beruecksichtgigt"""
if (args["mlevel"] + args["mprio"] > int(self.level)): if (args["mlevel"] + args["mprio"] > int(self.level)):
return return
elif (self.componente is None): # and self.logfile.closed == False: elif (self.compName is None): # and self.logfile.closed == False:
try: try:
self.logfile.write(args["mtext"] + "\n") self.logfile.write(args["mtext"] + "\n")
except: except:

41
basic/program.py

@ -30,6 +30,8 @@ import tools.job_tool
LIMIT_INFO = 16 #basic.message.LIMIT_INFO LIMIT_INFO = 16 #basic.message.LIMIT_INFO
LIMIT_DEBUG = 12 #basic.message.LIMIT_DEBUG LIMIT_DEBUG = 12 #basic.message.LIMIT_DEBUG
TOOL_NAME = "job_tool"
CTLG_NAME = "programs" CTLG_NAME = "programs"
CTLG_PARDEF = "pardef" CTLG_PARDEF = "pardef"
CTLG_PARSOURCE = "pfilesource" CTLG_PARSOURCE = "pfilesource"
@ -102,12 +104,9 @@ def createJob(pprg="", pgran="", papp="", penv="", ptstamp="", pmode=""):
path = T.DATA_PATH + "/workspace/" path = T.DATA_PATH + "/workspace/"
job = basic.program.Job(prgname) job = basic.program.Job(prgname)
# job.conf[B.SUBJECT_PATH]["components"] = T.COMP_PATH
args = {"application": app, "environment": env, "modus": mode, gran + "time": tstamp, args = {"application": app, "environment": env, "modus": mode, gran + "time": tstamp,
gran + "dir": path, gran + "dir": path,
"step": 1} "step": 1}
print(str(args))
# "usecase": "TST001", "tstime": "2022-03-17_17-28"}
job.par.setParameterArgs(job, args) job.par.setParameterArgs(job, args)
return job return job
@ -190,7 +189,6 @@ class Job:
# - job.conf with basis config # - job.conf with basis config
# - job.par with parameter-args or cli-args # - job.par with parameter-args or cli-args
# - job.msg # - job.msg
print("################# init Job ## " + program + " #################")
# logtime muss unique sein denn logDateien und Verzeichnisse muessen eindeutig sein # logtime muss unique sein denn logDateien und Verzeichnisse muessen eindeutig sein
logTime = tools.date_tool.getActdate(tools.date_tool.F_LOG) logTime = tools.date_tool.getActdate(tools.date_tool.F_LOG)
while logTime <= Job.__logtime: while logTime <= Job.__logtime:
@ -212,8 +210,6 @@ class Job:
self.programDef = catalog.getValue(self, CTLG_NAME, program, "") self.programDef = catalog.getValue(self, CTLG_NAME, program, "")
try: try:
path = tools.config_tool.getConfigPath(self, P.KEY_BASIC, B.BASIS_FILE) 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) self.conf = self.getConfiguration(path)
except: except:
print("FATAL: config-file could not be loaded") print("FATAL: config-file could not be loaded")
@ -257,19 +253,6 @@ class Job:
conf[k] = v conf[k] = v
return conf 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): def setProgram(self, program):
self.program = program self.program = program
basedir = self.programDef[CTLG_BASEDIR] basedir = self.programDef[CTLG_BASEDIR]
@ -284,16 +267,13 @@ class Job:
if not hasattr(self.par, self.programDef[B.PAR_DIRNAME]): if not hasattr(self.par, self.programDef[B.PAR_DIRNAME]):
setattr(self.par, self.programDef[B.PAR_DIRNAME], setattr(self.par, self.programDef[B.PAR_DIRNAME],
tools.path_tool.compose_path(self, "{"+basedir+"}", None)) tools.path_tool.compose_path(self, "{"+basedir+"}", None))
print(parstring)
self.par.setParameterLoaded(self) self.par.setParameterLoaded(self)
def startJob(self): def startJob(self):
self.start = datetime.now() self.start = datetime.now()
print("prog-68 " + str(self.par.basedir))
logTime = self.start.strftime("%Y%m%d_%H%M%S") logTime = self.start.strftime("%Y%m%d_%H%M%S")
self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None) self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None)
print("prog-68 " + str(self.m.rc))
tools.job_tool.startJobProcesses(self) tools.job_tool.startJobProcesses(self)
self.par.setParameterLoaded(self) self.par.setParameterLoaded(self)
self.m.logInfo("# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ") 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: if len(str(self.programDef[CTLG_PARSOURCE])) < 2:
return None return None
parpath = tools.path_tool.compose_path(self, self.programDef[CTLG_PARSOURCE], None) parpath = tools.path_tool.compose_path(self, self.programDef[CTLG_PARSOURCE], None)
print("parpath "+parpath)
if not os.path.join(parpath): if not os.path.join(parpath):
return None return None
print("parpath "+parpath)
doc = tools.file_tool.readFileDict(self, parpath, None) doc = tools.file_tool.readFileDict(self, parpath, None)
for k in doc.keys(): for k in doc.keys():
output[k] = copy.deepcopy(doc[k]) output[k] = copy.deepcopy(doc[k])
@ -389,7 +367,6 @@ class Job:
:return: :return:
""" """
if hasattr(self.par, parameter): if hasattr(self.par, parameter):
print (parameter + " in Parameter")
if getattr(self.par, parameter).find(elem) >= 0: if getattr(self.par, parameter).find(elem) >= 0:
return True return True
return False return False
@ -433,11 +410,8 @@ class Job:
def getTraceLevel(self, elem): def getTraceLevel(self, elem):
return self.getMessageLevel("trace", elem) return self.getMessageLevel("trace", elem)
def debug(self, prio, text): def debug(self, prio, text):
#print("job.debug "+str(prio)+" "+text)
if hasattr(self, "m"): if hasattr(self, "m"):
self.m.debug(prio, text) self.m.debug(prio, text)
else:
print(text)
def getConfiguration(job, path): def getConfiguration(job, path):
conf = {} conf = {}
@ -466,9 +440,7 @@ class Parameter:
+ dirname of work-folder either from dir-parameter or composed from single parameter + dirname of work-folder either from dir-parameter or composed from single parameter
comparison with a parameter-file from the work-folder comparison with a parameter-file from the work-folder
""" """
print ("class Parameter")
def __init__ (self, job, args=None): def __init__ (self, job, args=None):
print ("# init Parameter for " + job.program)
self.program = job.program self.program = job.program
if args is not None and isinstance(args, dict): if args is not None and isinstance(args, dict):
self.setParameterArgs(job, args) self.setParameterArgs(job, args)
@ -476,7 +448,6 @@ class Parameter:
self.setParameter(job) self.setParameter(job)
self.basedir = job.programDef[B.PAR_BASEDIR] self.basedir = job.programDef[B.PAR_BASEDIR]
job.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 job.par = self
# Parameter aus Verzeichnis extraieren bzw. Verzeichnis aus Parameter erstellen # Parameter aus Verzeichnis extraieren bzw. Verzeichnis aus Parameter erstellen
if not hasattr(self, job.programDef[B.PAR_DIRNAME]): if not hasattr(self, job.programDef[B.PAR_DIRNAME]):
@ -494,7 +465,6 @@ class Parameter:
print (f"Parameter initialisiert {self.program}") print (f"Parameter initialisiert {self.program}")
pardef = self.programDef[CTLG_PARDEF] pardef = self.programDef[CTLG_PARDEF]
for p in pardef.split(","): for p in pardef.split(","):
print(p)
if len(p) > 1 and not hasattr(self, p): if len(p) > 1 and not hasattr(self, p):
job.m.setFatal("Parameter " + p + " is not set!") job.m.setFatal("Parameter " + p + " is not set!")
@ -517,8 +487,6 @@ class Parameter:
12. funktion -- schraenkt Verarbeitung auf parametriserte Funktionen ein 12. funktion -- schraenkt Verarbeitung auf parametriserte Funktionen ein
13. tool -- schraenkt Protokollierung/Verarbeitung auf parametriserte Tools ein 13. tool -- schraenkt Protokollierung/Verarbeitung auf parametriserte Tools ein
""" """
# args = str(sys.argv)
# print ("Job-Programm %s : " % args)
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-a', '--'+B.SUBJECT_APPS, required=True, action='store') parser.add_argument('-a', '--'+B.SUBJECT_APPS, required=True, action='store')
parser.add_argument('-e', '--'+B.PAR_ENV, 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): def setParameterArgs(self, job, args):
print("setParArgs " + str(type(args)))
self.parstring = "python " + self.program self.parstring = "python " + self.program
if "dict" in str(type(args)): if "dict" in str(type(args)):
for k in args: for k in args:
@ -562,8 +529,6 @@ class Parameter:
if getattr(args, k) is not None: if getattr(args, k) is not None:
self.setJobAttr(k , getattr(args, k)) self.setJobAttr(k , getattr(args, k))
dirpath = self.getDirParameter() 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 \ if hasattr(self, "application") and B.SUBJECT_APPS in job.conf \
and getattr(self, "application") in job.conf[B.SUBJECT_APPS]: and getattr(self, "application") in job.conf[B.SUBJECT_APPS]:
if B.ATTR_APPS_PROJECT in job.conf[B.SUBJECT_APPS][self.application]: if B.ATTR_APPS_PROJECT in job.conf[B.SUBJECT_APPS][self.application]:
@ -573,10 +538,8 @@ class Parameter:
def setParameterLoaded(self, job): def setParameterLoaded(self, job):
#job = Job.getInstance() #job = Job.getInstance()
print("setParLoaded "+job.program)
readedPar = job.loadParameter() readedPar = job.loadParameter()
if readedPar is not None: if readedPar is not None:
print(str(readedPar))
for k in readedPar["par"].keys(): for k in readedPar["par"].keys():
if not hasattr(self, k): if not hasattr(self, k):
self.setJobAttr(k, readedPar["par"][k]) self.setJobAttr(k, readedPar["par"][k])

42
catalog/programs.csv

@ -1,21 +1,21 @@
_key;name;;;;;;;;;;;; _key;name;;;;;;;;;;;;;
table:programs;name;objtype;objname;time;env;app;variant;pardef;pfilesource;pfiletarget;basedir;loglevel;logpath 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}base;info;{job.par.wsdir}/{log}/log_{job.start}.txt ;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;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{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;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;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;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 ;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 ;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;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;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;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;envbase;info;{job.par.envdir}/{log}/log_{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;;;;;;;;wsbase;info;{job.par.wsdir}/{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;;;;;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;;;_;;;;;;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;;;;;;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;;;;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 ;;_;;;;;;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;;;;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;;;;;;;;;wsbase;warn;{job.par.wsdir}/{log}/log_{job.start}.txt ;web_start;ws;;;;;;;;;wsdir;wsbase;warn;{job.par.wsdir}/{log}/log_{job.start}.txt

1 _key name
2 table:programs name objtype objname time env app variant pardef pfilesource pfiletarget basedir dirname loglevel basedir logpath loglevel logpath
3 test_executer tp,ts,tc m m m m o {objtype}base {objtype}dir info {objtype}base {job.par.wsdir}/{log}/log_{job.start}.txt info {job.par.wsdir}/{log}/log_{job.start}.txt
4 init_testsuite ts m o m m o envparfile tsparfile tsbase tsdir info tsbase {job.par.tsdir}/{log}/{job.program}_{job.start}.txt info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
5 execute_testsuite ts m m m m o tsparfile tsparfile tsbase tsdir info tsbase {job.par.tsdir}/{log}/{job.program}_{job.start}.txt info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
6 collect_testsuite ts m m m m o tsparfile tsparfile tsbase tsdir info tsbase {job.par.tsdir}/{log}/{job.program}_{job.start}.txt info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
7 finish_testsuite ts m m m m o tsparfile tsparfile tsbase tsdir info tsbase {job.par.tsdir}/{log}/{job.program}_{job.start}.txt info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
8 unzip_testsuite ts m m m m o info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
9 init_testcase tc m o m m o tsparfile tcparfile tcbase tcdir info tcbase {job.par.tcdir}/{log}/{job.program}_{job.start}.txt info {job.par.tcdir}/{log}/{job.program}_{job.start}.txt
10 exec_testcase tc m m m m o tcparfile tcparfile tcbase tcdir info tcbase {job.par.tcdir}/{log}/{job.program}_{job.start}.txt info {job.par.tcdir}/{log}/{job.program}_{job.start}.txt
11 collect_testcase tc m m m m o tcparfile tcparfile tcbase tcdir info tcbase {job.par.tcdir}/{log}/{job.program}_{job.start}.txt info {job.par.tcdir}/{log}/{job.program}_{job.start}.txt
12 compare_testcase tc m m m m o tcparfile tcparfile tcbase tcdir info tcbase {job.par.tcdir}/{log}/{job.program}_{job.start}.txt info {job.par.tcdir}/{log}/{job.program}_{job.start}.txt
13 check_environment env m o envparfile envbase envdir info envbase {job.par.envdir}/{log}/log_{job.start}.txt info {job.par.envdir}/{log}/log_{job.start}.txt
14 check_specification tp,ts,tc o wsbase wsdir info wsbase {job.par.wsdir}/{log}/log_{job.start}.txt info {job.par.wsdir}/{log}/log_{job.start}.txt
15 check_configuration ws o o wsbase wsdir info wsbase {job.par.wsdir}/{log}/log_{job.start}.txt info {job.par.wsdir}/{log}/log_{job.start}.txt
16 make_workspace ws _ wsbase wsdir info wsbase {job.par.wsdir}/{log}/log_{job.start}.txt info {job.par.wsdir}/{log}/log_{job.start}.txt
17 unit_tester ws o d wsbase wsdir info wsbase {job.par.wsdir}/{log}/log_{job.start}.txt info {job.par.wsdir}/{log}/log_{job.start}.txt
18 declare_expection ts,tc m m m m o wsbase wsdir info wsbase {job.par.wsdir}/{log}/log_{job.start}.txt info {job.par.wsdir}/{log}/log_{job.start}.txt
19 clean_workspace ws o _ wsbase wsdir info wsbase {job.par.wsdir}/{log}/log_{job.start}.txt info {job.par.wsdir}/{log}/log_{job.start}.txt
20 start_dialog ws input input input input wsbase wsdir info wsbase {job.par.wsdir}/{log}/log_{job.start}.txt info {job.par.wsdir}/{log}/log_{job.start}.txt
21 web_start ws wsbase wsdir warn wsbase {job.par.wsdir}/{log}/log_{job.start}.txt warn {job.par.wsdir}/{log}/log_{job.start}.txt

14
test/test_03path.py

@ -23,10 +23,10 @@ class MyTestCase(unittest.TestCase):
def setTestPaths(self, job): def setTestPaths(self, job):
# here you can overwrite your workspace-configuration in order to get stable unittests # 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[B.SUBJECT_PATH][B.ATTR_PATH_HOME] = "home/unittest"
job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA] = "home/unittest/tdata" job.conf[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[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_ARCHIV] = "home/unittest/archiv"
pass pass
def setPathConfig(self, pt): def setPathConfig(self, pt):
@ -86,11 +86,11 @@ class MyTestCase(unittest.TestCase):
self.setPathConfig(pt) self.setPathConfig(pt)
# tests # tests
path = utils.path_tool.composePath(job, P.P_ENVBASE, None) 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) self.assertIn(getattr(job.par, B.PAR_ENV), path)
cnttest += 2 cnttest += 2
path = utils.path_tool.composePath(job, P.P_TCLOG, None) 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) self.assertIn(getattr(job.par, B.PAR_TESTCASE), path)
cnttest += 2 cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -110,7 +110,7 @@ class MyTestCase(unittest.TestCase):
self.setPathConfig(pt) self.setPathConfig(pt)
# tests # tests
path = utils.path_tool.composePattern(job, "{"+P.P_ENVBASE+"}", None) 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) self.assertIn(getattr(job.par, B.PAR_ENV), path)
cnttest += 2 cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

69
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()

53
test/test_11message.py

@ -1,20 +1,18 @@
import unittest import unittest
import os import os
import inspect import inspect
import shutil
import tools.path_tool import tools.path_tool
import basic.program import basic.program
from basic.componentHandling import ComponentManager
import test.constants import test.constants
import basic.constants as B import basic.constants as B
import test.constants as T
import basic.componentHandling import basic.componentHandling
import tools.file_tool import tools.file_tool
import basic.message import basic.message
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" 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" PROGRAM_NAME = "clean_workspace"
NOT_TO_LOG = ["xx1xx", "xx4xx"] NOT_TO_LOG = ["xx1xx", "xx4xx"]
@ -45,15 +43,43 @@ class MyTestCase(unittest.TestCase):
tmsg = basic.message.TempMessage(job, tlogTime) tmsg = basic.message.TempMessage(job, tlogTime)
print(str(tmsg.__dict__)) print(str(tmsg.__dict__))
self.checkSimpleMessage(tmsg, "debug", tlogTime) self.checkSimpleMessage(tmsg, "debug", tlogTime)
cnttest += 3
self.assertEqual(basic.message.LIMIT_DEBUG, getattr(tmsg, "level")) self.assertEqual(basic.message.LIMIT_DEBUG, getattr(tmsg, "level"))
setattr(job, "m", tmsg) setattr(job, "m", tmsg)
msg = basic.message.Message(job, "trace", tlogTime, None) msg = basic.message.Message(job, "trace", tlogTime, None)
setattr(job, "m", msg) setattr(job, "m", msg)
print(str(msg.__dict__)) print(str(msg.__dict__))
self.checkSimpleMessage(msg, "debug", tlogTime) self.checkSimpleMessage(msg, "debug", tlogTime)
cnttest += 3
self.checkSimpleMessage(msg, "log", tlogTime) self.checkSimpleMessage(msg, "log", tlogTime)
cnttest += 3
self.assertEqual(basic.message.LIMIT_TRACE, getattr(msg, "level")) self.assertEqual(basic.message.LIMIT_TRACE, getattr(msg, "level"))
cnttest += 3
msgObject = msg # 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): def test_05loginigArgs(self):
global mymsg global mymsg
@ -73,6 +99,8 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(res["mlevel"], 12) self.assertEqual(res["mlevel"], 12)
self.assertEqual(res["mprio"], 0) self.assertEqual(res["mprio"], 0)
self.assertEqual(res["mtext"], "ERROR: text") self.assertEqual(res["mtext"], "ERROR: text")
cnttest += 9
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_10set(self): def test_10set(self):
global mymsg global mymsg
@ -83,16 +111,30 @@ class MyTestCase(unittest.TestCase):
print("test_set "+str(msgObject.__dict__)) print("test_set "+str(msgObject.__dict__))
msgObject.setMsg("yy1yy result-msg") msgObject.setMsg("yy1yy result-msg")
self.assertEqual(basic.message.RC_MSG, msgObject.getFinalRc()) 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") msgObject.setWarn("yy2yy warn-msg")
self.assertEqual(basic.message.RC_WARN, msgObject.getFinalRc()) 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") msgObject.setError("yy3yy error-msg")
self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc()) self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc())
self.assertEqual("ERROR: yy3yy error-msg", msgObject.topmessage)
msgObject.setWarn("yy4yy warn-msg") msgObject.setWarn("yy4yy warn-msg")
self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc()) self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc())
self.assertEqual("ERROR: yy3yy error-msg", msgObject.topmessage)
msgObject.setError("yy5yy error-msg") msgObject.setError("yy5yy error-msg")
self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc()) self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc())
self.assertEqual("ERROR: yy3yy error-msg", msgObject.topmessage)
msgObject.setFatal("yy6yy fatal-msg") msgObject.setFatal("yy6yy fatal-msg")
self.assertEqual(basic.message.RC_FATAL, msgObject.getFinalRc()) 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): def test_11log(self):
@ -161,5 +203,8 @@ class MyTestCase(unittest.TestCase):
self.assertIn(x, msg.__dict__) self.assertIn(x, msg.__dict__)
self.assertIn(logTime, getattr(msg, "debugpath")) self.assertIn(logTime, getattr(msg, "debugpath"))
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

4
test/testtools.py

@ -74,12 +74,12 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
path = DEFAULT_ARCHIV_DIR + "/TC0001/" + tstamp path = DEFAULT_ARCHIV_DIR + "/TC0001/" + tstamp
elif gran == "ts": elif gran == "ts":
path = DEFAULT_ARCHIV_DIR + "/testlauf/TST001_" + tstamp 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, args = {"application": app, "environment": env, "modus": mode, gran+"time": tstamp,
gran+"dir": path, gran+"dir": path,
"step": 2} "step": 2}
# "usecase": "TST001", "tstime": "2022-03-17_17-28"} # "usecase": "TST001", "tstime": "2022-03-17_17-28"}
job = basic.program.Job("unit", args) job = basic.program.Job("unit_tester", "", args)
return job return job

5
tools/path_tool.py

@ -51,9 +51,6 @@ def getBasisConfigPath():
def getActualJsonPath(job): def getActualJsonPath(job):
username = getpass.getuser() username = getpass.getuser()
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG], username+"Job.json") 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 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 :param path: the concrete path - it should be the directory in the parameter of the job
:return: :return:
""" """
#job = basic.program.Job.getInstance()
patterlist = extractPattern(job, pathtyp) patterlist = extractPattern(job, pathtyp)
verbose = False verbose = False
work = path work = path
@ -166,7 +162,6 @@ def extractPath(job, pathtyp, path):
delim = p[0] delim = p[0]
key = p[1] key = p[1]
val = p[2] val = p[2]
nextdelim = ""
if i >= len(patterlist) - 1: if i >= len(patterlist) - 1:
nextdelim = "" nextdelim = ""
else: else:

8
tools/value_tool.py

@ -5,16 +5,13 @@
# Source : gitea.ucarmesin.de # Source : gitea.ucarmesin.de
# --------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------
""" In diesem Modul werden alle Funktionen zusammengefasst zur Generierung und Ermittlung von pathsn """ """ 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 tools.config_tool
import re import re
import basic.constants as B import basic.constants as B
import tools.path_const as P import tools.path_const as P
import tools.date_tool import tools.date_tool
import objects.catalog import objects.catalog
import getpass
TOOL_NAME = "value_tool" TOOL_NAME = "value_tool"
DOM_JOB = "job" DOM_JOB = "job"
@ -51,7 +48,6 @@ def get_key_value(job, key, comp=None):
:param comp: :param comp:
:return: :return:
""" """
#job = basic.program.Job.getInstance()
try: try:
verify = job.getDebugLevel(TOOL_NAME)-4 verify = job.getDebugLevel(TOOL_NAME)-4
except: except:
@ -128,7 +124,7 @@ def compose_string(job, pattern, comp):
verify = job.getDebugLevel(TOOL_NAME) verify = job.getDebugLevel(TOOL_NAME)
except: except:
verify = False verify = False
verbose = not False verbose = False
max=5 max=5
l = re.findall('\{.*?\}', pattern) l = re.findall('\{.*?\}', pattern)
#job.debug(verify, l) #job.debug(verify, l)

Loading…
Cancel
Save