Browse Source

example unittest

master
Ulrich Carmesin 2 years ago
parent
commit
217d0e0c09
  1. 59
      test/testtools.py
  2. 39
      utils/env_tool.py
  3. 70
      utils/path_const.py
  4. 112
      utils/path_tool.py

59
test/testtools.py

@ -0,0 +1,59 @@
import basic.program
import basic.constants as B
import components.component
DEFAULT_GRAN = "tc"
DEFAULT_APP = "TEST"
DEFAULT_ENV = "ENV01"
DEFAULT_DIR = "/home/ulrich/6_Projekte/Programme/datest/test/conf/lauf"
DEFAULT_TIME = "2022-03-19_12-09-09"
DEFAULT_MODE = "unit"
gran = ""
app = ""
env = ""
tstamp = ""
mode = ""
path = ""
def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
job = basic.program.Job.popInstance()
if not job is None:
job.stopJob()
if len(pgran) < 1:
gran = DEFAULT_GRAN
else:
gran = pgran
if len(papp) < 1:
app = DEFAULT_APP
else:
app = papp
if len(penv) < 1:
env = DEFAULT_ENV
else:
env = penv
if len(ptstamp) < 1:
tstamp = DEFAULT_TIME
else:
tstamp = ptstamp
if len(pmode) < 1:
mode = DEFAULT_MODE
else:
mode = pmode
if gran == "tc":
path = DEFAULT_DIR+"/TC0001/"+tstamp
elif gran == "ts":
path = DEFAULT_DIR + "/testlauf/TST001_" + tstamp
job = basic.program.Job("unit")
args = {"application": app, "environment": env, "modus": mode, gran+"time": tstamp,
gran+"dir": path,
"step": 2}
# "usecase": "TST001", "tstime": "2022-03-17_17-28"}
job.par.setParameterArgs(args)
return job
def getComp():
comp = components.component.Component()
comp.conf = {}
comp.name = "testcomp"
pass

39
utils/env_tool.py

@ -0,0 +1,39 @@
import utils.config_tool
import utils.file_tool
import basic.program
def importEnvProperty():
job = basic.program.Job.getInstance()
path = utils.config_tool.getConfig("tool", "env")
props = utils.file_tool.readFileDict(path, job.m)
job.conf.confs["env"] = props["prop"]
def exportEnvProperty():
job = basic.program.Job.getInstance()
props = {}
if not hasattr(job, "conf"): return
if not hasattr(job.conf, "confs"): return
if not "env" in job.confconfs: return
props["prop"] = job.conf.confs["env"]
path = utils.config_tool.getConfig("tool", "env")
utils.file_tool.writeFileDict(job.m, path, props)
def setEnvProp(props):
job = basic.program.Job.getInstance()
path = utils.config_tool.getConfig("tool", "env")
utils.file_tool.writeFileDict(job.m, path, props)
def getEnvProperty(propname):
job = basic.program.Job.getInstance()
if "env" not in job.conf.confs:
importEnvProperty()
prop = job.conf.confs[propname]
if (prop["type"] == "succ"):
val = prop["value"]
val += 1
prop["value"] = val
return val

70
utils/path_const.py

@ -0,0 +1,70 @@
import basic.constants as B
# -------------------------------------------------------------
# values and keywords
KEY_PRECOND = "precond"
KEY_POSTCOND = "postcond"
KEY_RESULT = "result"
KEY_ORIGIN = "origin"
KEY_PARTS = "parts"
KEY_SUMFILE = "sumfile"
KEY_BACKUP = "backup"
KEY_REFFILE = "reffile"
KEY_TESTCASE = "tc"
KEY_TESTSUITE = "ts"
KEY_DEBUGNAME = "debugname"
KEY_LOGNAME = "logname"
# -------------------------------------------------------------
# parameter with arguments
PAR_APP = "job.par." + B.PAR_APP
PAR_ENV = "job.par." + B.PAR_ENV
PAR_REL = "job.par." + B.PAR_REL
PAR_TSDIR = "job.par." + B.PAR_TSDIR
PAR_TCDIR = "job.par." + B.PAR_TCDIR
PAR_XPDIR = "job.par." + B.PAR_XPDIR
PAR_TDTYP = "job.par." + B.PAR_TDTYP
PAR_TDSRC = "job.par." + B.PAR_TDSRC
PAR_TDNAME = "job.par." + B.PAR_TDNAME
PAR_LOG = "job.par." + B.PAR_LOG
PAR_MODUS = "job.par." + B.PAR_MODUS
PAR_COMP = "job.par." + B.PAR_COMP
PAR_FCT = "job.par." + B.PAR_FCT
PAR_TOOL = "job.par." + B.PAR_TOOL
PAR_STEP = "job.par." + B.PAR_STEP
PAR_DESCRIPT = "job.par." + B.PAR_DESCRIPT
PAR_TESTCASE = "job.par." + B.PAR_TESTCASE
PAR_TESTCASES = "job.par." + B.PAR_TESTCASES
PAR_TESTSUITE = "job.par." + B.PAR_TESTSUITE
PAR_TCTIME = "job.par." + B.PAR_TCTIME
PAR_TSTIME = "job.par." + B.PAR_TSTIME
PAR_TESTINSTANCES = "job.par." + B.PAR_TESTINSTANCES
# -------------------------------------------------------------
# attributes
# -------------------------------------------------------------
# structure - nodes
P_DEBUGS = "debugs"
P_ENVBASE = "envbase"
P_ENVLOG = "envlog"
P_ENVPARFILE = "envparfile"
P_TCBASE = "tcbase"
P_TCLOG = "tclog"
P_TCRESULT = "tcresult"
P_TCPARFILE = "tcparfile"
P_TCDIFF = "tcdiff"
P_TCPREDIFF = "tcprediff"
P_TCRUNDIFF = "tcrundiff"
P_TCPRECOND = "tcprecond"
P_TCPOSTCOND = "tcpostcond"
P_TSBASE = "tsbase"
P_TSLOG = "tslog"
P_TSPARFILE = "tsparfile"
P_TSSUM = "tssum"
P_XPBASE = "xpbase"
P_XPRESULT = "xpresult"
P_XPBACKUP = "xpbackup"
# -------------------------------------------------------------
# exception texts
EXP_COMP_MISSING = "Component is missing for {}"

112
utils/path_tool.py

@ -5,29 +5,38 @@
# 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 sys
import basic.program import basic.program
import utils.config_tool import utils.config_tool
import re import re
import basic.constants as B import basic.constants as B
import utils.path_const as P
TOOL_NAME = "path_tool"
def getKeyValue(key, comp=None): def getKeyValue(key, comp=None):
"""
this function gets the value for the key which relates to an attribute in the job or in the component
:param key:
:param comp:
:return:
"""
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = job.getDebugLevel("path_tool")-4 verify = job.getDebugLevel(TOOL_NAME)-4
pt = PathConf.getInstance() pt = PathConf.getInstance()
job.debug(verify, "getKeyValue " + key) job.debug(verify, "getKeyValue " + key)
if 'job.par' in key: if 'job.par' in key:
neu = job.getParameter(key[8:]) val = job.getParameter(key[8:])
return neu return val
elif 'job.conf' in key: elif 'job.conf' in key:
neu = job.conf.confs[B.SUBJECT_PATH][key[9:]] val = job.conf.confs[B.SUBJECT_PATH][key[9:]]
job.debug(verify, neu) job.debug(verify, val)
return neu return val
# return job.conf.confs["paths"][key[9:]] # return job.conf.confs["paths"][key[9:]]
elif 'comp.' in key: elif 'comp.' in key:
if comp is None: if comp is None:
raise Exception("Component is missing for "+key) raise Exception(P.EXP_COMP_MISSING.format(key))
if utils.config_tool.hasAttr(comp.conf, key[5:]): if utils.config_tool.hasAttr(comp.conf, key[5:]):
return utils.config_tool.getAttr(comp.conf, key[5:]) return utils.config_tool.getAttr(comp.conf, key[5:])
if utils.config_tool.hasAttr(comp, key[5:]): if utils.config_tool.hasAttr(comp, key[5:]):
@ -44,8 +53,15 @@ def getKeyValue(key, comp=None):
def composePath(pathname, comp): def composePath(pathname, comp):
"""
this function composes a concrete path by the structured pathname
- the key of pathname is declared in path_const and the structure is configurated in config/path.yml.
:param pathname - plain keyword
:param comp:
:return:
"""
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = job.getDebugLevel("path_tool") verify = job.getDebugLevel(TOOL_NAME)
pt = PathConf.getInstance() pt = PathConf.getInstance()
job.debug(verify, "composePath " + pathname + " zu " + str(pt) + "mit ") job.debug(verify, "composePath " + pathname + " zu " + str(pt) + "mit ")
job.debug(verify, str(pt.pattern)) job.debug(verify, str(pt.pattern))
@ -56,8 +72,16 @@ def composePath(pathname, comp):
def composePattern(pattern, comp): def composePattern(pattern, comp):
"""
the function composes the pattern to the standardarized path with the attributes
which are stored in the job and the component
- the key of pathname is declared in path_const and the structure is configurated in config/path.yml.
:param pattern: - keyword surroundet with {}
:param comp:
:return: path
"""
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = job.getDebugLevel("path_tool") verify = job.getDebugLevel(TOOL_NAME)
job.debug(verify, "composePattern " + pattern) job.debug(verify, "composePattern " + pattern)
max=5 max=5
l = re.findall('\{.*?\}', pattern) l = re.findall('\{.*?\}', pattern)
@ -78,9 +102,61 @@ def composePattern(pattern, comp):
return pattern return pattern
def rejoinPath(a, b="", c="", d="", e="", f=""):
"""
this function concatenates the arguments to a path in the correct format for the operating-system
:param a:
:param b: optional
:param c: optional
:param d: optional
:param e: optional
:param f: optional
:return: path
"""
work = a+"/"+b+"/"+c+"/"+d+"/"+e+"/"+f
if a.find("://") > 1:
protocol = True
else:
protocol = False
work = re.sub(r'\\', '/', work)
work = re.sub(r'\/', '/', work)
work = re.sub(r'//', '/', work)
while work[-1:] == "/":
work = work[0:-1]
l = work.split("/")
out = ""
for x in l:
if len(x) < 1:
continue
if protocol:
if len(out) < 1:
out = x
else:
out = out+"/"+x
else:
out = os.path.join(out, x)
if out[1:2] == ":" and out[2:3] != "\\":
out = out[0:2]+"\\"+out[2:]
elif protocol:
if "://" not in out or out.index("://") > 8 or out.index("://") < 1:
i = out.index(":/")
out = out[0:i+1] + "/" + out[i+1:]
pass
if not protocol and out.count("\\") < 1 and out[0:1] != "/" and out[0:2] != "..":
out = "/"+out
return out
def extractPattern(pathtyp, comp=None): def extractPattern(pathtyp, comp=None):
"""
this function extracts recoursively all parts of the pathstrucure as key and gets the values from the
job-parameter and job-configuration
:param pathtyp: the name of the path-structure
:param comp:
:return: dictionary of all part (key) with their valuess
"""
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = job.getDebugLevel("path_tool") verify = job.getDebugLevel(TOOL_NAME)
out = [] out = []
pt = PathConf.getInstance() pt = PathConf.getInstance()
pattern = pt.pattern[pathtyp] pattern = pt.pattern[pathtyp]
@ -97,10 +173,19 @@ def extractPattern(pathtyp, comp=None):
work = work[j+1:] work = work[j+1:]
return out return out
def extractPath(pathtyp, pathname): def extractPath(pathtyp, path):
"""
this function extracts parts of a concrete structered path and stores the parts
as attributes into the actual job. So these attributes can read from the concrete
path instead of the related parameter-arguments.
It stores the values into the job-parameter
:param pathtyp: the structure of the concrete path
:param path: the concrete path - it should be the directory in the parameter of the job
:return:
"""
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
patterlist = extractPattern(pathtyp) patterlist = extractPattern(pathtyp)
work = pathname work = path
i = 0 i = 0
print("-- extractPatternList -- " + pathtyp + ":" + str(patterlist)) print("-- extractPatternList -- " + pathtyp + ":" + str(patterlist))
for p in patterlist: for p in patterlist:
@ -151,6 +236,9 @@ def extractPath(pathtyp, pathname):
class PathConf: class PathConf:
"""
this class contains the structure-informations of the testrelevant directories
"""
__instance = None __instance = None
def __init__(self): def __init__(self):
print('init pathConf') print('init pathConf')

Loading…
Cancel
Save