Browse Source

further correction after tests

master
Ulrich Carmesin 3 years ago
parent
commit
44dfb287fd
  1. 71
      basic/program.py
  2. 22
      collect_testcase.py
  3. 12
      components/testexec.py
  4. 34
      finish_testsuite.py
  5. 2
      init_testcase.py
  6. 2
      init_testsuite.py
  7. 17
      test/test_date.py
  8. 43
      test_executer.py
  9. 18
      utils/config_tool.py
  10. 5
      utils/db_abstract.py

71
basic/program.py

@ -9,8 +9,8 @@
#import sys, getopt #import sys, getopt
import argparse import argparse
import copy import copy
import yaml
import yaml, os import os
from datetime import datetime from datetime import datetime
import basic.constants as B import basic.constants as B
import basic.message import basic.message
@ -18,6 +18,7 @@ import basic.message
import basic.componentHandling import basic.componentHandling
import utils.date_tool import utils.date_tool
import utils.path_tool import utils.path_tool
import utils.file_tool
jobdef = { jobdef = {
"unit": { "unit": {
@ -55,16 +56,23 @@ jobdef = {
"basedir": "tcbase", "basedir": "tcbase",
"dirname": "tcdir", "dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" }, "logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" },
"execute_testcase": {
"pardef": "tcdir", # ",tdtyp,tdsrc,tdname",
"pfilesource": "tcparfile",
"pfiletarget": "tcparfile",
"basedir": "tcbase",
"dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" },
"collect_testcase": { "collect_testcase": {
"pardef": "tcdir", # ",tdtyp,tdsrc,tdname", "pardef": "tcdir", # ",tdtyp,tdsrc,tdname",
"pfilesource" : "envparfile", "pfilesource": "tcparfile",
"pfiletarget": "tcparfile", "pfiletarget": "tcparfile",
"basedir": "tcbase", "basedir": "tcbase",
"dirname": "tcdir", "dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" }, "logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" },
"compare_testcase": { "compare_testcase": {
"pardef": "tcdir", # ",tdtyp,tdsrc,tdname", "pardef": "tcdir", # ",tdtyp,tdsrc,tdname",
"pfilesource" : "envparfile", "pfilesource": "tcparfile",
"pfiletarget": "tcparfile", "pfiletarget": "tcparfile",
"basedir": "tcbase", "basedir": "tcbase",
"dirname": "tcdir", "dirname": "tcdir",
@ -72,22 +80,22 @@ jobdef = {
"test_system": { "test_system": {
"pardef": "tcdir,tdtyp,tdsrc,tdname", "pardef": "tcdir,tdtyp,tdsrc,tdname",
"pfilesource": "tsparfile", "pfilesource": "tsparfile",
"pfiletarget": "tcparfile", "pfiletarget": "tsparfile",
"basedir": "tcbase", "basedir": "tcbase",
"dirname": "tcdir", "dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt"}, "logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt"},
"finish_testcase": { "finish_testcase": {
"pardef": "tcdir,tdtyp,tdsrc,tdname", "pardef": "tcdir",
"pfilesource": "tsparfile", "pfilesource": "tcparfile",
"pfiletarget": "tcparfile", "pfiletarget": "tcparfile",
"basedir": "tcbase", "basedir": "tcbase",
"dirname": "tcdir", "dirname": "tcdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt"}, "logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt"},
"finish_testsuite": { "finish_testsuite": {
"pardef": "tcdir,tdtyp,tdsrc,tdname", "pardef": "tsdir",
"pfilesource": "tsparfile", "pfilesource": "tsparfile",
"pfiletarget": "tcparfile", "pfiletarget": "tssarfile",
"basedir": "tcbase", "basedir": "tsbase",
"dirname": "tsdir", "dirname": "tsdir",
"logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt"} "logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt"}
} }
@ -141,9 +149,18 @@ class Job:
def setProgram(self, program): def setProgram(self, program):
self.program = program self.program = program
self.par.program = program basedir = jobdef[program]["basedir"]
self.par.setBasedir(program) if (self.par is not None):
self.m.setLogdir("logTime") setattr(self.par, "program", program)
setattr(self.par, "basedir", basedir)
parstring = getattr(self.par, "parstring")
parstring = parstring[parstring.find("--"):]
parstring = "python "+program+" "+parstring
setattr(self.par, "parstring", parstring)
if not hasattr(self.par, jobdef[program]["dirname"]):
setattr(self.par, jobdef[program]["dirname"],
utils.path_tool.composePattern("{"+basedir+"}", None))
self.par.setParameterLoaded()
def getInstance(): def getInstance():
if (Job.__instance is not None): if (Job.__instance is not None):
@ -178,21 +195,28 @@ class Job:
def dumpParameter(self): def dumpParameter(self):
parpath = utils.path_tool.composePath(jobdef[self.program]["pfiletarget"], None) parpath = utils.path_tool.composePath(jobdef[self.program]["pfiletarget"], None)
if not os.path.exists(parpath):
return None
output = {} output = {}
output["comps"] = basic.componentHandling.getComponentDict() cconf = basic.componentHandling.getComponentDict()
output["par"] = self.par.__dict__ output["par"] = self.par.__dict__
# print(str(output)) output["comps"] = {}
with open(parpath, "w") as file: for c in cconf:
doc = yaml.dump(output, file) output["comps"][c] = {}
file.close() for x in ["function", "conn"]:
output["comps"][c][x] = cconf[c][x]
if x == "conn" and "passwd" in cconf[c][x]:
output["comps"][c][x]["passwd"] = "xxxxx"
utils.file_tool.writeFileText(self.m, parpath, output)
def loadParameter(self): def loadParameter(self):
output = {} output = {}
if len(str(jobdef[self.program]["pfilesource"])) < 2: if len(str(jobdef[self.program]["pfilesource"])) < 2:
return None return None
parpath = utils.path_tool.composePath(jobdef[self.program]["pfilesource"], None) parpath = utils.path_tool.composePath(jobdef[self.program]["pfilesource"], None)
with open(parpath, "r") as file: if not os.path.join(parpath):
doc = yaml.full_load(file) return None
doc = utils.file_tool.readFileDict(parpath, self.m)
for k in doc.keys(): for k in doc.keys():
output[k] = copy.deepcopy(doc[k]) output[k] = copy.deepcopy(doc[k])
return output return output
@ -256,7 +280,7 @@ class Parameter:
if hasattr(self, jobdef[program]["dirname"]): if hasattr(self, jobdef[program]["dirname"]):
utils.path_tool.extractPath(self.basedir, getattr(self, jobdef[program]["dirname"])) utils.path_tool.extractPath(self.basedir, getattr(self, jobdef[program]["dirname"]))
elif program != "unit": elif program != "unit":
dirpath = utils.path_tool.composePatttern("{"+jobdef[program]["basedir"]+"}", None) dirpath = utils.path_tool.composePattern("{"+jobdef[program]["basedir"]+"}", None)
setattr(self, jobdef[program]["dirname"], dirpath) setattr(self, jobdef[program]["dirname"], dirpath)
else: else:
self.basedir = "debugs" self.basedir = "debugs"
@ -331,6 +355,9 @@ class Parameter:
for k in vars(args): for k in vars(args):
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()
if dirpath is not None:
utils.path_tool.extractPath(dirpath[0], dirpath[1])
def setParameterLoaded(self): def setParameterLoaded(self):
job = Job.getInstance() job = Job.getInstance()
@ -369,6 +396,7 @@ class Configuration:
def setConfiguration(self, path): def setConfiguration(self, path):
self.confs = {} self.confs = {}
doc = utils.file_tool.readFileLines(path, None)
with open(path, "r") as file: with open(path, "r") as file:
doc = yaml.full_load(file) doc = yaml.full_load(file)
if "basic" in doc: if "basic" in doc:
@ -377,6 +405,7 @@ class Configuration:
else: else:
for i, v in doc.items(): for i, v in doc.items():
self.confs[i] = v self.confs[i] = v
def setConfig(self, path, val): def setConfig(self, path, val):
a = path.split(".") a = path.split(".")
if len(a) == 1: if len(a) == 1:

22
finish_testcase.py → collect_testcase.py

@ -3,11 +3,23 @@ import sys#
# import jsonpickle # pip install jsonpickle # import jsonpickle # pip install jsonpickle
import yaml # pip install pyyaml import yaml # pip install pyyaml
import basic.program import basic.program
from basic.componentHandling import ComponentManager import basic.componentHandling
import basic.message import basic.message
import utils.tdata_tool import utils.tdata_tool
PROGRAM_NAME = "finish_testcase" PROGRAM_NAME = "collect_testcase"
def startPyJob(job):
cm = basic.componentHandling.ComponentManager.getInstance("init")
cm.initComponents()
comps = cm.getComponents(PROGRAM_NAME)
print(" relevant components for this job: " + str(comps))
tdata = utils.tdata_tool.getTestdata()
job.m.setMsg("# components initialized with "+str(comps))
for c in comps:
comp = cm.getComponent(c)
comp.collect_Artifacts("testcase")
job.m.merge(comp.m)
if __name__ == '__main__': if __name__ == '__main__':
x = basic.program.Job(PROGRAM_NAME) x = basic.program.Job(PROGRAM_NAME)
@ -20,10 +32,6 @@ if __name__ == '__main__':
x.stopJob() x.stopJob()
exit(x.m.rc * (-1) + 3) exit(x.m.rc * (-1) + 3)
# now in theory the program is runnable # now in theory the program is runnable
cm = ComponentManager() startPyJob(x)
cm.initComponents()
comps = getComponents(PROGRAM_NAME)
print(" relevant components for this job: " + str(comps))
tdata = utils.tdata_tool.getTestdata()
x.stopJob() x.stopJob()
# See PyCharm help at https://www.jetbrains.com/help/pycharm/ # See PyCharm help at https://www.jetbrains.com/help/pycharm/

12
components/testexec.py

@ -106,7 +106,17 @@ class Testexecuter():
self.m.setMsg("data loaded for " + self.name + " is OK") self.m.setMsg("data loaded for " + self.name + " is OK")
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper())
def read_TData(self, granularity): def collect_TcArtifacts(self):
"""
collects the artifacts from the test-system.
the result is written as original in subfolder {tsorigin}
:return:
"""
job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel(self.name)
self.read_TData("nachher", "testcase")
def read_TData(self, subdir, granularity):
""" """
:param granularity: :param granularity:

34
finish_testsuite.py

@ -1,15 +1,41 @@
# This is a sample Python script. # This is a sample Python script.
import os.path
import sys# import sys#
# import jsonpickle # pip install jsonpickle # import jsonpickle # pip install jsonpickle
import yaml # pip install pyyaml
import basic.program as program import basic.program as program
from basic.componentHandling import ComponentManager import basic.componentHandling
import basic.message as message import utils.file_tool
import utils.path_tool
import utils.report_tool
import utils.zip_tool
# Press Umschalt+F10 to execute it or replace it with your code. # Press Umschalt+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
PROGRAM_NAME = "finish_testsuite"
def startPyJob(job):
cm = basic.componentHandling.ComponentManager.getInstance("init")
report = utils.report_tool.Report()
testinstances = {}
if hasattr(job.par, "testinstances"):
testinstances = getattr(job.par, "testinstances")
for tc in testinstances:
path = os.path.join(testinstances[tc], "Result.html")
text = utils.file_tool.readFileText(path, job.m)
report.extractTestcase(tc, text)
text = report.reportTestsuite()
path = os.path.join(job.par.tsdir, "Result.html")
utils.file_tool.writeFileText(job.m, path, text)
archivFolder = job.conf.confs["paths"]["archiv"]
tsFolder = os.path.join(archivFolder, "Testlauf")
tarfile = utils.zip_tool.openNewTarFile(tsFolder, job.par.usecase+"_"+job.par.tstime+".tar.gz")
utils.zip_tool.appendFolderIntoTarFile(tsFolder, job.par.usecase+"_"+job.par.tstime, tarfile)
for tc in testinstances:
tcSubFolder = testinstances[tc][len(archivFolder)+1:]
utils.zip_tool.appendFolderIntoTarFile(archivFolder, tcSubFolder, tarfile)
tarfile.close()
pass
# Press the green button in the gutter to run the script. # Press the green button in the gutter to run the script.
if __name__ == '__main__': if __name__ == '__main__':
@ -20,9 +46,9 @@ if __name__ == '__main__':
x.m.logInfo("hier eine LogInfo") x.m.logInfo("hier eine LogInfo")
x.m.logDebug("hier eine DbugMeldung") x.m.logDebug("hier eine DbugMeldung")
x.m.logDebug(str(vars(x.par)) + "\n" + str(vars(x.conf))) x.m.logDebug(str(vars(x.par)) + "\n" + str(vars(x.conf)))
cm = ComponentManager()
if x.m.isRc("fatal"): if x.m.isRc("fatal"):
x.stopJob() x.stopJob()
exit(x.m.rc * (-1) + 3) exit(x.m.rc * (-1) + 3)
startPyJob(x)
x.stopJob() x.stopJob()
# See PyCharm help at https://www.jetbrains.com/help/pycharm/ # See PyCharm help at https://www.jetbrains.com/help/pycharm/

2
init_testcase.py

@ -24,7 +24,7 @@ def startPyJob(job):
comp.m.logInfo("------- "+comp.name+" ----------------------------------------") comp.m.logInfo("------- "+comp.name+" ----------------------------------------")
comp.reset_TData("testcase") comp.reset_TData("testcase")
comp.load_TData("testcase", testdata) comp.load_TData("testcase", testdata)
comp.read_TData("testcase") comp.read_TData("vorher", "testcase")
comp.m.logInfo("------- "+comp.name+" ----------------------------------------") comp.m.logInfo("------- "+comp.name+" ----------------------------------------")
job.m.merge(comp.m) job.m.merge(comp.m)
print(str(comp)) print(str(comp))

2
init_testset.py → init_testsuite.py

@ -22,7 +22,7 @@ if __name__ == '__main__':
# now in theory the program is runnable # now in theory the program is runnable
cm = ComponentManager() cm = ComponentManager()
cm.initComponents() cm.initComponents()
comps = getComponents(PROGRAM_NAME) comps = cm.getComponents(PROGRAM_NAME)
print(" relevant components for this job: " + str(comps)) print(" relevant components for this job: " + str(comps))
tdata = utils.tdata_tool.getTestdata() tdata = utils.tdata_tool.getTestdata()
x.stopJob() x.stopJob()

17
test/test_date.py

@ -0,0 +1,17 @@
import json
import unittest
import datetime
import utils.date_tool
class MyTestCase(unittest.TestCase):
def test_dateformat(self):
stime = datetime.datetime.now()
print(stime)
tdate = (2022, 2, 10)
sdate = datetime.datetime(tdate[0], tdate[1],tdate[2], 3, 32, 23)
sdate = datetime.datetime(stime)
print(sdate)
if __name__ == '__main__':
unittest.main()

43
test_executer.py

@ -2,47 +2,74 @@ from datetime import datetime
import basic.program import basic.program
import basic.program as program import basic.program as program
import utils.tdata_tool import utils.tdata_tool
import init_testcase
import init_testsuite
import execute_testcase
import finish_testsuite
PROGRAM_NAME = "test_executer" PROGRAM_NAME = "test_executer"
myjob = None
testcases = []
testinstances = {}
def getTime(): def getTime():
time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
return time return time
def start(job): def start(myjob):
job.m.setMsg("# # # # # start executer # # # # # ") myjob.m.setMsg("# # # # # start executer # # # # # ")
tdata = utils.tdata_tool.getTestdata() tdata = utils.tdata_tool.getTestdata()
myjob = job job = basic.program.Job("unit")
testcases = getattr(myjob.par, "testcases")
if not hasattr(myjob.par, "step"):
raise Exception("Parameter step is missing")
for step in tdata["_steps"]: for step in tdata["_steps"]:
if int(step["_nr"]) != int(getattr(myjob.par, "step")):
continue
for arg in step["args"]: for arg in step["args"]:
if arg == "start": if arg == "start":
if "testsuite" in step["args"][arg]: if "testsuite" in step["args"][arg]:
jobargs = {"application": job.par.application, "environment": job.par.environment, jobargs = {"application": myjob.par.application, "environment": myjob.par.environment,
"usecase": job.par.usecase, "tstime": getTime()} "usecase": myjob.par.usecase, "tstime": utils.date_tool.getActdate(utils.date_tool.F_DIR)}
job.popInstance() job.popInstance()
job = basic.program.Job("unit") job = basic.program.Job("unit")
job.par.setParameterArgs(jobargs) job.par.setParameterArgs(jobargs)
job.setProgram(step["args"][arg]) job.setProgram(step["args"][arg])
print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tsdir")) print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tsdir"))
myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tsdir"))
dirname = getattr(job.par, "tsdir")
job.stopJob(1) job.stopJob(1)
job.popInstance() job.popInstance()
basic.program.Job.pushInstance(myjob) basic.program.Job.pushInstance(myjob)
print("ende") print("ende")
job = myjob job = myjob
if "testcase" in step["args"][arg]: if "testcase" in step["args"][arg]:
jobargs = {"application": job.par.application, "environment": job.par.environment, if step["comp"] in testcases:
"testcase": step["comp"], "tctime": getTime()} jobargs = {"application": myjob.par.application, "environment": myjob.par.environment,
"tcdir": testcases[step["comp"]] }
else:
jobargs = {"application": myjob.par.application, "environment": myjob.par.environment,
"testcase": step["comp"], "tctime": utils.date_tool.getActdate(utils.date_tool.F_DIR)}
job.popInstance() job.popInstance()
job = basic.program.Job("unit") job = basic.program.Job("unit")
job.par.setParameterArgs(jobargs) job.par.setParameterArgs(jobargs)
job.setProgram(step["args"][arg]) job.setProgram(step["args"][arg])
print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tcdir")) print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tcdir"))
myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tcdir"))
dirname = getattr(job.par, "tcdir")
testcases[step["comp"]] = dirname
job.stopJob(1) job.stopJob(1)
job.popInstance() job.popInstance()
basic.program.Job.pushInstance(myjob) basic.program.Job.pushInstance(myjob)
print("ende") print("ende")
job = myjob job = myjob
if arg == "report": # testsuite
basic.program.Job.pushInstance(myjob)
pass
basic.program.Job.pushInstance(myjob)
setattr(myjob.par, "testcases", testcases)
# myjob.stopJob(1)
if __name__ == '__main__': if __name__ == '__main__':

18
utils/config_tool.py

@ -12,9 +12,9 @@ try:
except ImportError: except ImportError:
print("ImportError: " + str(ImportError.with_traceback())) print("ImportError: " + str(ImportError.with_traceback()))
pass pass
import yaml
import basic.componentHandling import basic.componentHandling
import utils.path_tool import utils.path_tool
import utils.file_tool
import os.path import os.path
import basic.constants as B import basic.constants as B
@ -69,7 +69,8 @@ def getConfigPath(modul, name, subname=""):
job.debug(verify, "6 " + pathname) job.debug(verify, "6 " + pathname)
elif modul in COMP_FILES: elif modul in COMP_FILES:
for format in CONFIG_FORMAT: for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.confs.get("paths").get("program"), "components", basic.componentHandling.getComponentFolder(name), modul+"."+format) pathname = os.path.join(job.conf.confs.get("paths").get("program"), "components",
basic.componentHandling.getComponentFolder(name), modul+"."+format)
if os.path.exists(pathname): if os.path.exists(pathname):
return pathname return pathname
if len(subname) > 1: if len(subname) > 1:
@ -145,16 +146,17 @@ def hasAttr(o, name):
return True return True
return False return False
def getConfig(modul, name): def getConfig(modul, name, subname=""):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = job.getDebugLevel("config_tool")-4 verify = job.getDebugLevel("config_tool")-4
pathname = getConfigPath(modul, name) msg = None
if hasattr(job, "m"): msg = job.m
pathname = getConfigPath(modul, name, subname)
confs = {} confs = {}
job.debug(verify, "getConfig " + pathname) job.debug(verify, "getConfig " + pathname)
with open(pathname, "r") as file: if len(pathname) < 1:
job.debug(verify, "openfile") return confs
doc = yaml.full_load(file) doc = utils.file_tool.readFileDict(pathname, msg)
for i, v in doc.items(): for i, v in doc.items():
job.debug(verify, "item " + str(i) + ": " + str(v))
confs[i] = v confs[i] = v
return confs return confs

5
utils/db_abstract.py

@ -142,13 +142,14 @@ class DbFcts():
return out return out
def selectTables(self): def selectTables(self, subdir):
""" method to delete rows from a database """ method to delete rows from a database
statement written in sql """ statement written in sql """
self.loadDdl() self.loadDdl()
tdata = {} tdata = {}
tdata[subdir] = {}
for t in self.comp.conf[B.DATA_NODE_DDL]: for t in self.comp.conf[B.DATA_NODE_DDL]:
tdata[t] = self.selectRows(t) tdata[subdir][t] = self.selectRows(t)
return tdata return tdata
def selectRows(self, statement): def selectRows(self, statement):

Loading…
Cancel
Save