Compare commits

...

5 Commits

  1. 13
      basic/compexec.py
  2. 4
      basic/component.py
  3. 5
      basic/componentHandling.py
  4. 1
      basic/constants.py
  5. 17
      basic/message.py
  6. 49
      basic/program.py
  7. 17
      basic/toolHandling.py
  8. 146
      start_dialog.py
  9. 29
      test/constants.py
  10. 49
      test/test_01date.py
  11. 43
      test/test_02css.py
  12. 12
      test/test_03path.py
  13. 9
      test/test_04config.py
  14. 27
      test/test_05conn.py
  15. 2
      test/test_06file.py
  16. 12
      test/test_07catalog.py
  17. 96
      test/test_08i18n.py
  18. 0
      test/test_11component.py
  19. 21
      test/test_12toolhandling.py
  20. 21
      test/test_21tdata.py
  21. 106
      test/test_22compare.py
  22. 0
      test/test_22report.py
  23. 17
      test/test_31db.py
  24. 78
      test/test_71job.py
  25. 23
      test/test_conn.py
  26. 2
      test/test_xml.py
  27. 4
      test/testtools.py
  28. 49
      unit_run.py
  29. 13
      utils/config_tool.py
  30. 12
      utils/db_abstract.py
  31. 102
      utils/dbrel_tool.py
  32. 87
      utils/file_abstract.py
  33. 26
      utils/file_tool.py
  34. 95
      utils/i18n_tool.py
  35. 2
      utils/path_const.py

13
basic/compexec.py

@ -1,3 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
# abstract class for testrunning-functions
# ---------------------------------------------
"""
@ -32,6 +38,7 @@ import basic.message
import basic.program
import inspect
import os
import re
import utils.db_abstract
import basic.toolHandling
import basic.component
@ -196,12 +203,14 @@ class Testexecuter():
sql_new += " "+attr[B.ATTR_DB_DATABASE]+"."+table
print("sql_new "+sql_new)
if (hasattr(job.par, B.PAR_DB_WHERE)):
# actual it parses only conjunct or disjunct normalform without parentesis
parts = utils.db_abstract.parseSQLwhere(getattr(job.par, B.PAR_DB_WHERE), self.conf[B.DATA_NODE_DDL][table])
# Felder und Operationen
# print(dbwhere)
sql_new += " WHERE "+getattr(job.par, B.PAR_DB_WHERE)
sql_new += " WHERE "+parts
if sql_new[0:6] == "SELECT":
sql_new += " ORDER BY id"
ids = utils.db_abstract.getTechnicalIDFields(self.conf["ddl"][table])
sql_new += " ORDER BY "+",".join(ids)
print("sql_new "+sql_new)
sql_new = sql_new.replace('!', "\'")
if (hasattr(job.par, B.PAR_DB_PARTITION)) and (attr[B.ATTR_DB_PARTITION] != "n"):

4
basic/component.py

@ -8,7 +8,7 @@
# ---------------------------------------------------------------------
from datetime import datetime
import basic.testexec
import basic.compexec
import basic.message
import basic.program
import inspect
@ -24,7 +24,7 @@ class CompData:
#class Component(components.sysmonitor.SystemMonitor, components.testexec.Testexecuter, components.report.Report,
# components.maintain.Maintainer, components.catalog, threading.Thread):
class Component(basic.testexec.Testexecuter):
class Component(basic.compexec.Testexecuter):
"""
A component represents an application of the system-under-test or a data-artifact which is created from the system-under-test.
As the representation it has to knowlegde of the url, which other components depends on this component.

5
basic/componentHandling.py

@ -86,6 +86,8 @@ class ComponentManager:
job.m.setFatal("application " + job.par.application + " is not configured")
return
for k in job.conf.confs[B.SUBJECT_APPS].get(anw):
if k == B.ATTR_APPS_PROJECT:
continue
job.m.logDebug("applicationscomponente -- " + k + ":")
print("applicationscomponente -- " + k + ":")
self.createComponent(k, 0, "")
@ -179,6 +181,7 @@ class ComponentManager:
:param nr: number if component is multiple
:return: instance of the component with all necessary attributes
"""
job = basic.program.Job.getInstance()
cmodul = importlib.import_module(getComponentPath(compName))
class_ = getattr(cmodul, getComponentClass(compName))
c = class_()
@ -189,7 +192,7 @@ class ComponentManager:
name = compName
i = 0
c.name = name
c.m = basic.message.Message(basic.message.LIMIT_DEBUG, "logTime", name)
c.m = basic.message.Message(job, basic.message.LIMIT_DEBUG, "logTime", name)
c.conf = utils.config_tool.mergeConn(c.m, confs["conf"], conns[i])
c.conf[B.SUBJECT_CONN] = conns[i]
c.init()

1
basic/constants.py

@ -172,6 +172,7 @@ ATTR_PATH_PATTN = "pattern"
""" This constant defines the debug-folder in testing-filesystem """
SUBJECT_APPS = "applications" # | x | | | | CompHandling
ATTR_APPS_PROJECT = "project" # | | | | x | CompHanlding
SUBJECT_INST = "instance" # | | | | x | CompHanlding
ATTR_INST_CNT = "count" # | | | | x | CompHanlding

17
basic/message.py

@ -53,14 +53,9 @@ class Message:
"debug": "24", # wird nur in debug ausgegeben, wenn log-level hoechstens auf eingestelltem job-level steht
"trace": "28", # wird nur in debug ausgegeben, wenn log-level hoechstens auf eingestelltem job-level steht
"""
def __init__(self, level, logTime, componente):
def __init__(self, job, level, logTime, componente):
# (self, componente, out, level):
self.componente = componente # dezantrales Logsystem
#self.level = level # Vorgabe zu level zum Filtern, ob auszugebe
job = basic.program.Job.getInstance()
# print(vars(job))
# print(globals())
# exit(5)
verify = LIMIT_DEBUG
self.initErrorTyp()
self.rc = RC_INFO
@ -87,23 +82,23 @@ class Message:
elif job.program == "unit":
self.logfile = self.debugfile
else:
self.setLogdir(logTime)
self.setLogdir(job, logTime)
self.topmessage = ""
self.messages = []
print("message initialisiert mit level " + str(self.level))
def setLogdir(self, logTime):
job = basic.program.Job.getInstance()
def setLogdir(self, job, logTime):
basedir = job.par.basedir
basedir = basedir.replace("base", "log")
# basedir = utils.path_tool.composePath(basedir, None)
basedir = utils.path_tool.composePath(basedir, None)
os.makedirs(basedir, exist_ok=True)
logpath = basedir + "/protokoll_" + logTime + ".txt"
logpath = os.path.join(basedir , job.program + "_" + logTime + ".txt")
self.logDebug("logfile " + logpath)
self.logfile = open(logpath, "w")
def initErrorTyp(self):
self.CONST_ERRTYP = {
"fatal": "4", # wird immer in debug und log ausgegeben, setzt RC

49
basic/program.py

@ -19,6 +19,7 @@ import basic.componentHandling
import utils.date_tool
import utils.path_tool
import utils.file_tool
import utils.config_tool
jobdef = {
@ -109,18 +110,24 @@ EXCP_CANT_POP = "cant pop this job from the instances"
class Job:
__instance = None
instances = []
__instances = []
def __init__ (self, program):
print ("################# init Job ## " + program + " #################")
self.program = program
Job.__instance = self
if Job.__instances is None:
Job.__instances = []
Job.pushInstance(self)
par = Parameter(program)
self.par = par
print("prog-42 " + str(self.par.basedir))
conf = Configuration(program)
self.conf = conf
appl = utils.config_tool.getConfig("basic", B.SUBJECT_APPS)
print(appl)
if appl is not None:
self.conf.confs[B.SUBJECT_APPS] = appl[B.SUBJECT_APPS]
print("prog-45 " + str(self.par.basedir))
dirpath = self.par.getDirParameter()
setGlobal()
@ -129,7 +136,7 @@ class Job:
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(basic.message.LIMIT_DEBUG, logTime, None)
self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None)
print("prog-50 " + str(self.par.basedir))
@staticmethod
@ -138,27 +145,27 @@ class Job:
if pjob is not None and Job.__instance is not None and Job.__instance != pjob:
raise Exception(B.EXP_CANT_POP)
# for guarantee that both the stack and the original variable is empty if one is empty
if len(Job.instances) < 1:
if len(Job.__instances) < 1:
Job.__instance = None
return None
if Job.__instance is None:
while len(Job.instances) > 0:
Job.instances.pop()
while len(Job.__instances) > 0:
Job.__instances.pop()
return None
if len(Job.instances) == 1:
if len(Job.__instances) == 1:
job = Job.__instance
job.stopJob(1)
Job.instances.pop()
Job.__instances.pop()
Job.__instance = None
return None
job = Job.instances.pop()
job = Job.__instances.pop()
if pjob is not None and job is not None and job != pjob:
Job.instances.append(job)
Job.__instances.append(job)
Job.__instance = job
raise Exception(B.EXP_CANT_POP)
if len(Job.instances) > 0:
topjob = Job.instances.pop()
Job.instances.append(topjob)
if len(Job.__instances) > 0:
topjob = Job.__instances.pop()
Job.__instances.append(topjob)
Job.__instance = topjob
else:
Job.__instance = None
@ -168,11 +175,11 @@ class Job:
@staticmethod
def pushInstance(pjob):
""" push a new created subjob """
if len(Job.instances) > 0:
job = Job.instances.pop()
if len(Job.__instances) > 0:
job = Job.__instances.pop()
if pjob is not None and job is not None and job != pjob:
Job.instances.append(job)
Job.instances.append(pjob)
Job.__instances.append(job)
Job.__instances.append(pjob)
Job.__instance = pjob
return pjob
@ -214,7 +221,7 @@ class Job:
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(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))
self.par.setParameterLoaded()
self.m.logInfo("# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ")
@ -249,6 +256,8 @@ class Job:
for c in cconf:
output[B.SUBJECT_COMPS][c] = {}
for x in ["function", "conn"]:
if x not in cconf[c]:
continue
output[B.SUBJECT_COMPS][c][x] = cconf[c][x]
if x == B.SUBJECT_CONN and "passwd" in cconf[c][x]:
cconf[B.SUBJECT_COMPS][c][x]["passwd"] = "xxxxx"
@ -435,6 +444,12 @@ class Parameter:
dirpath = self.getDirParameter()
if dirpath is not None:
utils.path_tool.extractPath(dirpath[0], dirpath[1])
app = self.application
if self.application in job.conf.confs[B.SUBJECT_APPS]:
if B.ATTR_APPS_PROJECT in job.conf.confs[B.SUBJECT_APPS][self.application]:
setattr(self, B.ATTR_APPS_PROJECT, job.conf.confs[B.SUBJECT_APPS][self.application][B.ATTR_APPS_PROJECT])
proj = getattr(self, B.ATTR_APPS_PROJECT)
app2 = self.application
def setParameterLoaded(self):

17
basic/toolHandling.py

@ -4,7 +4,8 @@
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import importlib, os
import importlib
import os
import basic.program
import basic.constants as B
# -------------------------------------------------
@ -91,3 +92,17 @@ def getApiTool(comp):
c = class_()
c.setComp(comp)
return c
def getFileTool(job, comp=None):
verify = int(job.getDebugLevel("db_tool"))
filetype = getCompAttr(comp, B.TOPIC_NODE_FILE, B.ATTR_TYPE, "")
toolname = "file"+filetype+"_tool"
filepath = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_PROGRAM], "utils", toolname+".py")
#comp.m.debug(verify, "toolname "+filepath)
if not os.path.exists(filepath):
raise FileNotFoundError("file for tool "+toolname+" does not exist "+filepath)
cmodul = importlib.import_module("utils."+toolname)
class_ = getattr(cmodul, "FileFcts")
c = class_()
c.setComp(job, comp)
return c

146
start_dialog.py

@ -0,0 +1,146 @@
"""
"""
import os.path
import json
import basic.program
import basic.constants as B
import utils.file_tool
tempJob = {}
PROGRAM_NAME = "unit"
JSON_FILE = "actualJob.json"
JOB_NR = {
"init_testsuite": {
"jobnr": "0" },
"execute_testsuite": {
"jobnr": "1"},
"collect_testsuite": {
"jobnr": "2"},
"compare_testsuite": {
"jobnr": "3"},
"finish_testsuite": {
"jobnr": "4"},
"init_testcase": {
"jobnr": "5" },
"execute_testcase": {
"jobnr": "6" },
"collect_testcase": {
"jobnr": "7" },
"compare_testcase": {
"jobnr": "8" },
"check_environment": {
"jobnr": "9" },
"test_executer": {
"jobnr": "10"},
}
JOB_LIST = [
"init_testsuite",
"execute_testsuite",
"collect_testsuite",
"compare_testsuite",
"finish_testsuite",
"init_testcase",
"execute_testcase",
"collect_testcase",
"compare_testcase",
"check_environment",
"test_executer"
]
appList = []
envList = ["ENV01"]
testList = {"TEST": [
"TC0001", "TST001"
]}
def readContext(job):
for k in job.conf.confs["applications"]:
appList.append(k)
def restartActualProcess(job):
"""
check if an actual process is open
:return:
"""
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG], JSON_FILE)
if os.path.exists(path):
actProc = utils.file_tool.readFileDict(path)
jobNr = int(JOB_NR[actProc["job"]]["jobnr"])
question = "Prozess "
choiceList = ""
if jobNr < 8 and jobNr != 4:
question += "F_ortsetzen | "
choiceList += "f | "
question += "W_iederholen | N_euen Prozess | X_exit"
choiceList = "w | n | x ?"
print("+-----------------------------------------------")
for k in actProc:
print('| {:6s} : {:60s}'.format(k, actProc[k]))
print("+-----------------------------------------------")
print(question)
choice = input("Auswahl "+choiceList)
choiceList.replace(" | ","")
if choice.lower() not in choiceList[:-1]:
print("FEHLER : falsche Auswahl")
elif choice.lower() == "x":
job.stopJob(0)
elif choice.lower() == "w":
startProcess(job, actProc)
elif choice.lower() == "f":
actProc["job"] = JOB_NR[int(jobNr)+1]
startProcess(job, actProc)
elif choice.lower() == "n":
createProcess(job)
else:
print("unbekannte Situation")
else:
createProcess(job)
def createProcess(job):
process = {}
index = 0
print("create new process")
process["app"] = getChoice(job, appList, "Anwendung")
#
if len(envList) == 1:
process["env"] = envList[0]
else:
process["env"] = getChoice(job, envList, "Umgebung")
#
process["tc"] = getChoice(job, testList[process["app"]], "Testfall")
print(str(process))
def getChoice(job, choiselist, description):
index = 0
print("+------------- "+description+" ----------")
print('| {:2d} : {:60s}'.format(0, "exit"))
for k in choiselist:
index += 1
print('| {:2d} : {:60s}'.format(index, k))
print("+-----------------------------------------------")
choice = input("Auswahl 1-" + str(index) + ": ")
if not choice.isnumeric():
print("FEHLER Fehleingabe "+choice)
getChoice(job, choiselist, description)
elif int(choice) < 1:
exit(0)
elif int(choice) > index:
print("FEHLER Fehleingabe "+choice)
getChoice(job, choiselist, description)
else:
return choiselist[int(choice) - 1]
def startProcess(job, process):
print(str(process))
if __name__ == '__main__':
job = basic.program.Job(PROGRAM_NAME)
readContext(job)
restartActualProcess(job)

29
test/constants.py

@ -1,4 +1,27 @@
HOME_PATH = "/home/ulrich/6_Projekte/Programme/datest"
DATA_PATH = "/home/ulrich/6_Projekte/Programme/data"
COMP_PATH = "/home/ulrich/6_Projekte/Programme/data/components"
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
"""
constants
"""
import os
home = os.getcwd()
prgdir = ""
if home[-4:] == "test" and home[-6:] != "datest":
home = home[0:-5]
if home[-10:] == "components":
home = home[0:-11]
if home[-6:] == "datest":
prgdir = home[-6:]
home = home[0:-7]
elif home[-7:] == "program":
prgdir = home[-7:]
home = home[0:-8]
HOME_PATH = home
DATA_PATH = os.path.join(home, "data")
PROG_PATH = os.path.join(home, prgdir)
COMP_PATH = os.path.join(home, prgdir, "components")
OS_SYSTEM = "linux"

49
test/test_date.py → test/test_01date.py

@ -4,71 +4,88 @@ import unittest
import datetime
import utils.date_tool
#TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"]
TEST_FUNCTIONS = ["test_parseFormula"]
TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"]
#TEST_FUNCTIONS = ["test_parseFormula"]
verbose = True
# class MyTestCase(unittest.TestCase):
class MyTestCase(unittest.TestCase):
TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"]
mymsg = "--------------------------------------------------------------"
"""
def runTest(self):
# -> Optional[unittest.result.TestResult]:
suite = unittest.TestSuite()
#suite.addTest(MyTestCase("test_dateformat"))
for t in TEST_FUNCTIONS:
suite.addTest(MyTestCase(t))
unittest.TextTestRunner().run(suite)
#suite = unittest.defaultTestLoader.loadTestsFromTestCase("MyTestCase")
if verbose: print("run own test " + str(suite))
"""
def test_dateformat(self):
def test_dateformat(self, result=None):
if verbose: print(str(result))
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if verbose: print("test_dateformat -------")
if actfunction not in TEST_FUNCTIONS:
return
stime = datetime.datetime.now()
print(stime)
if verbose: print(stime)
tdate = (2022, 2, 10)
sdate = datetime.datetime(tdate[0], tdate[1],tdate[2], 3, 32, 23)
sdate = datetime.datetime(stime)
print(sdate)
#sdate = datetime.datetime(stime)
if verbose: print(sdate)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parseFormula(self):
def test_parseFormula(self, result=None):
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
res = utils.date_tool.parseFormula("{(21.12.2012 +1Y)}")
print(str(res))
if verbose: print(str(res))
self.assertEqual(res[0], 2013)
self.assertEqual(res[3], 0)
res = utils.date_tool.parseFormula("{(21.12.2012 +1Y -1M)}")
print(str(res))
if verbose: print(str(res))
self.assertEqual(res[0], 2013)
self.assertEqual(res[1], 11)
self.assertEqual(res[3], 0)
res = utils.date_tool.parseFormula("{(21.12.2012 +1 Jahre +20 Tage)}")
print(str(res))
if verbose: print(str(res))
self.assertEqual(res[0], 2014)
self.assertEqual(res[1], 1)
self.assertEqual(res[2], 10)
self.assertEqual(res[3], 0)
res = utils.date_tool.parseFormula("{(21.12.2012_11:12:43 +1Y)}")
print(str(res))
if verbose: print(str(res))
self.assertEqual(res[0], 2013)
self.assertEqual(res[5], 43)
res = utils.date_tool.parseFormula("{(21.12.2012 -60M)}")
print(str(res))
if verbose: print(str(res))
self.assertEqual(res[0], 2007)
self.assertEqual(res[1], 12)
self.assertEqual(res[3], 0)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parseDate(self):
def test_parseDate(self, result=None):
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
res = utils.date_tool.parseDate("21.12.2012")
print(str(res))
if verbose: print(str(res))
self.assertEqual(res[0], 2012)
self.assertEqual(res[3], 0)
res = utils.date_tool.parseDate("{(21.12.2012 +1Y)}")
print(str(res))
self.assertEqual(res[0], 2012)
if verbose: print(str(res))
self.assertEqual(res[0], 2013)
self.assertEqual(res[3], 0)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

43
test/test_css.py → test/test_02css.py

@ -1,20 +1,30 @@
"""
unit-test
"""
import unittest
import utils.css_tool
import basic.program
import json
import test.testtools
# the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function
TEST_FUNCTIONS = ["test_01css"]
#TEST_FUNCTIONS = ["test_01css"]
# with this variable you can switch prints on and off
verbose = False
class MyTestCase(unittest.TestCase):
def runTest(self):
self.test_css()
def test_css(self):
job = basic.program.Job("unit")
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug",
def test_01css(self):
job = test.testtools.getJob()
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug",
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit",
"modus": "unit"}
job.par.setParameterArgs(args)
print("eeeeeeeee")
print(json.dumps(job.conf.confs))
if verbose: print("eeeeeeeee")
if verbose: print(json.dumps(job.conf.confs))
# ------- inline ---------------
job.conf.setConfig("tools.csstyp", "inline")
job.conf.confs.get("tools")["csstyp"] == "inline"
@ -40,38 +50,39 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(len(text), 15)
self.assertEqual(("class" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles")
print(text)
if verbose: print(text)
self.assertEqual(len(text), 262)
self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("resultFile")
print(text)
if verbose: print(text)
self.assertEqual(len(text), 283)
self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles,resultFile")
print(text)
if verbose: print(text)
self.assertEqual(len(text), 465)
self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles")
self.assertEqual(len(text), 0)
print(text)
print(str(len(text)))
if verbose: print(text)
if verbose: print(str(len(text)))
# ------- external ---------------
job.conf.setConfig("tools.csstyp", "external")
text = utils.css_tool.getInlineStyle("diffFiles", "diffA")
self.assertEqual(len(text), 13)
self.assertEqual(("class" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles")
print(text)
if verbose: print(text)
self.assertEqual(len(text), 55)
self.assertEqual(("<link " in text and "stylesheet" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles")
self.assertEqual(len(text), 216)
print(text)
print(str(len(text)))
if verbose: print(text)
if verbose: print(str(len(text)))
text = utils.css_tool.getExternalStyle("diffFiles,resultFile")
self.assertEqual(len(text), 449)
print(text)
print(str(len(text)))
if verbose: print(text)
if verbose: print(str(len(text)))
if __name__ == '__main__':
verbose = True
unittest.main()

12
test/test_path.py → test/test_03path.py

@ -16,6 +16,7 @@ OS_SYSTEM = test.constants.OS_SYSTEM
TEST_FUNCTIONS = ["test_key", "test_rejoinPath", "test_rejoinPath", "test_composePath", "test_composePattern",
"test_extractPath", "test_extractPattern"]
#TEST_FUNCTIONS = [ "test_extractPath"]
verbose = True
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
@ -44,9 +45,10 @@ class MyTestCase(unittest.TestCase):
res = utils.path_tool.getKeyValue("job.par."+B.PAR_ENV, None)
self.assertEqual(res, test.testtools.DEFAULT_ENV)
cnttest += 1
for par in [B.ATTR_PATH_TDATA, B.ATTR_PATH_ARCHIV, B.ATTR_PATH_ENV, B.ATTR_PATH_PROGRAM]:
for par in [B.ATTR_PATH_ARCHIV, B.ATTR_PATH_ENV]:
res = utils.path_tool.getKeyValue("job.conf."+par, None)
self.assertIn(HOME_PATH, res)
if verbose: print("assertIn "+par+": "+res+" -- "+DATA_PATH)
self.assertIn(DATA_PATH, res)
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -140,9 +142,7 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob()
pt = utils.path_tool.PathConf()
r = utils.path_tool.extractPath("tsbase" , os.path.join(DATA_PATH, "lauf", "testlauf", "startjob_2021-08-21_10-02-01"))
print("r " + str(r))
#print(vars(job.par))
#self.assertEqual(job.par.release, "V0.1")
if verbose: print("r " + str(r))
self.assertEqual(job.par.usecase, "startjob")
self.assertEqual(job.par.tstime, "2021-08-21_10-02-01")
cnttest += 2
@ -150,7 +150,7 @@ class MyTestCase(unittest.TestCase):
def test_zzz(self):
print(MyTestCase.mymsg)
if verbose: print(MyTestCase.mymsg)
if __name__ == '__main__':

9
test/test_config.py → test/test_04config.py

@ -3,12 +3,11 @@ import os
import inspect
import utils.config_tool
import utils.conn_tool
import test.constants
import test.constants as T
import test.testtools
import utils.path_const as P
import basic.constants as B
HOME_PATH = test.constants.HOME_PATH
TEST_FUNCTIONS = ["test_getConfig", "test_mergeAttributes"]
VERIFY = False
@ -22,9 +21,13 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
x = B.SUBJECT_APPS
r = utils.config_tool.getConfigPath(P.KEY_BASIC, x)
self.assertIn(os.path.join(T.COMP_PATH, B.SUBJECT_APPS), r)
cnttest += 1
x = "path"
r = utils.config_tool.getConfigPath(P.KEY_TOOL, x)
self.assertIn(os.path.join(HOME_PATH, P.VAL_UTIL, P.VAL_CONFIG), r)
self.assertIn(os.path.join(T.PROG_PATH, P.VAL_UTIL, P.VAL_CONFIG), r)
cnttest += 1
x = "conn"
r = utils.config_tool.getConfigPath(P.KEY_TOOL, x)

27
test/test_05conn.py

@ -0,0 +1,27 @@
import unittest
import basic.program
import utils.conn_tool
TEST_FUNCTIONS = ["test_01conn"]
#TEST_FUNCTIONS = ["test_01conn"]
verbose = True
class MyTestCase(unittest.TestCase):
def runTest(self):
self.test_conn()
def test_01conn(self):
if verbose: print("# # # # testComponents # # # # #")
job = basic.program.Job("unit")
args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug", "tool" : "job_tool"}
job.par.setParameterArgs(args)
self.assertEqual(True, True)
conn = utils.conn_tool.getConnection("testcm", 1)
if verbose: print("test-conn " + str(conn))
conns = utils.conn_tool.getConnections("testcrmdb")
if verbose: print("test-conn " + str(conns))
conns = utils.conn_tool.getConnections("testprd")
if verbose: print("test-conn " + str(conns))
if __name__ == '__main__':
unittest.main()

2
test/test_file.py → test/test_06file.py

@ -22,7 +22,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file_.*.py", None)
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file_t.*.py", None)
self.assertEqual(len(r), 1)
cnttest += 3
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file__.*.py", None)

12
test/test_catalog.py → test/test_07catalog.py

@ -13,14 +13,14 @@ HOME_PATH = test.constants.HOME_PATH
OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_key", "test_rejoinPath", "test_rejoinPath", "test_composePath", "test_composePattern",
"test_extractPath", "test_extractPattern"]
#TEST_FUNCTIONS = [ "test_extractPath"]
TEST_FUNCTIONS = ["test_01class", "test_02key"]
#TEST_FUNCTIONS = [ "test_02key"]
verbose = True
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_class(self):
def test_01class(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -32,7 +32,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_key(self):
def test_02key(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -43,7 +43,7 @@ class MyTestCase(unittest.TestCase):
def test_zzz(self):
print(MyTestCase.mymsg)
if verbose: print(MyTestCase.mymsg)
if __name__ == '__main__':

96
test/test_08i18n.py

@ -0,0 +1,96 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import unittest
import os
import inspect
import utils.path_tool
import basic.program
import basic.constants as B
import test.constants
import test.testtools
import utils.path_const as P
import utils.i18n_tool
import basic.constants as B
HOME_PATH = test.constants.HOME_PATH
OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_01class", "test_02text", "test_03aliasList"]
#TEST_FUNCTIONS = [ "test_03aliasList"]
verbose = False
EXP_KEY_MISSING = "key is missing {}"
EXP_KEY_DOESNT_EXIST = "key doesnt exist in domain {}"
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_01class(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
i18n = utils.i18n_tool.I18n.getInstance()
self.assertIsNotNone(i18n)
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_02text(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
job.conf.confs["language"] = "de"
i18n = utils.i18n_tool.I18n.getInstance()
res = i18n.getText(f"{EXP_KEY_MISSING=}", job)
if verbose: print("RESULT "+res)
self.assertEqual(res, "Schluesselwort fehlt {}")
cnttest += 1
res = i18n.getText(f"{EXP_KEY_DOESNT_EXIST=}", job)
if verbose: print("RESULT "+res)
self.assertEqual(res, "key doesnt exist in domain {}")
cnttest += 1
res = i18n.getText(f"{B.ATTR_APPS_PROJECT=}", job)
if verbose: print("RESULT "+res)
self.assertEqual(res, "project")
cnttest += 1
job.conf.confs["language"] = "fr"
i18n = utils.i18n_tool.I18n.getInstance()
self.assertRaises(Exception, i18n.getText, (f"{EXP_KEY_MISSING=}", job))
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_03aliasList(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
job.conf.confs["language"] = "de"
i18n = utils.i18n_tool.I18n.getInstance()
# i18n.getText("EXP_KEY_MISSING", EXP_KEY_MISSING, job)
res = i18n.getAliasList(f"{EXP_KEY_MISSING=}", job)
if verbose: print("RESULT "+str(res))
self.assertEqual(res, ['key is missing {}', 'Schluesselwort fehlt {}'])
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_zzz(self):
if verbose: print(MyTestCase.mymsg)
if __name__ == '__main__':
verbose = True
unittest.main()

0
test/test_component.py → test/test_11component.py

21
test/test_toolhandling.py → test/test_12toolhandling.py

@ -1,5 +1,5 @@
import unittest
import inspect
import basic.program
import basic.toolHandling
import test.constants
@ -8,12 +8,24 @@ import basic.constants as B
HOME_PATH = test.constants.HOME_PATH
conf = {}
# the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function
TEST_FUNCTIONS = ["test_01toolhandling"]
#TEST_FUNCTIONS = ["test_01toolhandling"]
# with this variable you can switch prints on and off
verbose = False
class MyTestCase(unittest.TestCase):
def runTest(self):
self.test_toolhandling()
def test_toolhandling(self):
def test_01toolhandling(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = basic.program.Job("unit")
args = {B.PAR_APP: "TEST", B.PAR_ENV: "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"modus": "unit"}
@ -40,11 +52,16 @@ class MyTestCase(unittest.TestCase):
self.assertRegex(str(type(tool)), 'dbmysql_tool.DbFcts')
tool = basic.toolHandling.getCliTool(comp)
self.assertRegex(str(type(tool)), 'clissh_tool.CliFcts')
comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_FILE] = {}
comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_FILE][B.ATTR_TYPE] = "xml"
tool = basic.toolHandling.getFileTool(job, comp)
self.assertRegex(str(type(tool)), 'filexml_tool.FileFcts')
comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_DB][B.ATTR_TYPE] = "dxx"
comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_CLI][B.ATTR_TYPE] = "sxx"
self.assertRaises(FileNotFoundError, basic.toolHandling.getDbTool, comp)
self.assertRaises(FileNotFoundError, basic.toolHandling.getCliTool, comp)
if __name__ == '__main__':
unittest.main()

21
test/test_tdata.py → test/test_21tdata.py

@ -16,16 +16,19 @@ 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_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key",
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv"]
# the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function
TEST_FUNCTIONS = ["test_01tdata", "test_02getCsvSpec_data", "test_03getCsvSpec_tree", "test_04getCsvSpec_key",
"test_05getCsvSpec_conf", "test_06parseCsv"]
# TEST_FUNCTIONS = ["test_getCsvSpec_data"]
# with this variable you can switch prints on and off
verbose = False
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_tdata(self):
def test_01tdata(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -44,7 +47,7 @@ class MyTestCase(unittest.TestCase):
#self.assertEqual(("steps" in tdata), True)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_data(self):
def test_02getCsvSpec_data(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -172,7 +175,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_tree(self):
def test_03getCsvSpec_tree(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -187,7 +190,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_key(self):
def test_04getCsvSpec_key(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -251,7 +254,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_conf(self):
def test_05getCsvSpec_conf(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -282,7 +285,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parseCsv(self):
def test_06parseCsv(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0

106
test/test_compare.py → test/test_22compare.py

@ -1,6 +1,6 @@
import json
import unittest
import inspect
import basic
from basic.program import Job
import basic.constants as B
@ -8,6 +8,15 @@ import utils.data_const as D
import utils.match_tool
import utils.match_const as M
import basic.component
import test.testtools
# the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function
TEST_FUNCTIONS = ["test_01matchstart", "test_02hitmanage", "test_03similarity", "test_04bestfit",
"test_11compareRow", "test_12compareRows", "test_21match"]
# TEST_FUNCTIONS = ["test_getCsvSpec_data"]
# with this variable you can switch prints on and off
verbose = False
tdata = {
M.MATCH_SIDE_POSTEXPECT: {
@ -90,8 +99,13 @@ class MyTestCase(unittest.TestCase):
#self.test_compareRows()
#self.test_match()
def test_matchstart(self):
job = Job("unit")
def test_01matchstart(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001")
comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
@ -101,7 +115,12 @@ class MyTestCase(unittest.TestCase):
matching.setData(tdata, M.MATCH_SUCCESS)
print(matching.htmltext)
def test_hitmanage(self):
def test_02hitmanage(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component"
@ -117,15 +136,25 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(matching.isHitB("b0005"), True, "doesnt exist")
self.assertEqual(("b0005" in matching.linksB), True, "doesnt exist")
def test_similarity(self):
def test_03similarity(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
matching = self.getMatching()
utils.match_tool.setMatchkeys(matching, ":database:scheme:table:_data")
utils.match_tool.getSimilarity(matching,
tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0],
tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0], 1)
def test_bestfit(self):
job = Job("unit")
def test_04bestfit(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001")
comp = basic.component.Component()
comp.name = "component"
@ -144,8 +173,13 @@ class MyTestCase(unittest.TestCase):
print(json.dumps(matching.linksB))
print(json.dumps(matching.nomatch))
def test_compareRow(self):
job = Job("unit")
def test_11compareRow(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001")
comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
@ -165,8 +199,13 @@ class MyTestCase(unittest.TestCase):
tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][i])
print(text)
def test_compareRows(self):
job = Job("unit")
def test_12compareRows(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
comp = basic.component.Component()
comp.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"}
comp.name = "component"
@ -182,28 +221,33 @@ class MyTestCase(unittest.TestCase):
text = utils.match_tool.compareRows(matching, ":database:scheme:table:_data")
print(text)
def test_match(self):
job = Job("unit")
setattr(job.par, B.PAR_TESTCASE, "TC0001")
setattr(job.par, "tctime", "2022-03-25_19-25-31")
comp = basic.component.Component()
comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component"
cm = basic.componentHandling.ComponentManager()
cm.comps["component"] = comp
# tdata["postReq"] = tdata["preAct"]
comp.conf = conf
matching = utils.match_tool.Matching(comp)
matching.htmltext = ""
matching.setData(tdata, M.MATCH_POSTCOND)
text = utils.match_tool.matchTree(matching)
print("\n-------------\n")
print(text)
print("\n-------------\n")
print(matching.difftext)
def test_21match(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001")
setattr(job.par, "tctime", "2022-03-25_19-25-32")
comp = basic.component.Component()
comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component"
cm = basic.componentHandling.ComponentManager()
cm.comps["component"] = comp
# tdata["postReq"] = tdata["preAct"]
comp.conf = conf
matching = utils.match_tool.Matching(comp)
matching.htmltext = ""
matching.setData(tdata, M.MATCH_POSTCOND)
text = utils.match_tool.matchTree(matching)
print("\n-------------\n")
print(text)
print("\n-------------\n")
print(matching.difftext)
def getMatching(self):
job = Job("unit")
job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001")
setattr(job.par, "tctime", "2022-03-25_19-25-31")
comp = basic.component.Component()

0
test/test_report.py → test/test_22report.py

17
test/test_db.py → test/test_31db.py

@ -1,3 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import unittest
import inspect
import basic.program
@ -14,8 +20,9 @@ HOME_PATH = test.constants.HOME_PATH
conf = {}
# here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_parseSql", "test_toolhandling", "test_formatDbRows"]
#TEST_FUNCTIONS = ["test_formatDbRows"]
# "test_toolhandling", "test_parseSql" -> test of components
TEST_FUNCTIONS = ["test_formatDbRows"]
# TEST_FUNCTIONS = ["test_getTechnicalIDFields"]
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
@ -28,10 +35,6 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"modus": "unit"}
job.par.setParameterArgs(args)
# "SELECT * FROM lofts"
obj = utils.db_abstract.parseConditions("family like !%utz%! and state = !+reg+!")
self.assertEqual(obj[0][3], "and")
self.assertEqual(obj[0][1], "family")
@ -59,7 +62,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = basic.program.Job("unit")
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"modus": "unit"}
job.par.setParameterArgs(args)
#t = basic.toolHandling.ToolManager()

78
test/test_job.py → test/test_71job.py

@ -1,19 +1,24 @@
import unittest
import os
import inspect
import shutil
import utils.path_tool
from basic.program import Job
from basic.componentHandling import ComponentManager
import basic.step
import init_testcase
import test_executer
import test.constants
import basic.constants as B
import test.constants as T
import basic.componentHandling
import utils.file_tool
HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key",
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv"]
TEST_FUNCTIONS = ["test_run"]
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv", "test_smokeTestcase"]
TEST_FUNCTIONS = ["test_smokeTestcase"]
class MyTestCase(unittest.TestCase):
@ -76,5 +81,74 @@ class MyTestCase(unittest.TestCase):
#test_executer.start(job)
job.stopJob(1)
def test_smokeTestcase(self):
"""
the functions starts a test-roundtrip with dry unit-tests
1. simulate the test-object - copy results from testdata_preconditions into local env-directory
2. init_testcase - databases as csv in local env-directory
3. simulate the test-object - copy results from testdata_postconditions into local env-directory
4. execute_testcase - send=copy to local env-directory
- receive=read from local env-directory
5. collect_testcase - read from local env-directory
6. compare_testcase -
:return:
"""
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
# basic parameter
programs = ["copy_precondition", "init_testcase", "copy_postcondition", "execute_testcase",
"collect_testcase", "compare_testcase"]
programs = ["copy_precondition", "execute_testcase"]
testcase = "TC0001"
timexec = "2022-07-18_21-23-34"
fct = "read_TData"
if "init_testcase" in programs:
program = "init_testcase"
job = Job("unit")
args = {B.PAR_APP: "TESTAPP", B.PAR_ENV: "ENV01", "modus": "unit",
B.PAR_TCDIR: os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 1}
job.par.setParameterArgs(args)
job.setProgram(program)
if "copy_precondition" in programs:
copyAppData(job, program, "tdpreexec")
pass
job.startJob()
init_testcase.startPyJob(job)
job.stopJob(1)
if "execute_testcase" in programs:
program = "execute_testcase"
step = basic.step.Step()
step.start = "execute_testcase"
job = Job("unit")
args = {B.PAR_APP: "TESTAPP", B.PAR_ENV: "ENV01", "modus": "unit",
B.PAR_TCDIR: os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 2}
test_executer.startStepProgram(step, job, args)
print("fertig")
def copyAppData(job, program, tdsource):
cm = basic.componentHandling.ComponentManager.getInstance("init")
print("cm " + str(cm))
cm.initComponents()
comps = cm.getComponents(program)
for c in comps:
comp = cm.getComponent(c)
tdatapath = utils.path_tool.composePattern("{"+tdsource+"}", comp)
envapppath = utils.path_tool.composePattern("{envappdir}", comp)
if os.path.exists(tdatapath):
files = utils.file_tool.getFiles(job.m, tdatapath, ".+\.csv", None)
for f in files:
# shutil.copy()
print("cp " + os.path.join(tdatapath, f) + " " + os.path.join(envapppath, f))
utils.file_tool.mkPaths(os.path.join(envapppath, f), job.m)
shutil.copy(os.path.join(tdatapath, f), os.path.join(envapppath, f))
print(tdatapath)
if __name__ == '__main__':
unittest.main()

23
test/test_conn.py

@ -1,23 +0,0 @@
import unittest
import basic.program
import utils.conn_tool
class MyTestCase(unittest.TestCase):
def runTest(self):
self.test_conn()
def test_conn(self):
print("# # # # tetsComponents # # # # #")
job = basic.program.Job("unit")
args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug", "tool" : "job_tool"}
job.par.setParameterArgs(args)
self.assertEqual(True, True)
conn = utils.conn_tool.getConnection("testb", 1)
print("test-conn " + str(conn))
conns = utils.conn_tool.getConnections("testb")
print("test-conn " + str(conns))
conns = utils.conn_tool.getConnections("testa")
print("test-conn " + str(conns))
if __name__ == '__main__':
unittest.main()

2
test/test_xml.py

@ -6,7 +6,7 @@ import utils.xml1_tool
class MyTestCase(unittest.TestCase):
def xtest_xmlTool(self):
#job = basic.program.Job("unit")
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug",
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug",
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit",
"modus": "unit"}
beispiel_json = {'root': {'@attr': 'xyz', '$': 'inhalt', "b": "bold"}}

4
test/testtools.py

@ -47,7 +47,7 @@ conf = {
def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
job = basic.program.Job.popInstance()
if not job is None:
job.stopJob()
job.stopJob(1)
if len(pgran) < 1:
gran = DEFAULT_GRAN
else:
@ -73,7 +73,7 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
elif gran == "ts":
path = DEFAULT_ARCHIV_DIR + "/testlauf/TST001_" + tstamp
job = basic.program.Job("unit")
job.conf.confs[B.SUBJECT_PATH]["components"] = T.COMP_PATH
#job.conf.confs[B.SUBJECT_PATH]["components"] = T.COMP_PATH
args = {"application": app, "environment": env, "modus": mode, gran+"time": tstamp,
gran+"dir": path,
"step": 2}

49
unit_run.py

@ -1,7 +1,9 @@
#
#
# ----------------------------------------------------------
"""
This program is created for the business-test on the level of unit testing. On this level there is an intensive test-set up to a carthesian product possible.
This program is created for the business-test on the level of unit testing.
On this level there is an intensive test-set up to a carthesian product possible.
The test-specification is written in a yaml-config in the data-directory.
workflow:
1. generate test-cases with all inputs into a csv-file of the spec-yaml
@ -10,15 +12,19 @@ workflow:
OR instead 2 and 3 on test-first-strategy:
3. create manually the target-result with your inputs and the target system-outputs
4. run and compare the actual-result with the target-result
5. at the end you get an xls-sheet like your result-csv-file but additionally with comparsion-result as detailed result and the only counts of passed and failed tests as minimum-result which can be inserted into management-tools
5. at the end you get an xls-sheet like your result-csv-file
but additionally with comparsion-result as detailed result and the only counts of passed and failed tests
as minimum-result which can be inserted into management-tools
"""
# Press the green button in the gutter to run the script.
import importlib
import unittest
import test.constants
import os, glob
import io
import sys
import test.constants as T
HOME_PATH = test.constants.HOME_PATH
VERIFY = False
class MyTestLoader(unittest.TestLoader):
@ -26,29 +32,30 @@ class MyTestLoader(unittest.TestLoader):
pass
def create_test_suite():
testFileStrings = glob.glob(os.path.join(HOME_PATH, "test", 'test_*.py'))
print(testFileStrings)
suite = unittest.TestSuite()
for t in testFileStrings:
v = "test."+t[len(HOME_PATH)+6:-3]
#v = v.replace("\/", '.')
#v = v.replace("\\", '.')
cmodul = importlib.import_module(v)
class_ = getattr(cmodul, "MyTestCase")
suite.addTest(class_())
#module_strings = [str for str in test_file_strings]
#mod = __import__(os.path.join(HOME_PATH, "test", 'test_css.py'), globals(), locals(), ['suite'])
#suitefn = getattr(mod, 'MyTestCase')
#suite.addTest(suitefn())
# suites = ["test.test_css.MyTestCase()"]
# testSuite = unittest.TestSuite(suites)
for testdir in [T.PROG_PATH, T.COMP_PATH]:
print("testdir "+testdir)
testFileStrings = sorted(glob.glob(os.path.join(testdir, "test", 'test_*.py')))
print("testdir "+str(testFileStrings))
for t in testFileStrings:
print("t "+t)
if not t[len(testdir)+11:len(testdir)+13].isnumeric():
continue
if testdir == T.COMP_PATH:
v = "components.test." + t[len(testdir) + 6:-3]
else:
v = "test."+t[len(testdir)+6:-3]
cmodul = importlib.import_module(v)
class_ = getattr(cmodul, "MyTestCase")
c = class_()
for f in cmodul.TEST_FUNCTIONS:
setattr(c, "verbose", False)
suite.addTest(class_(f))
return suite
if __name__ == '__main__':
# loader = MyTestLoader()
print ("start")
loader = unittest.TestLoader()
suite = create_test_suite()
#loader.discover(os.path.join(HOME_PATH, "test"), 'test_.*py')
runner = unittest.TextTestRunner(verbosity=2)
runner = unittest.TextTestRunner(sys.stdout, True, 3, True, True)
runner.run(suite)

13
utils/config_tool.py

@ -44,6 +44,12 @@ def getConfigPath(modul, name, subname=""):
job.debug(verify, "getConfig " + modul + ", " + name)
#TODO path rejoin, config as const
if modul == P.KEY_TOOL:
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS),
P.KEY_TOOL+"_"+name+"."+format)
job.debug(verify, "1 " + pathname)
if os.path.exists(pathname):
return pathname
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_HOME),
P.VAL_CONFIG, P.KEY_TOOL+"_"+name+"."+format)
@ -93,6 +99,13 @@ def getConfigPath(modul, name, subname=""):
if os.path.exists(pathname):
return pathname
raise Exception(P.EXP_CONFIG_MISSING, modul+", "+name)
elif modul == P.KEY_BASIC:
for format in CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS),
name + "."+format)
job.debug(verify, "4 " + pathname)
if os.path.exists(pathname):
return pathname
else:
pathname = utils.path_tool.composePath(P.P_TCPARFILE)
job.debug(verify, "7 " + pathname)

12
utils/db_abstract.py

@ -65,7 +65,6 @@ def getDbAttributes(comp, table):
B.ATTR_DB_CONN_JAR: D.DEFAULT_DB_CONN_JAR
}
for attr in out.keys():
print(attr)
if (table in comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) \
and (attr in comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][table]):
out[attr] = comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][table][attr]
@ -180,10 +179,17 @@ def getTechnicalIDFields(ddl):
if "T" in ddl[f][D.DDL_KEY]:
keys[ddl[f][D.DDL_KEY]] = f
for k in keys:
ids.append(k)
return ids
ids.append(keys[k])
return ids
def isConditionInFields(cond, ddl):
a = cond.split(" ")
for x in a:
if x in ddl:
return True
return False
def formatDbRows(table, comp, rows):
out = []
fields = comp.conf[B.DATA_NODE_DDL][table]

102
utils/dbrel_tool.py

@ -0,0 +1,102 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import basic.program
import utils.config_tool
import utils.db_abstract
import mysql.connector
import basic.constants as B
class DbFcts(utils.db_abstract.DbFcts):
"""
This interface defines each necessary connection to any kind of database.
The specific technique how to connect to the concrete DBMS has to be implemented in the specific tool.
"""
def __init__(self):
pass
def selectRows(self, table):
""" method to select rows from a database
statement written in sql """
tdata = {}
job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel("db_tool")
cmd = "SELECT * FROM "+table+";"
#mycursor = self.getConnector()
#mycursor.execute(cmd)
#myresult = mycursor.fetchall()
tdata[B.DATA_NODE_HEADER] = []
for f in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]:
tdata[B.DATA_NODE_HEADER].append(f)
myresult = []
for x in myresult:
print(x)
self.comp.m.logInfo(cmd)
return tdata
def deleteRows(self, table):
""" method to delete rows from a database
statement written in sql """
job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel("db_tool")
cmd = "DELETE FROM "+table+";"
self.comp.m.logInfo(cmd)
def updateRows(self, statement):
""" method to delete rows from a database
statement written in sql """
raise Exception(B.EXCEPT_NOT_IMPLEMENT)
def insertRows(self, table, rows):
""" method to insert rows into a database
the rows will be interpreted by the ddl of the component
"""
job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel("db_tool")
cmd = "INSERT INTO "+table+";"
header = ""
for h in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]:
print(h)
header += ", "+h
cmd += " (" + header[1:]+" ) "
rowvalues = ""
for r in rows:
print("r-----------------")
print(r)
rowvalues = ""
cmd += "\n ( "
for h in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]:
print("h "+h)
if (h in r):
rowvalues += ", "+self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_DATA][h], r[h])
else:
rowvalues += ", "+self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_DATA][h], "")
print("rv " + rowvalues)
cmd += rowvalues[1:]+" ),"
cmd = cmd[0:-1]+";"
self.comp.m.logInfo(cmd)
def getConnector(self):
""" add-on-method to get the connector
this method should only called by the class itself """
job = basic.program.Job.getInstance()
mydb = mysql.connector.connect(
host = "localhost",
user = "datest",
password = "Advent!2021",
database = "datest"
)
return mysql
@staticmethod
def execStatement(self, comp, conn, statement):
""" add-on-method to execute the statement
this method should only called by the class itself """
raise Exception(B.EXCEPT_NOT_IMPLEMENT)

87
utils/file_abstract.py

@ -4,12 +4,26 @@
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import os
import basic.program
import basic.catalog
import utils.config_tool
import basic.constants as B
import basic.toolHandling
import utils.data_const as D
import utils.date_tool
import utils.file_tool
import utils.path_tool
"""
# TODO Beschreibung file-tools
* fileXml_tool
* fileJson_tool
* fileYaml_tool
* fileCsv_tool
* fileHtml_tool
...
"""
class FileFcts():
"""
@ -18,6 +32,9 @@ class FileFcts():
def __init__(self):
pass
def setComp(self, job, comp=None):
self.job = job
self.comp = comp
def parseText(self, text):
"""
@ -28,4 +45,70 @@ class FileFcts():
def file2dict(self):
pass
pass
# Funktionen
#=== init_testcase ===
def removeFiles(self):
utils.file_tool.removeFiles(self.comp.m, "envpath", "pattern", self.comp.conf["conn"])
def copyFiles(self):
fileList = []
srcpath = ""
envpath = ""
pattern = ""
utils.file_tool.copyFiles(self.job, fileList, srcpath, envpath, pattern)
def readEnvFiles(self):
envpath = ""
pattern = ""
fileList = utils.file_tool.getFiles(self.comp.m, envpath, pattern, self.comp.conf["conn"])
# === execute_testcase ===
def create_request(self, tdata, step):
mapping = ""
schema = ""
archivpath = ""
filename = step.args["filename"]
txt = ""
for o in self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_FILE]:
if o["name"] != filename:
continue
mapping = o["mapping"]
schema = o["schema"]
archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/request", self.comp), filename) # ergebnisse/comp/request )
#txt = self.createDict()
utils.file_tool.writeFileText(self.comp.m, archivpath, txt)
def send_request(self, step):
archivpath = ""
filename = step.args["filename"]
technique = step.args["technique"]
archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/request", self.comp), filename)
if technique == "cli":
for o in self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_FILE]:
if o["name"] != filename:
continue
envpath = o["envpath"]
envpath = utils.path_tool.composePattern(envpath, self.comp)
fct = basic.toolHandling.getCliTool(self.comp)
fct.copy(self.job, archivpath, envpath)
elif technique == "api":
txt = utils.file_tool.readFileText(archivpath, self.comp.m)
fct = basic.toolHandling.getApiTool(self.comp)
response = fct.send(self.job, self.comp, txt)
archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/response", self.comp), filename)
"""
get_response:
- channel (sync/async)
... implement
- archivpath ( ergebnisse/comp/response )
- envpath ( ./log) / envconn ( = in Request empfangen )
=== collect_testcase ===
- envpath
- pattern
> readfiles
"""

26
utils/file_tool.py

@ -50,6 +50,32 @@ def getFiles(msg, path, pattern, conn):
return out
def removeFiles(msg, path, pattern, conn):
"""
search filenames in the directory and removes it
- if conn is set search remote
:param msg: -- msg-Objekt
:param path: -- path - String
:param pattern: -- filename as Pattern
:param conn:
:return: Array filenames
"""
pass
def copyFiles(job, fileList, source, target, comp):
"""
copies files from source to target
:param job:
:param fileList:
:param source:
:param target:
:param comp:
:return:
"""
pass
def getRemoteFiles(msg, path, pattern, conn):
"""
search filenames in the directory - if conn is set search remote

95
utils/i18n_tool.py

@ -0,0 +1,95 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import utils.config_tool
import utils.path_const as P
import basic.program
DEFAULT_LANGUAGE = "en"
EXP_KEY_MISSING = "key is missing {}"
EXP_KEY_DOESNT_EXIST = "key doesnt exist in domain {}"
class I18n:
__instance = None
cache = {}
"""
in this class there should be managed each defined key-value-pairs
the pairs ara loaded from the path testdata/catalog:
* initially the csv-file catalog.csv
* on demand other csv-files in the path
"""
def __init__(self):
self.cache = {}
self.cache = utils.config_tool.getConfig(P.KEY_TOOL, "i18n")
I18n.__instance = self
pass
@staticmethod
def getInstance():
if I18n.__instance == None:
return I18n()
return I18n.__instance
def getText(self, key, job=None):
"""
this function gets the text depending on language which is set in job.conf
:param domain:
:param key:
:return:
if not (isinstance(langue, str) and len(langue)):
raise Exception(EXP_KEY_MISSING, (domain, key))
if not (isinstance(key, str) and len(key)):
raise Exception(EXP_KEY_MISSING, (langue, key))
return self.cache[langue][key]
"""
if job is None:
jon = basic.program.Job.getInstance()
language = job.conf.confs["language"]
if language not in self.cache:
raise Exception(EXP_KEY_MISSING, (key))
print(key)
out = self.extractText(key)
key = self.extractKey(key)
if key in self.cache[language]:
out = self.cache[language][key]
elif key in self.cache[DEFAULT_LANGUAGE]:
out = self.cache[DEFAULT_LANGUAGE][key]
return out
def getAliasList(self, key, job=None):
if job is None:
jon = basic.program.Job.getInstance()
out = []
key = self.extractKey(key)
for language in self.cache:
out.append(self.cache[language][key])
return out
def extractKey(self, key):
if "=" in key:
i = key.find("=")
x = key[0:i]
if "." in x:
i = x.find(".")
y = x[i + 1:]
else:
y = x
key = y
print("= in key " + y)
else:
print("!= in key")
y = key
return key
def extractText(self, key):
if "=" in key:
i = key.find("=")
return key[i + 2:-1]
return ""

2
utils/path_const.py

@ -13,6 +13,8 @@ KEY_TESTCASE = "tc"
KEY_TESTSUITE = "ts"
KEY_DEBUGNAME = "debugname"
KEY_LOGNAME = "logname"
KEY_BASIC = "basic"
""" keyword for basic config in components """
KEY_COMP = "comp"
""" keyword for individual component """
KEY_TOOL = "tool"

Loading…
Cancel
Save