Browse Source

refactor: job not anymore as singleton, in order to run multiple jobs

master
Ulrich Carmesin 2 years ago
parent
commit
6c6d2db1b1
  1. 2
      .gitignore
  2. 4
      basic/catalog.py
  3. 85
      basic/compexec.py
  4. 50
      basic/component.py
  5. 45
      basic/componentHandling.py
  6. 4
      basic/constants.py
  7. 2
      basic/message.py
  8. 205
      basic/program.py
  9. 2
      basic/sysmonitor.py
  10. 6
      basic/toolHandling.py
  11. 2
      check_environment.py
  12. 4
      collect_testcase.py
  13. 10
      compare_testcase.py
  14. 4
      execute_testcase.py
  15. 8
      finish_testsuite.py
  16. 2
      generate_testcases.py
  17. 10
      init_testcase.py
  18. 4
      init_testsuite.py
  19. 2
      start_dialog.py
  20. 32
      test/test_02css.py
  21. 6
      test/test_03path.py
  22. 14
      test/test_04config.py
  23. 8
      test/test_05conn.py
  24. 22
      test/test_06file.py
  25. 8
      test/test_11component.py
  26. 2
      test/test_12toolhandling.py
  27. 38
      test/test_21tdata.py
  28. 19
      test/test_22compare.py
  29. 2
      test/test_22report.py
  30. 18
      test/test_25map.py
  31. 13
      test/test_31db.py
  32. 6
      test/test_32file.py
  33. 33
      test/test_71job.py
  34. 66
      test/test_xml.py
  35. 14
      test/testtools.py
  36. 28
      test_executer.py
  37. 3
      utils/api_abstract.py
  38. 5
      utils/config/path.yml
  39. 14
      utils/config_tool.py
  40. 12
      utils/conn_tool.py
  41. 12
      utils/css_tool.py
  42. 5
      utils/db_abstract.py
  43. 14
      utils/dbcsv_tool.py
  44. 4
      utils/dbmysql_tool.py
  45. 2
      utils/dbrel_tool.py
  46. 8
      utils/dbsfile_tool.py
  47. 8
      utils/dbshive_tool.py
  48. 6
      utils/dbspark_tool.py
  49. 30
      utils/env_tool.py
  50. 18
      utils/file_abstract.py
  51. 56
      utils/file_tool.py
  52. 5
      utils/flask_tool.py
  53. 10
      utils/i18n_tool.py
  54. 6
      utils/job_tool.py
  55. 53
      utils/match_tool.py
  56. 59
      utils/path_tool.py
  57. 29
      utils/report_tool.py
  58. 44
      utils/tdata_tool.py
  59. 757
      utils/xml1_tool.py
  60. 5
      utils/zip_tool.py

2
.gitignore

@ -11,5 +11,5 @@ instance
doc doc
venv venv
lib lib
reste

4
basic/catalog.py

@ -94,9 +94,9 @@ class Catalog:
if pathname is None: if pathname is None:
raise Exception(EXP_KEY_MISSING, (domain)) raise Exception(EXP_KEY_MISSING, (domain))
if pathname[-4:] == ".csv": if pathname[-4:] == ".csv":
data = utils.tdata_tool.getCsvSpec(job.m, pathname, D.CSV_SPECTYPE_KEYS) data = utils.tdata_tool.getCsvSpec(job.m, job, pathname, D.CSV_SPECTYPE_KEYS)
else: else:
data = utils.file_tool.readFileDict(pathname, job.m) data = utils.file_tool.readFileDict(job, pathname, job.m)
self.catalog[domain] = data[B.DATA_NODE_TABLES][domain][B.DATA_NODE_KEYS] self.catalog[domain] = data[B.DATA_NODE_TABLES][domain][B.DATA_NODE_KEYS]
return data return data

85
basic/compexec.py

@ -51,10 +51,10 @@ import utils.tdata_tool
import basic.constants as B import basic.constants as B
import basic.text_const as T import basic.text_const as T
import utils.data_const as D import utils.data_const as D
import utils.path_const as P
class Testexecuter(): class Testexecuter():
def prepare_system(self, granularity): def prepare_system(self, job, granularity):
""" """
In order to preparate the test system test data should be cleaned and loaded with actual data. In order to preparate the test system test data should be cleaned and loaded with actual data.
This can happen on different granularities: for each testcase or for each test sequences or for a test set or This can happen on different granularities: for each testcase or for each test sequences or for a test set or
@ -62,7 +62,7 @@ class Testexecuter():
The loaded test data should be selected for a later comparison. The loaded test data should be selected for a later comparison.
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel(self.name) verify = -1+job.getDebugLevel(self.name)
self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper())
self.reset_TData(granularity) self.reset_TData(granularity)
@ -70,14 +70,14 @@ class Testexecuter():
self.m.logInfo("--- " + 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.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper())
pass pass
def reset_TData(self, granularity): def reset_TData(self, job, granularity):
""" """
the testdata in the component of the testsystem will be resetted the testdata in the component of the testsystem will be resetted
correponding with the configuration of the componend correponding with the configuration of the componend
:param granularity: :param granularity:
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel(self.name) verify = -1+job.getDebugLevel(self.name)
self.m.debug(verify, "--- "+str(inspect.currentframe().f_code.co_name)+"() started at " self.m.debug(verify, "--- "+str(inspect.currentframe().f_code.co_name)+"() started at "
+ datetime.now().strftime("%Y%m%d_%H%M%S")+" for " + str(self.name).upper()) + datetime.now().strftime("%Y%m%d_%H%M%S")+" for " + str(self.name).upper())
@ -96,7 +96,7 @@ class Testexecuter():
self.m.setMsg("resetInstance for " + self.name + " is OK") self.m.setMsg("resetInstance 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 load_TData(self, granularity, tdata): def load_TData(self, job, granularity, tdata):
""" """
the testdata will be loaded into the componend especially into databses the testdata will be loaded into the componend especially into databses
or with import-functions of the component or with import-functions of the component
@ -104,7 +104,7 @@ class Testexecuter():
:param testdata: :param testdata:
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel(self.name) verify = -1+job.getDebugLevel(self.name)
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started 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) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper())
for node in [B.TOPIC_NODE_DB, B.TOPIC_NODE_CLI, B.TOPIC_NODE_FILE, B.TOPIC_NODE_API]: for node in [B.TOPIC_NODE_DB, B.TOPIC_NODE_CLI, B.TOPIC_NODE_FILE, B.TOPIC_NODE_API]:
@ -112,7 +112,7 @@ class Testexecuter():
if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS] and B.DATA_NODE_TABLES in tdata: if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS] and B.DATA_NODE_TABLES in tdata:
for t in tdata[B.DATA_NODE_TABLES]: for t in tdata[B.DATA_NODE_TABLES]:
print (t) print (t)
if utils.db_abstract.isCompTable(self, tdata, t): if utils.db_abstract.isCompTable(self, job, tdata, t):
self.m.logInfo("insert content "+ self.name) self.m.logInfo("insert content "+ self.name)
dbi = basic.toolHandling.getDbTool(job, self) dbi = basic.toolHandling.getDbTool(job, self)
dbi.insertTables(tdata, job) dbi.insertTables(tdata, job)
@ -120,23 +120,23 @@ 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 collect_TcArtifacts(self): def collect_TcArtifacts(self, job):
""" """
collects the artifacts from the test-system. collects the artifacts from the test-system.
the result is written as original in subfolder {tsorigin} the result is written as original in subfolder {tsorigin}
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel(self.name) verify = -1+job.getDebugLevel(self.name)
self.read_TData("nachher", B.PAR_TESTCASE) self.read_TData(job, utils.path_tool.getKeyValue(P.KEY_PRECOND), B.PAR_TESTCASE)
def read_TData(self, subdir, granularity): def read_TData(self, job, subdir, granularity):
""" """
:param granularity: :param granularity:
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel(self.name) verify = -1+job.getDebugLevel(self.name)
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started 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) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper())
if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS]: if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS]:
@ -149,7 +149,7 @@ class Testexecuter():
data[B.DATA_NODE_TABLES] = {} data[B.DATA_NODE_TABLES] = {}
data[B.DATA_NODE_TABLES][t] = data[subdir][t] data[B.DATA_NODE_TABLES][t] = data[subdir][t]
utils.tdata_tool.writeCsvData( utils.tdata_tool.writeCsvData(
utils.path_tool.rejoinPath(utils.path_tool.composePattern("{tcresult}", self), subdir, t+".csv"), utils.path_tool.rejoinPath(utils.path_tool.composePattern(job, "{tcresult}", self), subdir, t+".csv"),
data, self, job) data, self, job)
if B.ATTR_ARTS_LOB in self.conf[B.SUBJECT_ARTS]: if B.ATTR_ARTS_LOB in self.conf[B.SUBJECT_ARTS]:
self.m.logInfo("check lob if is deleted with flaskdb "+ self.name) self.m.logInfo("check lob if is deleted with flaskdb "+ self.name)
@ -157,10 +157,10 @@ class Testexecuter():
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 composeFileClauses(self, pattern): def composeFileClauses(self, job, pattern):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
out = {} out = {}
attr = utils.db_abstract.getDbAttributes(self, "null") attr = utils.db_abstract.getDbAttributes(self, job, "null")
while "{" in pattern: while "{" in pattern:
pre = pattern[0:pattern.index("{")] pre = pattern[0:pattern.index("{")]
pat = pattern[pattern.index("{"):pattern.index("}")] pat = pattern[pattern.index("{"):pattern.index("}")]
@ -194,15 +194,15 @@ class Testexecuter():
return out return out
return out return out
def composeSqlClauses(self, sql): def composeSqlClauses(self, job, sql):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
out = {} out = {}
print("-------- composeSqlClauses "+sql) print("-------- composeSqlClauses "+sql)
table = sql[sql.upper().index(" FROM ")+6:].strip() table = sql[sql.upper().index(" FROM ")+6:].strip()
print("table "+table) print("table "+table)
sql_new = sql[0:sql.upper().index(" FROM ")+5] sql_new = sql[0:sql.upper().index(" FROM ")+5]
print("sql_new "+sql_new) print("sql_new "+sql_new)
attr = utils.db_abstract.getDbAttributes(self, table) attr = utils.db_abstract.getDbAttributes(self, job, table)
if attr[B.ATTR_DB_TABNAME] != "": if attr[B.ATTR_DB_TABNAME] != "":
table = attr[B.ATTR_DB_TABNAME] table = attr[B.ATTR_DB_TABNAME]
if attr[B.ATTR_DB_SCHEMA] != "": if attr[B.ATTR_DB_SCHEMA] != "":
@ -232,17 +232,17 @@ class Testexecuter():
print("---> out "+str(out)) print("---> out "+str(out))
return out return out
def test_System(self, granularity): def test_System(self, job, granularity):
""" """
:param granularity: :param granularity:
:return: :return:
""" """
def create_Request(self, granularity): def create_Request(self, job, granularity):
pass pass
def send_Request(self, granularity): def send_Request(self, job, granularity):
pass pass
def get_Response(self, granularity): def get_Response(self, job, granularity):
pass pass
def execute_test(self, job, step, tdata): def execute_test(self, job, step, tdata):
@ -271,19 +271,19 @@ class Testexecuter():
print("nichts da") print("nichts da")
def finish_Test(self, granularity): def finish_Test(self, job, granularity):
""" """
initialization-routine for finish-step initialization-routine for finish-step
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel(self.name) verify = -1+job.getDebugLevel(self.name)
self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper())
self.m.logInfo("something in "+ self.name) self.m.logInfo("something in "+ self.name)
self.m.setMsg("checkInstance for " + self.name + " is OK") self.m.setMsg("checkInstance for " + self.name + " is OK")
self.m.logInfo("--- " + 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.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper())
def collect_system(self, granularity): def collect_system(self, job, granularity):
""" """
After the test the test data of each component should be selected again - to get the post-condition. After the test the test data of each component should be selected again - to get the post-condition.
In each component is configured how these data can be collected. In each component is configured how these data can be collected.
@ -292,14 +292,14 @@ class Testexecuter():
""" """
pass pass
def collect_TcArtifact(self, granularity): def collect_TcArtifact(self, job, granularity):
""" """
collects the artifacts from the test-system. collects the artifacts from the test-system.
the result is written as original in subfolder {tcorigin} the result is written as original in subfolder {tcorigin}
post: a further contact zo the test-system is not necessary post: a further contact zo the test-system is not necessary
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
if B.ATTR_ARTS_LOG in self.conf[B.SUBJECT_ARTS]: if B.ATTR_ARTS_LOG in self.conf[B.SUBJECT_ARTS]:
self.m.logInfo("get files in for "+ self.name + " in " + self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_LOG]["path"]) self.m.logInfo("get files in for "+ self.name + " in " + self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_LOG]["path"])
@ -312,13 +312,13 @@ class Testexecuter():
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name))
def split_TcResult(self, granularity): def split_TcResult(self, job, granularity):
""" """
transforms the result from subfolder {tcorigin}. transforms the result from subfolder {tcorigin}.
the result is written as utf-8-readable parts in subfolder {tcparts} the result is written as utf-8-readable parts in subfolder {tcparts}
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
self.m.debug(verify, "--- "+str(inspect.currentframe().f_code.co_name)+"() "+str(self.name)) self.m.debug(verify, "--- "+str(inspect.currentframe().f_code.co_name)+"() "+str(self.name))
if B.ATTR_ARTS_LOG in self.conf[B.SUBJECT_ARTS]: if B.ATTR_ARTS_LOG in self.conf[B.SUBJECT_ARTS]:
@ -330,18 +330,18 @@ class Testexecuter():
if B.ATTR_ARTS_FILE in self.conf[B.SUBJECT_ARTS]: if B.ATTR_ARTS_FILE in self.conf[B.SUBJECT_ARTS]:
self.m.logInfo("tidy files in for "+self.name+" in "+self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_FILE]["format"]) self.m.logInfo("tidy files in for "+self.name+" in "+self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_FILE]["format"])
def fix_TcResult(self, granularity): def fix_TcResult(self, job, granularity):
""" """
fixes the result which is collected and transformed from the test-system. fixes the result which is collected and transformed from the test-system.
the result is written in comparable form in folder {tcresult} the result is written in comparable form in folder {tcresult}
with the identifiable name - like in target with the identifiable name - like in target
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name))
def compare_results(self, report): def compare_results(self, job, report):
""" """
to compare the actual result with the target result has three steps: to compare the actual result with the target result has three steps:
1 matching each element so you get a comparable pair 1 matching each element so you get a comparable pair
@ -349,11 +349,11 @@ class Testexecuter():
3 rating the difference if this can be accepted 3 rating the difference if this can be accepted
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
cm = basic.componentHandling.ComponentManager.getInstance() cm = basic.componentHandling.ComponentManager.getInstance()
data = {} data = {}
matching = utils.match_tool.Matching() matching = utils.match_tool.Matching(job, self)
if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS]: if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS]:
for t in self.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB]: for t in self.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB]:
if t in B.LIST_DB_ATTR: if t in B.LIST_DB_ATTR:
@ -367,17 +367,18 @@ class Testexecuter():
comp = cm.getComponent(a[0]) comp = cm.getComponent(a[0])
else: else:
comp = self comp = self
path = os.path.join(utils.path_tool.composePattern( path = os.path.join(utils.path_tool.composePattern(job,
"{"+M.MATCH[M.MATCH_SIDE_POSTACTUAL][M.M_FILEPATTERN]+"}", comp), a[1]+".csv") "{"+M.MATCH[M.MATCH_SIDE_POSTACTUAL][M.M_FILEPATTERN]+"}", comp), a[1]+".csv")
pass pass
elif side == M.MATCH_SIDE_TESTCASE: elif side == M.MATCH_SIDE_TESTCASE:
if hasattr(job.par, "testcase_example"): if hasattr(job.par, "testcase_example"):
path = os.path.join(utils.path_tool.composePattern( path = os.path.join(utils.path_tool.composePattern(job,
"{"+M.MATCH[M.MATCH_SIDE_POSTEXPECT][M.M_FILEPATTERN]+"}", self), t+".csv") "{"+M.MATCH[M.MATCH_SIDE_POSTEXPECT][M.M_FILEPATTERN]+"}", self), t+".csv")
path.replace(getattr(job.par, B.PAR_TESTCASE), getattr(job.par, "testcase_example")) path.replace(getattr(job.par, B.PAR_TESTCASE), getattr(job.par, "testcase_example"))
else: else:
path = os.path.join(utils.path_tool.composePattern("{" + M.MATCH[side][M.M_FILEPATTERN] + "}", self), t + ".csv") path = os.path.join(utils.path_tool.composePattern(job,
filedata = utils.tdata_tool.readCsv(self.m, path, self) "{" + M.MATCH[side][M.M_FILEPATTERN] + "}", self), t + ".csv")
filedata = utils.tdata_tool.readCsv(self.m, job, path, self)
data[side] = M.MATCH[side] data[side] = M.MATCH[side]
data[side]["path"] = path data[side]["path"] = path
data[side]["data"] = filedata data[side]["data"] = filedata
@ -387,9 +388,9 @@ class Testexecuter():
report.setPaths(job.par.testcase, self.name, t, type, matching.matchfiles["A"], matching.matchfiles["B"]) report.setPaths(job.par.testcase, self.name, t, type, matching.matchfiles["A"], matching.matchfiles["B"])
text = utils.match_tool.matchTree(matching) text = utils.match_tool.matchTree(matching)
report.setMatchResult(job.par.testcase, self.name, t, type, matching.cssClass, matching.diffText) report.setMatchResult(job.par.testcase, self.name, t, type, matching.cssClass, matching.diffText)
path = os.path.join(utils.path_tool.composePattern("{tcresult}", self), path = os.path.join(utils.path_tool.composePattern(job, "{tcresult}", self),
t+"_"+M.MATCH[type]["filename"]+".html") t+"_"+M.MATCH[type]["filename"]+".html")
utils.file_tool.writeFileText(self.m, path, text) utils.file_tool.writeFileText(self.m, job, path, text)
# write text # write text
pass pass
pass pass

50
basic/component.py

@ -11,6 +11,7 @@ from datetime import datetime
import basic.compexec import basic.compexec
import basic.message import basic.message
import basic.program import basic.program
import basic.constants as B
import inspect import inspect
@ -31,7 +32,7 @@ class Component(basic.compexec.Testexecuter):
During a test-run the component must be checked, prepared, appfiles has to be collected, etc. For this doing there are some standard-methods implemented. During a test-run the component must be checked, prepared, appfiles has to be collected, etc. For this doing there are some standard-methods implemented.
""" """
def init(self): def init(self, job):
""" """
The range of the test-system is defined by the dependancy graph which starts at the application.and indate each component. The range of the test-system is defined by the dependancy graph which starts at the application.and indate each component.
By this way it is possible to use the same component in different test-systems and so the By this way it is possible to use the same component in different test-systems and so the
@ -41,52 +42,52 @@ class Component(basic.compexec.Testexecuter):
it is controlled by their configuration it is controlled by their configuration
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name))
def run(self): def run(self, job):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
if job.program == "check_environment": if job.program == "check_environment":
self.check_Instance() self.check_Instance()
elif job.program == "init_testset": elif job.program == "init_testset":
self.prepare_system("testset") self.prepare_system(job, B.PAR_TESTSUITE)
elif job.program == "init_testcase": elif job.program == "init_testcase":
self.prepare_system(B.PAR_TESTCASE) self.prepare_system(job, B.PAR_TESTCASE)
elif job.program == "test_system": elif job.program == "test_system":
self.test_System("test") self.test_System(job, "test")
elif job.program == "test_system": elif job.program == "test_system":
self.test_System("test") self.test_System(job, "test")
elif job.program == "finish_testcase": elif job.program == "finish_testcase":
self.finish_Test("test") self.finish_Test(job, B.PAR_TESTCASE)
elif job.program == "finish_testset": elif job.program == "finish_testset":
self.finish_Test("test") self.finish_Test(job, B.PAR_TESTSUITE)
def collect_TcResult(self): def collect_TcResult(self, job):
""" """
collects the result from the folder {tcresult}. collects the result from the folder {tcresult}.
the content is stored intern for comparison the content is stored intern for comparison
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
self.m.logInfo("get files in for " + self.name + " in tcresult ") self.m.logInfo("get files in for " + self.name + " in tcresult ")
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name))
def collect_Expect(self): def collect_Expect(self, job):
""" """
pre: only for components which be collected at the end of the test-set pre: only for components which be collected at the end of the test-set
collects the result from the folder {rsresult}. collects the result from the folder {rsresult}.
post: a further contact zo the test-system is not necessary post: a further contact zo the test-system is not necessary
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name))
def compare_TcResults(self): def compare_TcResults(self, job):
""" """
compares the result with the target compares the result with the target
(1) the elements of both sides are assigned (1) the elements of both sides are assigned
@ -96,7 +97,7 @@ class Component(basic.compexec.Testexecuter):
(5) the summary result is returned (5) the summary result is returned
:return: :return:
""" """
job = basic.program.Job.getInstance() # job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name))
@ -111,6 +112,7 @@ class Component(basic.compexec.Testexecuter):
:param tg: :param tg:
:return: :return:
""" """
pass
def report_TcResults(self): def report_TcResults(self):
""" """
reports the result-code reports the result-code
@ -128,25 +130,25 @@ class Component(basic.compexec.Testexecuter):
:return: :return:
""" """
pass pass
def split_TsResult(self): def split_TsResult(self, job):
""" """
transforms the result which is collected from the test-system. transforms the result which is collected from the test-system.
the result is written as utf-8-readable parts in the specific subfolder {tcparts} the result is written as utf-8-readable parts in the specific subfolder {tcparts}
the relevant testcases will be called the relevant testcases will be called
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name))
# for tc in testcases: # for tc in testcases:
# self.fix_TcResult(self) # self.fix_TcResult(self)
def compare_TsResults(self): def compare_TsResults(self, job):
""" """
controles the comparison the result with the target controles the comparison the result with the target
:return: :return:
""" """
job = basic.program.Job.getInstance() # job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name))
# for tc in testcases: # for tc in testcases:
@ -154,14 +156,14 @@ class Component(basic.compexec.Testexecuter):
# self.collect_Target # self.collect_Target
# self.compare_TcResults # self.compare_TcResults
def report_TsResults(self): def report_TsResults(self, job):
""" """
(1.2) extraction of diff-files (only not accepted differences) as html-file in test-set - result-report - (1.2) extraction of diff-files (only not accepted differences) as html-file in test-set - result-report -
(2.3) visualization of final result-code of each component and each testcase in test-set - result-report - (2.3) visualization of final result-code of each component and each testcase in test-set - result-report -
(2.4) visualization of statistical result-codes of each component and each test-set in test-context - result-report - (2.4) visualization of statistical result-codes of each component and each test-set in test-context - result-report -
:return: :return:
""" """
job = basic.program.Job.getInstance() # job = basic.program.Job.getInstance()
verify = job.getDebugLevel(self.name) verify = job.getDebugLevel(self.name)
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name))
reportheader = '<head>' reportheader = '<head>'
@ -199,8 +201,8 @@ class Component(basic.compexec.Testexecuter):
""" """
pass pass
def declare_Target(self): def declare_Target(self, job):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = -1+job.getDebugLevel(self.name) verify = -1+job.getDebugLevel(self.name)
self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper())
self.m.logInfo("something in "+ self.name) self.m.logInfo("something in "+ self.name)

45
basic/componentHandling.py

@ -48,8 +48,8 @@ def getInstanceAttributes(conf):
return out return out
def getComponents(mainfct): def getComponents(job, mainfct):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = -2 + job.getDebugLevel("job_tool") verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents " + mainfct) job.debug(verify, "getComponents " + mainfct)
out = [] out = []
@ -67,11 +67,12 @@ class ComponentManager:
initializes the Manager with all necessary components initializes the Manager with all necessary components
""" """
def __init__(self): def __init__(self, job, option=""):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
job.m.logDebug("applicationscomponente -- " + str(type(job.par))) job.m.logDebug("applicationscomponente -- " + str(type(job.par)))
self.components = {} self.components = {}
self.comps = {} self.comps = {}
self.job = job
ComponentManager.__instance = self ComponentManager.__instance = self
print ("init ComponentHandling "+str(self)) print ("init ComponentHandling "+str(self))
@ -79,7 +80,7 @@ class ComponentManager:
def initComponents(self): def initComponents(self):
# sets components the first time # sets components the first time
# afterwards set components from parameter-file # afterwards set components from parameter-file
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
anw = job.par.application anw = job.par.application
job.m.logDebug("applicationscomponente -- " + str(type(job.par))) job.m.logDebug("applicationscomponente -- " + str(type(job.par)))
if not job.conf.confs[B.SUBJECT_APPS].get(anw): if not job.conf.confs[B.SUBJECT_APPS].get(anw):
@ -93,14 +94,8 @@ class ComponentManager:
self.createComponent(k, 0, "") self.createComponent(k, 0, "")
def setComponents(self):
# set components from parameter-file
job = basic.program.Job.getInstance()
job.m.logDebug("applicationscomponente -- " + str(type(job.par)))
def getComponent(self, compobjname): def getComponent(self, compobjname):
job = basic.program.Job.getInstance() job = self.job #basic.program.Job.getInstance()
verify = -2 + job.getDebugLevel("job_tool") verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents " + compobjname) job.debug(verify, "getComponents " + compobjname)
if compobjname in self.comps: if compobjname in self.comps:
@ -109,7 +104,7 @@ class ComponentManager:
def getComponents(self, mainfct): def getComponents(self, mainfct):
job = basic.program.Job.getInstance() job = self.job #basic.program.Job.getInstance()
verify = -2 + job.getDebugLevel("job_tool") verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents " + mainfct) job.debug(verify, "getComponents " + mainfct)
out = [] out = []
@ -142,12 +137,12 @@ class ComponentManager:
:param suffix: suffix for specific context of the component :param suffix: suffix for specific context of the component
:return: :return:
""" """
job = basic.program.Job.getInstance() job = self.job #basic.program.Job.getInstance()
verify = job.getDebugLevel("job_tool") verify = job.getDebugLevel("job_tool")
componentName = componentName.lower() componentName = componentName.lower()
job.debug(verify, "createComponent " + componentName) job.debug(verify, "createComponent " + componentName)
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig(job, "comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(job, componentName)
instAttr = getInstanceAttributes(confs) instAttr = getInstanceAttributes(confs)
job.debug(verify, "createComponent -91- " + componentName + " : " + str(confs)) job.debug(verify, "createComponent -91- " + componentName + " : " + str(confs))
if nr > 0 and int(instAttr[B.ATTR_INST_CNT]) > 1: if nr > 0 and int(instAttr[B.ATTR_INST_CNT]) > 1:
@ -181,7 +176,7 @@ class ComponentManager:
:param nr: number if component is multiple :param nr: number if component is multiple
:return: instance of the component with all necessary attributes :return: instance of the component with all necessary attributes
""" """
job = basic.program.Job.getInstance() job = self.job #basic.program.Job.getInstance()
cmodul = importlib.import_module(getComponentPath(compName)) cmodul = importlib.import_module(getComponentPath(compName))
class_ = getattr(cmodul, getComponentClass(compName)) class_ = getattr(cmodul, getComponentClass(compName))
c = class_() c = class_()
@ -197,7 +192,7 @@ class ComponentManager:
c.m = basic.message.Message(job, 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 = utils.config_tool.mergeConn(c.m, confs["conf"], conns[i])
c.conf[B.SUBJECT_CONN] = conns[i] c.conf[B.SUBJECT_CONN] = conns[i]
c.init() c.init(job)
if parContent is not None: if parContent is not None:
print("createComponent 5 a " + compName + " : " + str(parContent)) print("createComponent 5 a " + compName + " : " + str(parContent))
if B.SUBJECT_COMPS in parContent and compName in parContent[B.SUBJECT_COMPS]: if B.SUBJECT_COMPS in parContent and compName in parContent[B.SUBJECT_COMPS]:
@ -209,7 +204,7 @@ class ComponentManager:
for table in c.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB]: for table in c.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB]:
if table in B.LIST_DB_ATTR: if table in B.LIST_DB_ATTR:
continue continue
conf = utils.config_tool.getConfig(D.DDL_FILENAME, compName, table) conf = utils.config_tool.getConfig(job, D.DDL_FILENAME, compName, table)
if B.DATA_NODE_TABLES in conf and table in conf[B.DATA_NODE_TABLES]: if B.DATA_NODE_TABLES in conf and table in conf[B.DATA_NODE_TABLES]:
c.conf[B.DATA_NODE_DDL][table] = conf[B.DATA_NODE_TABLES][table] c.conf[B.DATA_NODE_DDL][table] = conf[B.DATA_NODE_TABLES][table]
elif table in conf: elif table in conf:
@ -222,7 +217,7 @@ class ComponentManager:
def createSubComponents(self, comp, nr, suffix): def createSubComponents(self, comp, nr, suffix):
job = basic.program.Job.getInstance() job = self.job #basic.program.Job.getInstance()
verify = -2 + job.getDebugLevel("job_tool") verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents " + str(comp.conf[B.ATTR_INST_SUBCOMP])) job.debug(verify, "getComponents " + str(comp.conf[B.ATTR_INST_SUBCOMP]))
for c in comp.conf[B.ATTR_INST_SUBCOMP].keys(): for c in comp.conf[B.ATTR_INST_SUBCOMP].keys():
@ -232,7 +227,7 @@ class ComponentManager:
def getComponentDict(self): def getComponentDict(self):
job = basic.program.Job.getInstance() job = self.job #basic.program.Job.getInstance()
verify = -2 + job.getDebugLevel("job_tool") verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents ") job.debug(verify, "getComponents ")
out = {} out = {}
@ -260,10 +255,10 @@ def getComponentPath(comp):
return "components." + getComponentFolder(comp) + "." + getComponentModul(comp) return "components." + getComponentFolder(comp) + "." + getComponentModul(comp)
def getComponentDict(): def getComponentDict(job = None):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = -2 + job.getDebugLevel("job_tool") #verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents ") #job.debug(verify, "getComponents ")
out = {} out = {}
for c in comps: for c in comps:
out[comps[c].name] = {} out[comps[c].name] = {}

4
basic/constants.py

@ -22,7 +22,7 @@ The constants desribes the keywords of the main datastructures, these are
# ------------------------------------------------------------- # -------------------------------------------------------------
# values and keywords # values and keywords
BASIS_FILE = "basis.yml" BASIS_FILE = "basis"
SVAL_YES = "y" SVAL_YES = "y"
SVAL_NO = "n" SVAL_NO = "n"
@ -42,6 +42,8 @@ PAR_TCDIR = 'tcdir'
""" definition of the directory of the testcase for logs and results """ """ definition of the directory of the testcase for logs and results """
PAR_XPDIR = 'xpdir' PAR_XPDIR = 'xpdir'
""" definition of the directory of expectation for comparing the testcase """ """ definition of the directory of expectation for comparing the testcase """
PAR_WSDIR = "wsdir"
""" definition of the directory of the workspace """
PAR_TDTYP = 'tdtyp' PAR_TDTYP = 'tdtyp'
PAR_TDSRC = 'tdsrc' PAR_TDSRC = 'tdsrc'
PAR_TDNAME = 'tdname' PAR_TDNAME = 'tdname'

2
basic/message.py

@ -149,7 +149,7 @@ class Message:
self.debugfile.close() self.debugfile.close()
def setRc(self, rc, text): def setRc(self, rc, text):
job = basic.program.Job.getInstance() job = self.job #basic.program.Job.getInstance()
verify = -0+LIMIT_DEBUG verify = -0+LIMIT_DEBUG
self.debug(verify, "setRc " + str(rc) + " " + str(self.rc)+ "\n") self.debug(verify, "setRc " + str(rc) + " " + str(self.rc)+ "\n")
if (int(rc) > self.rc): if (int(rc) > self.rc):

205
basic/program.py

@ -20,9 +20,17 @@ import utils.date_tool
import utils.path_tool import utils.path_tool
import utils.file_tool import utils.file_tool
import utils.config_tool import utils.config_tool
import test.constants as T
jobdef = { jobdef = {
"webflask": {
"pardef": "",
"pfilesource": "",
"pfiletarget": "",
"basedir": "workbase",
"dirname": "workdir",
"logdir": "{job.par.debugs}/webflask/log_{time}.txt" },
"unit": { "unit": {
"pardef": "", "pardef": "",
"pfilesource": "", "pfilesource": "",
@ -108,6 +116,72 @@ def setGlobal():
EXCP_CANT_POP = "cant pop this job from the instances" EXCP_CANT_POP = "cant pop this job from the instances"
DEFAULT_ARCHIV_DIR = T.DATA_PATH + "/lauf"
DEFAULT_GRAN = "ws"
DEFAULT_PRG = "webflask"
DEFAULT_GRAN = "ws"
DEFAULT_APP = "WEBFLASK"
DEFAULT_ENV = "Workspace"
DEFAULT_MODE = "test"
DEFAULT_TIME = "2022-08-29_17-29-59"
def createJob(pprg="", pgran="", papp="", penv="", ptstamp="", pmode=""):
"""
this creates a Job-Object with the main arguments.
:param pprg: program-name
:param pgran: tc|ts|
:param papp: application
:param penv: environment
:param ptstamp: timestamp - part of specific testfolder
:param pmode: if it is a productive or development execution
:return:
"""
if len(pprg) < 1:
prgname = DEFAULT_PRG
else:
prgname = pprg
if len(pgran) < 1:
gran = DEFAULT_GRAN
else:
gran = pgran
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_ARCHIV_DIR + "/TC0001/" + tstamp
elif gran == "ts":
path = DEFAULT_ARCHIV_DIR + "/testlauf/TST001_" + tstamp
else:
path = T.DATA_PATH + "/workspace/"
job = basic.program.Job(prgname)
# job.conf.confs[B.SUBJECT_PATH]["components"] = T.COMP_PATH
args = {"application": app, "environment": env, "modus": mode, gran + "time": tstamp,
gran + "dir": path,
"step": 1}
print(str(args))
# "usecase": "TST001", "tstime": "2022-03-17_17-28"}
job.par.setParameterArgs(job, args)
return job
class Job: class Job:
__instance = None __instance = None
__instances = [] __instances = []
@ -118,13 +192,13 @@ class Job:
Job.__instance = self Job.__instance = self
if Job.__instances is None: if Job.__instances is None:
Job.__instances = [] Job.__instances = []
Job.pushInstance(self) #Job.pushInstance(self)
par = Parameter(program) par = Parameter(self, program)
self.par = par self.par = par
print("prog-42 " + str(self.par.basedir)) print("prog-42 " + str(self.par.basedir))
conf = Configuration(program) conf = Configuration(self, program)
self.conf = conf self.conf = conf
appl = utils.config_tool.getConfig("basic", B.SUBJECT_APPS) appl = utils.config_tool.getConfig(self, "basic", B.SUBJECT_APPS)
print(appl) print(appl)
if appl is not None: if appl is not None:
self.conf.confs[B.SUBJECT_APPS] = appl[B.SUBJECT_APPS] self.conf.confs[B.SUBJECT_APPS] = appl[B.SUBJECT_APPS]
@ -139,59 +213,6 @@ class Job:
self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None) self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None)
print("prog-50 " + str(self.par.basedir)) print("prog-50 " + str(self.par.basedir))
@staticmethod
def popInstance(pjob=None):
""" pop and stop a subjob """
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:
Job.__instance = None
return None
if Job.__instance is None:
while len(Job.__instances) > 0:
Job.__instances.pop()
return None
if len(Job.__instances) == 1:
job = Job.__instance
job.stopJob(1)
Job.__instances.pop()
Job.__instance = None
return None
job = Job.__instances.pop()
if pjob is not None and job is not None and job != pjob:
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)
Job.__instance = topjob
else:
Job.__instance = None
return job
@staticmethod
def pushInstance(pjob):
""" push a new created subjob """
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.__instance = pjob
return pjob
@staticmethod
def resetInstance(program):
job = Job.getInstance()
if job is not None:
job.stopJob(1)
Job.__instance = None
Job(program)
return Job.__instance
def setProgram(self, program): def setProgram(self, program):
self.program = program self.program = program
@ -206,15 +227,8 @@ class Job:
setattr(self.par, "parstring", parstring) setattr(self.par, "parstring", parstring)
if not hasattr(self.par, jobdef[program]["dirname"]): if not hasattr(self.par, jobdef[program]["dirname"]):
setattr(self.par, jobdef[program]["dirname"], setattr(self.par, jobdef[program]["dirname"],
utils.path_tool.composePattern("{"+basedir+"}", None)) utils.path_tool.composePattern(self, "{"+basedir+"}", None))
self.par.setParameterLoaded() self.par.setParameterLoaded(self)
@staticmethod
def getInstance():
if (Job.__instance is not None):
return Job.__instance
else:
return None
def startJob(self): def startJob(self):
@ -223,10 +237,10 @@ class Job:
logTime = self.start.strftime("%Y%m%d_%H%M%S") logTime = self.start.strftime("%Y%m%d_%H%M%S")
self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None) self.m = basic.message.Message(self, basic.message.LIMIT_DEBUG, logTime, None)
print("prog-68 " + str(self.m.rc)) print("prog-68 " + str(self.m.rc))
self.par.setParameterLoaded() self.par.setParameterLoaded(self)
self.m.logInfo("# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ") self.m.logInfo("# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ")
self.m.debug(basic.message.LIMIT_INFO, "# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ") self.m.debug(basic.message.LIMIT_INFO, "# # # Start Job " + self.start.strftime("%d.%m.%Y %H:%M:%S") + " # # # ")
self.par.checkParameter() self.par.checkParameter(self)
def stopJob(self, reboot=0): def stopJob(self, reboot=0):
@ -250,7 +264,7 @@ class Job:
cconf = basic.componentHandling.getComponentDict() cconf = basic.componentHandling.getComponentDict()
output["par"] = self.par.__dict__ output["par"] = self.par.__dict__
if len(cconf) < 1: if len(cconf) < 1:
utils.file_tool.writeFileDict(self.m, parpath, output) utils.file_tool.writeFileDict(self.m, self, parpath, output)
return return
output[B.SUBJECT_COMPS] = {} output[B.SUBJECT_COMPS] = {}
for c in cconf: for c in cconf:
@ -261,7 +275,7 @@ class Job:
output[B.SUBJECT_COMPS][c][x] = cconf[c][x] output[B.SUBJECT_COMPS][c][x] = cconf[c][x]
if x == B.SUBJECT_CONN and "passwd" in cconf[c][x]: if x == B.SUBJECT_CONN and "passwd" in cconf[c][x]:
cconf[B.SUBJECT_COMPS][c][x]["passwd"] = "xxxxx" cconf[B.SUBJECT_COMPS][c][x]["passwd"] = "xxxxx"
utils.file_tool.writeFileDict(self.m, parpath, output) utils.file_tool.writeFileDict(self.m, self, parpath, output)
def loadParameter(self): def loadParameter(self):
@ -271,7 +285,7 @@ class Job:
parpath = utils.path_tool.composePath(jobdef[self.program]["pfilesource"], None) parpath = utils.path_tool.composePath(jobdef[self.program]["pfilesource"], None)
if not os.path.join(parpath): if not os.path.join(parpath):
return None return None
doc = utils.file_tool.readFileDict(parpath, self.m) doc = utils.file_tool.readFileDict(self, 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
@ -349,13 +363,13 @@ class Job:
# ------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------
class Parameter: class Parameter:
print ("class Parameter") print ("class Parameter")
def __init__ (self, program): def __init__ (self, job, program):
print ("# init Parameter for " + program) print ("# init Parameter for " + program)
self.program = program self.program = program
self.basedir = "debugs" self.basedir = "debugs"
self.setBasedir(program) self.setBasedir(program)
print (f"# Parameter initialisiert {self.program} mit basedir {self.basedir}") print (f"# Parameter initialisiert {self.program} mit basedir {self.basedir}")
if (program != "unit"): self.setParameter() if (program not in ["unit", "webflask"] ): self.setParameter(job)
def setBasedir(self, program): def setBasedir(self, program):
@ -363,15 +377,18 @@ class Parameter:
self.basedir = jobdef[program]["basedir"] self.basedir = jobdef[program]["basedir"]
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 self.basedir == "workbase":
home = utils.path_tool.getHome()
dirpath = os.path.join(home, "data", "workspace")
setattr(self, jobdef[program]["dirname"], dirpath)
elif program != "unit": elif program != "unit":
dirpath = utils.path_tool.composePattern("{"+jobdef[program]["basedir"]+"}", None) dirpath = utils.path_tool.composePattern(None, "{"+jobdef[program]["basedir"]+"}", None)
setattr(self, jobdef[program]["dirname"], dirpath) setattr(self, jobdef[program]["dirname"], dirpath)
else: else:
self.basedir = "debugs" self.basedir = "debugs"
def checkParameter(self): def checkParameter(self, job):
job = Job.getInstance()
print (f"Parameter initialisiert {self.program}") print (f"Parameter initialisiert {self.program}")
pardef = jobdef[job.program]["pardef"] pardef = jobdef[job.program]["pardef"]
for p in pardef.split(","): for p in pardef.split(","):
@ -379,7 +396,7 @@ class Parameter:
if len(p) > 1 and not hasattr(self, p): if len(p) > 1 and not hasattr(self, p):
job.m.setFatal("Parameter " + p + " is not set!") job.m.setFatal("Parameter " + p + " is not set!")
def setParameter(self): def setParameter(self, job):
""" """
1. Programm -- implementiert in Main-Klasse 1. Programm -- implementiert in Main-Klasse
2. anwndung -- steuert zu pruefende System [ in basis_Config ] 2. anwndung -- steuert zu pruefende System [ in basis_Config ]
@ -406,6 +423,7 @@ class Parameter:
parser.add_argument('-r', '--release', action='store') parser.add_argument('-r', '--release', action='store')
parser.add_argument('-ts', '--'+B.PAR_TSDIR, action='store') parser.add_argument('-ts', '--'+B.PAR_TSDIR, action='store')
parser.add_argument('-tc', '--'+B.PAR_TCDIR, action='store') parser.add_argument('-tc', '--'+B.PAR_TCDIR, action='store')
parser.add_argument('-ws', '--'+B.PAR_WSDIR, action='store')
parser.add_argument('-rs', '--rsdir', action='store') parser.add_argument('-rs', '--rsdir', action='store')
parser.add_argument('-dt', '--tdtyp', action='store') # PAR_TDTYP parser.add_argument('-dt', '--tdtyp', action='store') # PAR_TDTYP
parser.add_argument('-ds', '--tdsrc', action='store') # PAR_TDSRC parser.add_argument('-ds', '--tdsrc', action='store') # PAR_TDSRC
@ -419,7 +437,7 @@ class Parameter:
# parser.add_argument('-t', '--typ', default='einzel', action='store') # parser.add_argument('-t', '--typ', default='einzel', action='store')
# parser.add_argument('-d', '--dir', action='store') # parser.add_argument('-d', '--dir', action='store')
args = parser.parse_args() args = parser.parse_args()
self.setParameterArgs(args) self.setParameterArgs(job, args)
def getDirParameter(self): def getDirParameter(self):
@ -430,8 +448,7 @@ class Parameter:
return None return None
def setParameterArgs(self, args): def setParameterArgs(self, job, args):
job = Job.getInstance()
print("setParArgs " + str(type(args))) print("setParArgs " + str(type(args)))
self.parstring = "python " + self.program self.parstring = "python " + self.program
if "dict" in str(type(args)): if "dict" in str(type(args)):
@ -452,8 +469,8 @@ class Parameter:
app2 = self.application app2 = self.application
def setParameterLoaded(self): def setParameterLoaded(self, job):
job = Job.getInstance() #job = Job.getInstance()
print("setParLoaded " ) print("setParLoaded " )
readedPar = job.loadParameter() readedPar = job.loadParameter()
if readedPar is not None: if readedPar is not None:
@ -476,29 +493,17 @@ class Parameter:
# ------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------
class Configuration: class Configuration:
def __init__ (self, program): def __init__ (self, job, program):
self.program = program self.program = program
print (f"job initialisiert {self.program}") print (f"job initialisiert {self.program}")
if program == "unit": path = utils.path_tool.getBasisConfigPath()
if (os.path.exists(utils.path_tool.rejoinPath("..", "..", "config", B.BASIS_FILE))): self.setConfiguration(job, path)
self.setConfiguration(utils.path_tool.rejoinPath("..", "..", "config", B.BASIS_FILE))
return
if (os.path.exists(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))):
self.setConfiguration(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))
return
elif (os.path.exists(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))):
self.setConfiguration(utils.path_tool.rejoinPath("..", "config", B.BASIS_FILE))
return
elif (os.path.exists(utils.path_tool.rejoinPath("config", B.BASIS_FILE))):
self.setConfiguration(utils.path_tool.rejoinPath("config", B.BASIS_FILE))
return return
raise Exception(B.EXP_NO_BASIS_FILE)
def setConfiguration(self, path): def setConfiguration(self, job, path):
self.confs = {} self.confs = {}
doc = utils.file_tool.readFileLines(path, None) doc = utils.file_tool.readFileDict(job, path, None)
with open(path, "r") as file: self.confs["configpath"] = path
doc = yaml.full_load(file)
if "basic" in doc: if "basic" in doc:
for i, v in doc["basic"].items(): for i, v in doc["basic"].items():
self.confs[i] = v self.confs[i] = v

2
basic/sysmonitor.py

@ -18,7 +18,7 @@ class SystemMonitor():
""" """
checks system-instances and writes it into the parameter-file checks system-instances and writes it into the parameter-file
""" """
job = basic.program.Job.getInstance() job = None #basic.program.Job.getInstance()
verify = -1 + job.getDebugLevel(self.name) verify = -1 + job.getDebugLevel(self.name)
self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime( self.m.logInfo("--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime(
"%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) "%Y%m%d_%H%M%S") + " for " + str(self.name).upper())

6
basic/toolHandling.py

@ -72,7 +72,7 @@ def getDbTool(job, comp, dbtype=""):
cmodul = importlib.import_module("utils."+toolname) cmodul = importlib.import_module("utils."+toolname)
class_ = getattr(cmodul, "DbFcts") class_ = getattr(cmodul, "DbFcts")
c = class_() c = class_()
c.setComp(comp) c.setComp(job, comp)
return c return c
def getCliTool(job, comp): def getCliTool(job, comp):
@ -86,7 +86,7 @@ def getCliTool(job, comp):
cmodul = importlib.import_module("utils."+toolname) cmodul = importlib.import_module("utils."+toolname)
class_ = getattr(cmodul, "CliFcts") class_ = getattr(cmodul, "CliFcts")
c = class_() c = class_()
c.setComp(comp) c.setComp(job, comp)
return c return c
def getApiTool(job, comp): def getApiTool(job, comp):
@ -100,7 +100,7 @@ def getApiTool(job, comp):
cmodul = importlib.import_module("utils."+toolname) cmodul = importlib.import_module("utils."+toolname)
class_ = getattr(cmodul, "ApiFcts") class_ = getattr(cmodul, "ApiFcts")
c = class_() c = class_()
c.setComp(comp) c.setComp(job, comp)
return c return c
def getFileTool(job, comp, filenode=""): def getFileTool(job, comp, filenode=""):

2
check_environment.py

@ -22,7 +22,7 @@ if __name__ == '__main__':
cm = basic.componentHandling.ComponentManager() cm = basic.componentHandling.ComponentManager()
print("cm "+str(cm)) print("cm "+str(cm))
cm.initComponents() cm.initComponents()
comps = cm.getComponents(PROGRAM_NAME) comps = cm.getComponents(x, PROGRAM_NAME)
x.m.setMsg("# Components initialized with these relevant components " + str(comps)) x.m.setMsg("# Components initialized with these relevant components " + str(comps))
for c in comps: for c in comps:
comp = cm.getComponent(c) comp = cm.getComponent(c)

4
collect_testcase.py

@ -18,9 +18,9 @@ PROGRAM_NAME = "collect_testcase"
def startPyJob(job): def startPyJob(job):
cm = basic.componentHandling.ComponentManager.getInstance("init") cm = basic.componentHandling.ComponentManager.getInstance("init")
cm.initComponents() cm.initComponents()
comps = cm.getComponents(PROGRAM_NAME) comps = cm.getComponents(job, 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(job)
job.m.setMsg("# components initialized with "+str(comps)) job.m.setMsg("# components initialized with "+str(comps))
for c in comps: for c in comps:
comp = cm.getComponent(c) comp = cm.getComponent(c)

10
compare_testcase.py

@ -20,24 +20,24 @@ import basic.message as message
PROGRAM_NAME = "compare_testcase" PROGRAM_NAME = "compare_testcase"
def startPyJob(job): def startPyJob(job):
cm = basic.componentHandling.ComponentManager("init") cm = basic.componentHandling.ComponentManager(job, "init")
print("cm "+str(cm)) print("cm "+str(cm))
cm.initComponents() cm.initComponents()
comps = cm.getComponents(PROGRAM_NAME) comps = cm.getComponents(PROGRAM_NAME)
job.m.setMsg("# Components initialized with these relevant components " + str(comps)) job.m.setMsg("# Components initialized with these relevant components " + str(comps))
report = utils.report_tool.Report() report = utils.report_tool.Report(job)
testdata = utils.tdata_tool.getTestdata() testdata = utils.tdata_tool.getTestdata(job)
for c in comps: for c in comps:
comp = cm.getComponent(c) comp = cm.getComponent(c)
comp.m.logInfo("------- "+comp.name+" ----------------------------------------") comp.m.logInfo("------- "+comp.name+" ----------------------------------------")
comp.compare_results(report) comp.compare_results(job, report)
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))
comp.conf["function"][PROGRAM_NAME] = comp.m.topmessage comp.conf["function"][PROGRAM_NAME] = comp.m.topmessage
text = report.reportTestcase(job.par.testcase) text = report.reportTestcase(job.par.testcase)
path = os.path.join(job.par.tcdir, "Result.html") path = os.path.join(job.par.tcdir, "Result.html")
utils.file_tool.writeFileText(job.m, path, text) utils.file_tool.writeFileText(job.m, job, path, text)
# 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__':

4
execute_testcase.py

@ -22,12 +22,12 @@ import basic.message as message
PROGRAM_NAME = "execute_testcase" PROGRAM_NAME = "execute_testcase"
def startPyJob(job): def startPyJob(job):
cm = basic.componentHandling.ComponentManager() cm = basic.componentHandling.ComponentManager(job)
print("cm "+str(cm)) print("cm "+str(cm))
cm.initComponents() cm.initComponents()
comps = cm.getComponents(PROGRAM_NAME) comps = cm.getComponents(PROGRAM_NAME)
job.m.setMsg("# Components initialized with these relevant components " + str(comps)) job.m.setMsg("# Components initialized with these relevant components " + str(comps))
tdata = utils.tdata_tool.getTestdata() tdata = utils.tdata_tool.getTestdata(job)
if not "_steps" in tdata: if not "_steps" in tdata:
raise Exception("no steps to execute in testdata") raise Exception("no steps to execute in testdata")
for (step) in tdata["_steps"]: for (step) in tdata["_steps"]:

8
finish_testsuite.py

@ -22,15 +22,15 @@ def startPyJob(job):
testinstances = getattr(job.par, "testinstances") testinstances = getattr(job.par, "testinstances")
for tc in testinstances: for tc in testinstances:
path = os.path.join(testinstances[tc], "Result.html") path = os.path.join(testinstances[tc], "Result.html")
text = utils.file_tool.readFileText(path, job.m) text = utils.file_tool.readFileText(job, path, job.m)
report.extractTestcase(tc, text) report.extractTestcase(tc, text)
text = report.reportTestsuite() text = report.reportTestsuite()
path = os.path.join(job.par.tsdir, "Result.html") path = os.path.join(job.par.tsdir, "Result.html")
utils.file_tool.writeFileText(job.m, path, text) utils.file_tool.writeFileText(job.m, job, path, text)
archivFolder = job.conf.confs["paths"]["archiv"] archivFolder = job.conf.confs["paths"]["archiv"]
tsFolder = os.path.join(archivFolder, "Testlauf") tsFolder = os.path.join(archivFolder, "Testlauf")
tarfile = utils.zip_tool.openNewTarFile(tsFolder, job.par.usecase+"_"+job.par.tstime+".tar.gz") tarfile = utils.zip_tool.openNewTarFile(job, tsFolder, job.par.usecase+"_"+job.par.tstime+".tar.gz")
utils.zip_tool.appendFolderIntoTarFile(tsFolder, job.par.usecase+"_"+job.par.tstime, tarfile) utils.zip_tool.appendFolderIntoTarFile(job, tsFolder, job.par.usecase+"_"+job.par.tstime, tarfile)
for tc in testinstances: for tc in testinstances:
tcSubFolder = testinstances[tc][len(archivFolder)+1:] tcSubFolder = testinstances[tc][len(archivFolder)+1:]
utils.zip_tool.appendFolderIntoTarFile(archivFolder, tcSubFolder, tarfile) utils.zip_tool.appendFolderIntoTarFile(archivFolder, tcSubFolder, tarfile)

2
generate_testcases.py

@ -1,6 +1,6 @@
# https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/232-testfallgenerierung # https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/232-testfallgenerierung
import random import random
#from flask import #from webflask import
# #
class Koeln(): class Koeln():
# Konfig # Konfig

10
init_testcase.py

@ -19,21 +19,21 @@ import basic.message as message
PROGRAM_NAME = "init_testcase" PROGRAM_NAME = "init_testcase"
def startPyJob(job): def startPyJob(job):
cm = basic.componentHandling.ComponentManager.getInstance("init") cm = basic.componentHandling.ComponentManager.getInstance(job, "init")
cm.initComponents() cm.initComponents()
comps = cm.getComponents(PROGRAM_NAME) comps = cm.getComponents(PROGRAM_NAME)
job.m.setMsg("# Components initialized with these relevant components " + str(comps)) job.m.setMsg("# Components initialized with these relevant components " + str(comps))
testdata = utils.tdata_tool.getTestdata() testdata = utils.tdata_tool.getTestdata(job)
print("------------------------------------------------------------") print("------------------------------------------------------------")
for c in comps: for c in comps:
comp = cm.getComponent(c) comp = cm.getComponent(c)
comp.m.logInfo("------- "+comp.name+" ----------------------------------------") comp.m.logInfo("------- "+comp.name+" ----------------------------------------")
if job.hasFunction("reset_TData"): if job.hasFunction("reset_TData"):
comp.reset_TData(B.PAR_TESTCASE) comp.reset_TData(job, B.PAR_TESTCASE)
if job.hasFunction("load_TData"): if job.hasFunction("load_TData"):
comp.load_TData(B.PAR_TESTCASE, testdata) comp.load_TData(job, B.PAR_TESTCASE, testdata)
if job.hasFunction("read_TData"): if job.hasFunction("read_TData"):
comp.read_TData(utils.path_tool.getKeyValue(P.KEY_PRECOND), B.PAR_TESTCASE) comp.read_TData(job, utils.path_tool.getKeyValue(P.KEY_PRECOND), B.PAR_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))

4
init_testsuite.py

@ -20,10 +20,10 @@ 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() cm = ComponentManager(x)
cm.initComponents() cm.initComponents()
comps = cm.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)
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
start_dialog.py

@ -74,7 +74,7 @@ def restartActualProcess(job):
""" """
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG], JSON_FILE) path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_DEBUG], JSON_FILE)
if os.path.exists(path): if os.path.exists(path):
actProc = utils.file_tool.readFileDict(path) actProc = utils.file_tool.readFileDict(job, path)
jobNr = int(JOB_NR[actProc["job"]]["jobnr"]) jobNr = int(JOB_NR[actProc["job"]]["jobnr"])
question = "Prozess " question = "Prozess "
choiceList = "" choiceList = ""

32
test/test_02css.py

@ -22,61 +22,61 @@ class MyTestCase(unittest.TestCase):
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug",
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", "tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit",
"modus": "unit"} "modus": "unit"}
job.par.setParameterArgs(args) job.par.setParameterArgs(job, args)
# ------- inline --------------- # ------- inline ---------------
job.conf.setConfig("tools.csstyp", "inline") job.conf.setConfig("tools.csstyp", "inline")
job.conf.confs.get("tools")["csstyp"] == "inline" job.conf.confs.get("tools")["csstyp"] == "inline"
text = utils.css_tool.getInlineStyle("diffFiles", "diffA") text = utils.css_tool.getInlineStyle(job, "diffFiles", "diffA")
self.assertEqual(len(text), 37) self.assertEqual(len(text), 37)
self.assertEqual(("style" in text), True) self.assertEqual(("style" in text), True)
text = utils.css_tool.getInlineStyle("diffFiles", "acceptA") text = utils.css_tool.getInlineStyle(job, "diffFiles", "acceptA")
self.assertEqual(len(text), 23) self.assertEqual(len(text), 23)
self.assertEqual(("style" in text), True) self.assertEqual(("style" in text), True)
text = utils.css_tool.getInlineStyle("resultFile", "result1") text = utils.css_tool.getInlineStyle(job, "resultFile", "result1")
self.assertEqual(len(text), 36) self.assertEqual(len(text), 36)
self.assertEqual(("style" in text), True) self.assertEqual(("style" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles") text = utils.css_tool.getInternalStyle(job, "diffFiles")
self.assertEqual(len(text), 84) self.assertEqual(len(text), 84)
text = utils.css_tool.getExternalStyle("diffFiles") text = utils.css_tool.getExternalStyle(job, "diffFiles")
self.assertEqual(len(text), 0) self.assertEqual(len(text), 0)
# ------- internal --------------- # ------- internal ---------------
job.conf.setConfig("tools.csstyp", "internal") job.conf.setConfig("tools.csstyp", "internal")
text = utils.css_tool.getInlineStyle("diffFiles", "diffA") text = utils.css_tool.getInlineStyle(job, "diffFiles", "diffA")
self.assertEqual(len(text), 13) self.assertEqual(len(text), 13)
self.assertEqual(("class" in text), True) self.assertEqual(("class" in text), True)
text = utils.css_tool.getInlineStyle("resultFile", "result1") text = utils.css_tool.getInlineStyle(job, "resultFile", "result1")
self.assertEqual(len(text), 15) self.assertEqual(len(text), 15)
self.assertEqual(("class" in text), True) self.assertEqual(("class" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles") text = utils.css_tool.getInternalStyle(job, "diffFiles")
if verbose: print(text) if verbose: print(text)
self.assertEqual(len(text), 262) self.assertEqual(len(text), 262)
self.assertEqual(("<style>" in text), True) self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("resultFile") text = utils.css_tool.getInternalStyle(job, "resultFile")
if verbose: print(text) if verbose: print(text)
self.assertEqual(len(text), 283) self.assertEqual(len(text), 283)
self.assertEqual(("<style>" in text), True) self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles,resultFile") text = utils.css_tool.getInternalStyle(job, "diffFiles,resultFile")
if verbose: print(text) if verbose: print(text)
self.assertEqual(len(text), 465) self.assertEqual(len(text), 465)
self.assertEqual(("<style>" in text), True) self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles") text = utils.css_tool.getExternalStyle(job, "diffFiles")
self.assertEqual(len(text), 0) self.assertEqual(len(text), 0)
if verbose: print(text) if verbose: print(text)
if verbose: print(str(len(text))) if verbose: print(str(len(text)))
# ------- external --------------- # ------- external ---------------
job.conf.setConfig("tools.csstyp", "external") job.conf.setConfig("tools.csstyp", "external")
text = utils.css_tool.getInlineStyle("diffFiles", "diffA") text = utils.css_tool.getInlineStyle(job, "diffFiles", "diffA")
self.assertEqual(len(text), 13) self.assertEqual(len(text), 13)
self.assertEqual(("class" in text), True) self.assertEqual(("class" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles") text = utils.css_tool.getInternalStyle(job, "diffFiles")
if verbose: print(text) if verbose: print(text)
self.assertEqual(len(text), 55) self.assertEqual(len(text), 55)
self.assertEqual(("<link " in text and "stylesheet" in text), True) self.assertEqual(("<link " in text and "stylesheet" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles") text = utils.css_tool.getExternalStyle(job, "diffFiles")
self.assertEqual(len(text), 216) self.assertEqual(len(text), 216)
if verbose: print(text) if verbose: print(text)
if verbose: print(str(len(text))) if verbose: print(str(len(text)))
text = utils.css_tool.getExternalStyle("diffFiles,resultFile") text = utils.css_tool.getExternalStyle(job, "diffFiles,resultFile")
self.assertEqual(len(text), 449) self.assertEqual(len(text), 449)
if verbose: print(text) if verbose: print(text)
if verbose: print(str(len(text))) if verbose: print(str(len(text)))

6
test/test_03path.py

@ -80,7 +80,7 @@ class MyTestCase(unittest.TestCase):
return return
# set the relevant datastrutures # set the relevant datastrutures
job = test.testtools.getJob() job = test.testtools.getJob()
comp = test.testtools.getComp() comp = test.testtools.getComp(job)
pt = utils.path_tool.PathConf() pt = utils.path_tool.PathConf()
self.setTestPaths(job) self.setTestPaths(job)
self.setPathConfig(pt) self.setPathConfig(pt)
@ -104,12 +104,12 @@ class MyTestCase(unittest.TestCase):
return return
# set the relevant datastrutures # set the relevant datastrutures
job = test.testtools.getJob() job = test.testtools.getJob()
comp = test.testtools.getComp() comp = test.testtools.getComp(job)
pt = utils.path_tool.PathConf() pt = utils.path_tool.PathConf()
self.setTestPaths(job) self.setTestPaths(job)
self.setPathConfig(pt) self.setPathConfig(pt)
# tests # tests
path = utils.path_tool.composePattern("{"+P.P_ENVBASE+"}", None) path = utils.path_tool.composePattern(job, "{"+P.P_ENVBASE+"}", None)
self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path) self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path)
self.assertIn(getattr(job.par, B.PAR_ENV), path) self.assertIn(getattr(job.par, B.PAR_ENV), path)
cnttest += 2 cnttest += 2

14
test/test_04config.py

@ -48,7 +48,7 @@ class MyTestCase(unittest.TestCase):
cnttest += 1 cnttest += 1
r = utils.config_tool.getConfigPath(P.KEY_COMP, "testcrm") r = utils.config_tool.getConfigPath(P.KEY_COMP, "testcrm")
self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS), "testcrm", "CONFIG"), r) self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS), "testcrm", "CONFIG"), r)
r = utils.config_tool.getConfig(P.KEY_TOOL, "path") r = utils.config_tool.getConfig(job, P.KEY_TOOL, "path")
if verbose: print("pattern " + r["pattern"]["log"]) if verbose: print("pattern " + r["pattern"]["log"])
if verbose: print("pattern " + r["pattern"]["precond"]) if verbose: print("pattern " + r["pattern"]["precond"])
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -62,8 +62,8 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
componentName = "testcm" componentName = "testcm"
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig(job, "comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(job, componentName)
self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_CNT], 1) self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_CNT], 1)
self.assertEqual(conns[0][B.SUBJECT_INST][B.ATTR_INST_CNT], 2) self.assertEqual(conns[0][B.SUBJECT_INST][B.ATTR_INST_CNT], 2)
self.assertNotIn(B.ATTR_INST_SGL, conns[0][B.SUBJECT_INST]) self.assertNotIn(B.ATTR_INST_SGL, conns[0][B.SUBJECT_INST])
@ -73,8 +73,8 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_SGL], "n") self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_SGL], "n")
cnttest += 1 # it keep cnttest += 1 # it keep
componentName = "testprddb" componentName = "testprddb"
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig(job, "comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(job, componentName)
self.assertNotIn(B.ATTR_ARTS_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) self.assertNotIn(B.ATTR_ARTS_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB])
confs["conf"] = utils.config_tool.mergeConn(job.m, confs["conf"], conns[0]) confs["conf"] = utils.config_tool.mergeConn(job.m, confs["conf"], conns[0])
self.assertIn(B.ATTR_ARTS_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) self.assertIn(B.ATTR_ARTS_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB])
@ -89,13 +89,13 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
comp = test.testtools.getComp("testprddb") comp = test.testtools.getComp(job, "testprddb")
path = "db.product" path = "db.product"
attrList = utils.config_tool.getAttributeList(comp, path, job) attrList = utils.config_tool.getAttributeList(comp, path, job)
self.assertIn(B.ATTR_ARTS_PATH, attrList) self.assertIn(B.ATTR_ARTS_PATH, attrList)
self.assertIn(B.ATTR_ARTS_RESET, attrList) self.assertIn(B.ATTR_ARTS_RESET, attrList)
cnttest += 2 # new attribute cnttest += 2 # new attribute
comp = test.testtools.getComp("testrest") comp = test.testtools.getComp(job, "testrest")
path = "file.xmlrest" path = "file.xmlrest"
attrList = utils.config_tool.getAttributeList(comp, path, job) attrList = utils.config_tool.getAttributeList(comp, path, job)
print(str(comp.conf["conn"])) print(str(comp.conf["conn"]))

8
test/test_05conn.py

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

22
test/test_06file.py

@ -25,15 +25,15 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file_t.*.py", None) r = t.getFiles(job.m, job, job.conf.getPath("program") + "/utils", "^file_t.*.py", None)
self.assertEqual(len(r), 1) self.assertEqual(len(r), 1)
cnttest += 3 cnttest += 3
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file__.*.py", None) r = t.getFiles(job.m, job, job.conf.getPath("program") + "/utils", "^file__.*.py", None)
self.assertEqual((len(r) == 0), True) self.assertEqual((len(r) == 0), True)
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", ".*_tool.py", None) r = t.getFiles(job.m, job, job.conf.getPath("program") + "/utils", ".*_tool.py", None)
self.assertEqual((len(r) > 2), True) self.assertEqual((len(r) > 2), True)
cnttest += 3 cnttest += 3
r = t.getFilesRec(job.m, job.conf.getPath("program"), ".*?file.*.py") r = t.getFilesRec(job.m, job, job.conf.getPath("program"), ".*?file.*.py")
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
@ -58,11 +58,11 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob() job = test.testtools.getJob()
print("------- test_encoding") print("------- test_encoding")
encodings = ['utf-8', 'windows-1250', 'iso-8859-1'] encodings = ['utf-8', 'windows-1250', 'iso-8859-1']
res = utils.file_tool.getFileEncoding(job.m, os.path.join(DATA_PATH, "tdata", "encoded_iso8859.txt")) res = utils.file_tool.getFileEncoding(job.m, job, os.path.join(DATA_PATH, "tdata", "encoded_iso8859.txt"))
self.assertEqual(res, "iso-8859-1") self.assertEqual(res, "iso-8859-1")
res = utils.file_tool.getFileEncoding(job.m, os.path.join(DATA_PATH, "tdata", "encoded_win1250.txt")) res = utils.file_tool.getFileEncoding(job.m, job, os.path.join(DATA_PATH, "tdata", "encoded_win1250.txt"))
self.assertEqual(res, "iso-8859-1") self.assertEqual(res, "iso-8859-1")
res = utils.file_tool.getFileEncoding(job.m, os.path.join(DATA_PATH, "tdata", "encoded_utf8.txt")) res = utils.file_tool.getFileEncoding(job.m, job, os.path.join(DATA_PATH, "tdata", "encoded_utf8.txt"))
self.assertEqual(res, "utf-8") self.assertEqual(res, "utf-8")
cnttest += 3 cnttest += 3
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
@ -75,10 +75,10 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
pathname = os.path.join(T.COMP_PATH, "testrest", "mapping-rest.yml") pathname = os.path.join(T.COMP_PATH, "testrest", "mapping-rest.yml")
res = utils.file_tool.readFileDict(pathname, job.m) res = utils.file_tool.readFileDict(job, pathname, job.m)
print(res) print(res)
pathname = os.path.join(DATA_PATH, "tdata", "UNIT_TEST", "rest-message.xml") pathname = os.path.join(DATA_PATH, "tdata", "UNIT_TEST", "rest-message.xml")
utils.file_tool.writeFileDict(job.m, pathname, res) utils.file_tool.writeFileDict(job.m, job, pathname, res)
def test_14readXml(self): def test_14readXml(self):
@ -89,7 +89,7 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
pathname = os.path.join(DATA_PATH, "tdata", "UNIT_TEST", "shiporder.xml") pathname = os.path.join(DATA_PATH, "tdata", "UNIT_TEST", "shiporder.xml")
res = utils.file_tool.readFileDict(pathname, job.m) res = utils.file_tool.readFileDict(job, pathname, job.m)
res = dict(res) res = dict(res)
print(res) print(res)
self.assertIn("shiporder", res) self.assertIn("shiporder", res)
@ -97,7 +97,7 @@ class MyTestCase(unittest.TestCase):
for x in res["shiporder"]: for x in res["shiporder"]:
print(x+" "+str(type(res["shiporder"][x]))) print(x+" "+str(type(res["shiporder"][x])))
pathname = os.path.join(DATA_PATH, "tdata", "UNIT_TEST", "shiporder-res.yml") pathname = os.path.join(DATA_PATH, "tdata", "UNIT_TEST", "shiporder-res.yml")
utils.file_tool.writeFileDict(job.m, pathname, res) utils.file_tool.writeFileDict(job.m, job, pathname, res)
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)

8
test/test_11component.py

@ -58,8 +58,8 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob() job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager.getInstance("J") cm = basic.componentHandling.ComponentManager.getInstance("J")
componentName = "testcm" componentName = "testcm"
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig(job, "comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(job, componentName)
c = cm.createInstance(componentName, None, confs, conns, 1) c = cm.createInstance(componentName, None, confs, conns, 1)
self.assertEqual(hasattr(c, "conf"), True, "cinfig-dict must be") self.assertEqual(hasattr(c, "conf"), True, "cinfig-dict must be")
self.assertEqual(hasattr(c, "m"), True, "message-object must be") self.assertEqual(hasattr(c, "m"), True, "message-object must be")
@ -70,8 +70,8 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(c.conf[B.SUBJECT_INST][B.ATTR_INST_SGL], "n", "without conn-attribute the config-attribute keeps") self.assertEqual(c.conf[B.SUBJECT_INST][B.ATTR_INST_SGL], "n", "without conn-attribute the config-attribute keeps")
cnttest += 1 # it keep cnttest += 1 # it keep
componentName = "testprddb" componentName = "testprddb"
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig(job, "comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(job, componentName)
c = cm.createInstance(componentName, None, confs, conns, 0) c = cm.createInstance(componentName, None, confs, conns, 0)
self.assertEqual(c.name, "testprddb") self.assertEqual(c.name, "testprddb")
self.assertIn(B.ATTR_DB_TYPE, c.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB], "conn-attribute creates missing config-attribute") self.assertIn(B.ATTR_DB_TYPE, c.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB], "conn-attribute creates missing config-attribute")

2
test/test_12toolhandling.py

@ -29,7 +29,7 @@ class MyTestCase(unittest.TestCase):
job = basic.program.Job("unit") job = basic.program.Job("unit")
args = {B.PAR_APP: "TEST", B.PAR_ENV: "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool", args = {B.PAR_APP: "TEST", B.PAR_ENV: "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"modus": "unit"} "modus": "unit"}
job.par.setParameterArgs(args) job.par.setParameterArgs(job, args)
#t = basic.toolHandling.ToolManager() #t = basic.toolHandling.ToolManager()
comp = basic.component.Component() comp = basic.component.Component()
comp.name = "testb" comp.name = "testb"

38
test/test_21tdata.py

@ -67,7 +67,7 @@ class MyTestCase(unittest.TestCase):
";;;;;;", ";;;;;;",
"#;;;;;;" "#;;;;;;"
] ]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job)
self.assertEqual(0, len(tdata)) self.assertEqual(0, len(tdata))
cnttest += 1 cnttest += 1
if "malformated" in tests: if "malformated" in tests:
@ -78,7 +78,7 @@ class MyTestCase(unittest.TestCase):
"#option:nopar;arg;;;;;", "#option:nopar;arg;;;;;",
"#;;;;;;" "#;;;;;;"
] ]
self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_DATA)) self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_DATA, job))
cnttest += 1 cnttest += 1
malformat = "step;component;1;arg:val;;;;;" malformat = "step;component;1;arg:val;;;;;"
specLines = [ specLines = [
@ -92,7 +92,7 @@ class MyTestCase(unittest.TestCase):
"step:1;component;1;arg:val;;;", "step:1;component;1;arg:val;;;",
malformat malformat
] ]
self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_DATA)) self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_DATA, job))
cnttest += 1 cnttest += 1
specLines = [ specLines = [
"option:par;arg;;;;;", "option:par;arg;;;;;",
@ -104,7 +104,7 @@ class MyTestCase(unittest.TestCase):
"option:description;something;;;;;", "option:description;something;;;;;",
"#;;;;;;" "#;;;;;;"
] ]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job)
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
print(tdata) print(tdata)
self.assertIn(D.CSV_BLOCK_OPTION, tdata) self.assertIn(D.CSV_BLOCK_OPTION, tdata)
@ -114,7 +114,7 @@ class MyTestCase(unittest.TestCase):
"step:1;testa;1;1;table:_lofts,action:import;;;;;", "step:1;testa;1;1;table:_lofts,action:import;;;;;",
"#;;;;;;" "#;;;;;;"
] ]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job)
print(tdata) print(tdata)
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
self.assertIn(B.DATA_NODE_STEPS, tdata) self.assertIn(B.DATA_NODE_STEPS, tdata)
@ -131,7 +131,7 @@ class MyTestCase(unittest.TestCase):
"#;;;;;;" "#;;;;;;"
] ]
tdata = {} tdata = {}
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job)
print(tdata) print(tdata)
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
self.assertIn(B.DATA_NODE_STEPS, tdata) self.assertIn(B.DATA_NODE_STEPS, tdata)
@ -144,7 +144,7 @@ class MyTestCase(unittest.TestCase):
"testa:lofts;1;stra;town;12345;usa;4;1;50;house;111;45;8", "testa:lofts;1;stra;town;12345;usa;4;1;50;house;111;45;8",
"#;;;;;;" "#;;;;;;"
] ]
tdata = t.parseCsvSpec(job.m, specLines, B.DATA_NODE_TABLES) tdata = t.parseCsvSpec(job.m, specLines, B.DATA_NODE_TABLES, job)
print(tdata) print(tdata)
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
self.assertIn(B.DATA_NODE_TABLES, tdata) self.assertIn(B.DATA_NODE_TABLES, tdata)
@ -170,7 +170,7 @@ class MyTestCase(unittest.TestCase):
"testrest:person;1;Brecht;Bert;10.02.98;m", "testrest:person;1;Brecht;Bert;10.02.98;m",
"testrest:person,testcrmdb:person;2;Leon;Donna;28.09.42;f" "testrest:person,testcrmdb:person;2;Leon;Donna;28.09.42;f"
] ]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job)
print(tdata) print(tdata)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -209,7 +209,7 @@ class MyTestCase(unittest.TestCase):
";;;;;;", ";;;;;;",
"#;;;;;;" "#;;;;;;"
] ]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS, job)
self.assertEqual(0, len(tdata)) self.assertEqual(0, len(tdata))
cnttest += 1 cnttest += 1
if "malformated" in tests: if "malformated" in tests:
@ -218,7 +218,7 @@ class MyTestCase(unittest.TestCase):
malformat, malformat,
"#;;;;;;" "#;;;;;;"
] ]
self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_KEYS)) self.assertRaises(Exception, t.parseCsvSpec, (job.m, specLines, D.CSV_SPECTYPE_KEYS, job))
cnttest += 1 cnttest += 1
if B.DATA_NODE_TABLES in tests: if B.DATA_NODE_TABLES in tests:
specLines = [ specLines = [
@ -227,7 +227,7 @@ class MyTestCase(unittest.TestCase):
";berlin;;;;;", ";berlin;;;;;",
";cairo;;;;;" ";cairo;;;;;"
] ]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS, job)
print(str(tdata)) print(str(tdata))
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
self.assertEqual(1, len(tdata["_tables"])) self.assertEqual(1, len(tdata["_tables"]))
@ -242,7 +242,7 @@ class MyTestCase(unittest.TestCase):
";greece;;;;;", ";greece;;;;;",
";germany;;;;;" ";germany;;;;;"
] ]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS, job)
#tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_TREE) #tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_TREE)
print(str(tdata)) print(str(tdata))
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
@ -272,7 +272,7 @@ class MyTestCase(unittest.TestCase):
";city;b;str;;F:1", ";city;b;str;;F:1",
"#;;;;;;" "#;;;;;;"
] ]
tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_CONF) tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_CONF, job)
print(tdata) print(tdata)
self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata))
self.assertNotIn(B.DATA_NODE_TABLES, tdata) self.assertNotIn(B.DATA_NODE_TABLES, tdata)
@ -294,8 +294,8 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob() job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager.getInstance("J") cm = basic.componentHandling.ComponentManager.getInstance("J")
componentName = "testcrmdb" componentName = "testcrmdb"
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig(job, "comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(job, componentName)
comp = cm.createInstance(componentName, None, confs, conns, 1) comp = cm.createInstance(componentName, None, confs, conns, 1)
fileLines = [ fileLines = [
"table:person;_nr;famname;name;birth;sex", "table:person;_nr;famname;name;birth;sex",
@ -304,7 +304,7 @@ class MyTestCase(unittest.TestCase):
"#;;;;;;" "#;;;;;;"
] ]
filename = utils.path_tool.rejoinPath(utils.path_tool.composePath(P.P_TCBASE, comp), "t_person.csv") filename = utils.path_tool.rejoinPath(utils.path_tool.composePath(P.P_TCBASE, comp), "t_person.csv")
tdata = t.parseCsv(comp.m, filename, fileLines, comp, aliasNode="") tdata = t.parseCsv(comp.m, job, filename, fileLines, comp, aliasNode="")
print(str(tdata)) print(str(tdata))
self.assertIn(B.DATA_NODE_TABLES, tdata) self.assertIn(B.DATA_NODE_TABLES, tdata)
self.assertIn("person", tdata[B.DATA_NODE_TABLES]) self.assertIn("person", tdata[B.DATA_NODE_TABLES])
@ -318,7 +318,7 @@ class MyTestCase(unittest.TestCase):
"testcrmdb:person;2;Leon;Donna;28.09.42;f", "testcrmdb:person;2;Leon;Donna;28.09.42;f",
"#;;;;;;" "#;;;;;;"
] ]
tdata = t.parseCsv(comp.m, filename, fileLines, comp, aliasNode="") tdata = t.parseCsv(comp.m, job, filename, fileLines, comp, aliasNode="")
self.assertIn(B.DATA_NODE_TABLES, tdata) self.assertIn(B.DATA_NODE_TABLES, tdata)
self.assertIn("person", tdata[B.DATA_NODE_TABLES]) self.assertIn("person", tdata[B.DATA_NODE_TABLES])
self.assertEqual(2, len(tdata[B.DATA_NODE_TABLES]["person"][B.DATA_NODE_DATA])) self.assertEqual(2, len(tdata[B.DATA_NODE_TABLES]["person"][B.DATA_NODE_DATA]))
@ -332,14 +332,14 @@ class MyTestCase(unittest.TestCase):
"2;Leon;Donna;28.09.42;f", "2;Leon;Donna;28.09.42;f",
"#;;;;;;" "#;;;;;;"
] ]
tdata = t.parseCsv(comp.m, filename, fileLines, comp, aliasNode="") tdata = t.parseCsv(comp.m, job, filename, fileLines, comp, aliasNode="")
self.assertIn(B.DATA_NODE_TABLES, tdata) self.assertIn(B.DATA_NODE_TABLES, tdata)
self.assertIn("person", tdata[B.DATA_NODE_TABLES]) self.assertIn("person", tdata[B.DATA_NODE_TABLES])
self.assertEqual(2, len(tdata[B.DATA_NODE_TABLES]["person"][B.DATA_NODE_DATA])) self.assertEqual(2, len(tdata[B.DATA_NODE_TABLES]["person"][B.DATA_NODE_DATA]))
cnttest += 3 cnttest += 3
text = "" text = ""
for k in tdata[B.DATA_NODE_TABLES]: for k in tdata[B.DATA_NODE_TABLES]:
text += t.buildCsvData(filename, tdata[B.DATA_NODE_TABLES][k], comp) text += t.buildCsvData(filename, tdata[B.DATA_NODE_TABLES][k], comp, job)
text += "\n" text += "\n"
print(text) print(text)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

19
test/test_22compare.py

@ -111,7 +111,7 @@ class MyTestCase(unittest.TestCase):
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.conf = conf comp.conf = conf
comp.name = "component" comp.name = "component"
matching = utils.match_tool.Matching(comp) matching = utils.match_tool.Matching(job, comp)
matching.setData(tdata, M.MATCH_SUCCESS) matching.setData(tdata, M.MATCH_SUCCESS)
print(matching.htmltext) print(matching.htmltext)
@ -121,11 +121,12 @@ class MyTestCase(unittest.TestCase):
cnttest = 0 cnttest = 0
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob()
comp = basic.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
comp.conf = conf comp.conf = conf
matching = utils.match_tool.Matching(comp) matching = utils.match_tool.Matching(job, comp)
matching.linksA = { "a0001": "null", "a0002": "null", "a0003": "null", "a0004": "null"} matching.linksA = { "a0001": "null", "a0002": "null", "a0003": "null", "a0004": "null"}
matching.linksB = { "b0001": "null", "b0002": "null", "b0003": "null", "b0004": "null"} matching.linksB = { "b0001": "null", "b0002": "null", "b0003": "null", "b0004": "null"}
self.assertEqual(matching.isHitA("a0001"), False, "with value null") self.assertEqual(matching.isHitA("a0001"), False, "with value null")
@ -142,7 +143,7 @@ class MyTestCase(unittest.TestCase):
cnttest = 0 cnttest = 0
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
matching = self.getMatching() matching = self.getMatching(job, )
utils.match_tool.setMatchkeys(matching, ":database:scheme:table:_data") utils.match_tool.setMatchkeys(matching, ":database:scheme:table:_data")
utils.match_tool.getSimilarity(matching, utils.match_tool.getSimilarity(matching,
tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0], tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0],
@ -160,7 +161,7 @@ class MyTestCase(unittest.TestCase):
comp.name = "component" comp.name = "component"
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.conf = conf comp.conf = conf
matching = utils.match_tool.Matching(comp) matching = utils.match_tool.Matching(job, comp)
matching.matchtype = M.MATCH_SUCCESS matching.matchtype = M.MATCH_SUCCESS
matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA] matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA] matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
@ -185,7 +186,7 @@ class MyTestCase(unittest.TestCase):
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
comp.conf = conf comp.conf = conf
matching = self.getMatching() matching = self.getMatching(job, comp)
matching.matchtype = M.MATCH_SUCCESS matching.matchtype = M.MATCH_SUCCESS
matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA] matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA] matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
@ -212,7 +213,7 @@ class MyTestCase(unittest.TestCase):
comp.conf = conf comp.conf = conf
cm = basic.componentHandling.ComponentManager() cm = basic.componentHandling.ComponentManager()
basic.componentHandling.comps["component"] = comp basic.componentHandling.comps["component"] = comp
matching = self.getMatching() matching = self.getMatching(job, comp)
comp.name = "component" comp.name = "component"
matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA] matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA] matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
@ -237,7 +238,7 @@ class MyTestCase(unittest.TestCase):
cm.comps["component"] = comp cm.comps["component"] = comp
# tdata["postReq"] = tdata["preAct"] # tdata["postReq"] = tdata["preAct"]
comp.conf = conf comp.conf = conf
matching = utils.match_tool.Matching(comp) matching = utils.match_tool.Matching(job, comp)
matching.htmltext = "" matching.htmltext = ""
matching.setData(tdata, M.MATCH_POSTCOND) matching.setData(tdata, M.MATCH_POSTCOND)
text = utils.match_tool.matchTree(matching) text = utils.match_tool.matchTree(matching)
@ -246,7 +247,7 @@ class MyTestCase(unittest.TestCase):
print("\n-------------\n") print("\n-------------\n")
print(matching.difftext) print(matching.difftext)
def getMatching(self): def getMatching(self, job):
job = test.testtools.getJob() job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
setattr(job.par, "tctime", "2022-03-25_19-25-31") setattr(job.par, "tctime", "2022-03-25_19-25-31")
@ -254,7 +255,7 @@ class MyTestCase(unittest.TestCase):
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
comp.conf = conf comp.conf = conf
matching = utils.match_tool.Matching(comp) matching = utils.match_tool.Matching(job, comp)
matching.setData(tdata, M.MATCH_SUCCESS) matching.setData(tdata, M.MATCH_SUCCESS)
matching.difftext = "" matching.difftext = ""
return matching return matching

2
test/test_22report.py

@ -20,7 +20,7 @@ class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"
def getReport(self): def getReport(self):
job = basic.program.Job.getInstance() job = test.testtools.getJob()
report = utils.report_tool.Report() report = utils.report_tool.Report()
archiv = job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV]+"/" archiv = job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV]+"/"
i = 0 i = 0

18
test/test_25map.py

@ -62,7 +62,7 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job)
tdata = utils.tdata_tool.getCsvSpec(job.m, path, D.CSV_SPECTYPE_DATA) tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA)
args = {} args = {}
args[B.DATA_NODE_DATA] = tdata args[B.DATA_NODE_DATA] = tdata
args[B.DATA_NODE_STEPS] = tdata[B.DATA_NODE_STEPS][0] args[B.DATA_NODE_STEPS] = tdata[B.DATA_NODE_STEPS][0]
@ -88,9 +88,9 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(res[1], ("1", "5")) self.assertEqual(res[1], ("1", "5"))
cnttest += 1 cnttest += 1
compName = "testcrmdb" compName = "testcrmdb"
args[B.DATA_NODE_COMP] = test.testtools.getComp(compName) args[B.DATA_NODE_COMP] = test.testtools.getComp(job, compName)
comp = args[B.DATA_NODE_COMP] comp = args[B.DATA_NODE_COMP]
conf = utils.config_tool.getConfig(D.DDL_FILENAME, compName, "person") conf = utils.config_tool.getConfig(job, D.DDL_FILENAME, compName, "person")
comp.conf[B.DATA_NODE_DDL] = {} comp.conf[B.DATA_NODE_DDL] = {}
comp.conf[B.DATA_NODE_DDL]["person"] = conf comp.conf[B.DATA_NODE_DDL]["person"] = conf
res = utils.map_tool.getIds(job, args, "fields={_comp.ddl.person}") res = utils.map_tool.getIds(job, args, "fields={_comp.ddl.person}")
@ -112,7 +112,7 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job)
tdata = utils.tdata_tool.getCsvSpec(job.m, path, D.CSV_SPECTYPE_DATA) tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA)
condIds = [["1"]] condIds = [["1"]]
args = {} args = {}
args[B.DATA_NODE_DATA] = tdata args[B.DATA_NODE_DATA] = tdata
@ -130,7 +130,7 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job)
tdata = utils.tdata_tool.getCsvSpec(job.m, path, D.CSV_SPECTYPE_DATA) tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA)
condIds = [["1"]] condIds = [["1"]]
args = {} args = {}
args[B.DATA_NODE_DATA] = tdata args[B.DATA_NODE_DATA] = tdata
@ -172,17 +172,17 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
comp = test.testtools.getComp("testrest") comp = test.testtools.getComp(job, "testrest")
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_COMPS], "testrest", "mapping-rest.yml") path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_COMPS], "testrest", "mapping-rest.yml")
mapping = utils.file_tool.readFileDict(path, job.m) mapping = utils.file_tool.readFileDict(job, path, job.m)
path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job)
tdata = utils.tdata_tool.getCsvSpec(job.m, path, D.CSV_SPECTYPE_DATA) tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA)
res = utils.map_tool.mapTdata(job, mapping, tdata, tdata[B.DATA_NODE_STEPS][1], comp) res = utils.map_tool.mapTdata(job, mapping, tdata, tdata[B.DATA_NODE_STEPS][1], comp)
print(res) print(res)
for format in ["xml", "yml", "json"]: for format in ["xml", "yml", "json"]:
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA], "temp", "result-rest."+format) path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA], "temp", "result-rest."+format)
print(path) print(path)
utils.file_tool.writeFileDict(job.m, path, res) utils.file_tool.writeFileDict(job.m, job, path, res)
doc = json.dumps(res, indent=0) doc = json.dumps(res, indent=0)
print(doc) print(doc)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

13
test/test_31db.py

@ -15,6 +15,7 @@ import basic.constants as B
import utils.db_abstract import utils.db_abstract
import test.testtools import test.testtools
import utils.config_tool import utils.config_tool
import utils.data_const as D
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
@ -45,7 +46,7 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(obj[0][1], "family") self.assertEqual(obj[0][1], "family")
self.assertEqual(obj[1][3], "end") self.assertEqual(obj[1][3], "end")
self.assertEqual(obj[1][1], "state") self.assertEqual(obj[1][1], "state")
ddl = utils.config_tool.getConfig("DATASTRUCTURE", "testb1", "lofts") ddl = utils.config_tool.getConfig(job, D.DDL_FILENAME, "testb1", "lofts")
dbwhere = utils.db_abstract.parseSQLwhere("street like !%utz%! and state = !+reg+!", ddl["testb1"]["lofts"]) dbwhere = utils.db_abstract.parseSQLwhere("street like !%utz%! and state = !+reg+!", ddl["testb1"]["lofts"])
self.assertIn("state", dbwhere) self.assertIn("state", dbwhere)
self.assertNotIn("family", dbwhere) self.assertNotIn("family", dbwhere)
@ -64,14 +65,14 @@ class MyTestCase(unittest.TestCase):
job = basic.program.Job("unit") job = basic.program.Job("unit")
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool", args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"modus": "unit"} "modus": "unit"}
job.par.setParameterArgs(args) job.par.setParameterArgs(job, args)
#t = basic.toolHandling.ToolManager() #t = basic.toolHandling.ToolManager()
comp = basic.component.Component() comp = basic.component.Component()
comp.name = "testb1" comp.name = "testb1"
table = "lofts" table = "lofts"
comp.conf = {} comp.conf = {}
comp.conf[B.DATA_NODE_DDL] = {} comp.conf[B.DATA_NODE_DDL] = {}
comp.conf[B.DATA_NODE_DDL][table] = utils.config_tool.getConfig("DATASTRUCTURE", comp.name, table) comp.conf[B.DATA_NODE_DDL][table] = utils.config_tool.getConfig(job, D.DDL_FILENAME, comp.name, table)
comp.conf[B.SUBJECT_ARTS] = {} comp.conf[B.SUBJECT_ARTS] = {}
comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB] = {} comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB] = {}
comp.conf[B.SUBJECT_CONN] = {} comp.conf[B.SUBJECT_CONN] = {}
@ -88,18 +89,18 @@ class MyTestCase(unittest.TestCase):
attr = tool.getDbAttributes("xx") attr = tool.getDbAttributes("xx")
self.assertRegex(attr[B.ATTR_DB_PARTITION], 'z') self.assertRegex(attr[B.ATTR_DB_PARTITION], 'z')
# #
sqls = comp.composeSqlClauses("SELECT * FROM lofts") sqls = comp.composeSqlClauses(job, "SELECT * FROM lofts")
print(sqls) print(sqls)
self.assertEqual(sqls["ALL"], "SELECT * FROM .lofts ORDER BY id") self.assertEqual(sqls["ALL"], "SELECT * FROM .lofts ORDER BY id")
setattr(job.par, B.PAR_DB_WHERE, "street like !%utz%! and state = !+reg+!") setattr(job.par, B.PAR_DB_WHERE, "street like !%utz%! and state = !+reg+!")
comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "+reg+" comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "+reg+"
sqls = comp.composeSqlClauses("SELECT * FROM lofts") sqls = comp.composeSqlClauses(job, "SELECT * FROM lofts")
print(sqls) print(sqls)
self.assertIn("street", sqls["ALL"]) #assertEqual(("street" in sqls), True) self.assertIn("street", sqls["ALL"]) #assertEqual(("street" in sqls), True)
self.assertIn("state", sqls["ALL"]) self.assertIn("state", sqls["ALL"])
setattr(job.par, B.PAR_DB_WHERE, "family like !%utz%! and state = !+reg+!") setattr(job.par, B.PAR_DB_WHERE, "family like !%utz%! and state = !+reg+!")
comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "+reg+" comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "+reg+"
sqls = comp.composeSqlClauses("SELECT * FROM lofts") sqls = comp.composeSqlClauses(job, "SELECT * FROM lofts")
print(sqls) print(sqls)
self.assertIn("family", sqls["ALL"]) self.assertIn("family", sqls["ALL"])
self.assertIn("state", sqls["ALL"]) self.assertIn("state", sqls["ALL"])

6
test/test_32file.py

@ -41,11 +41,11 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
comp = test.testtools.getComp("testrest") comp = test.testtools.getComp(job, "testrest")
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_COMPS], "testrest", "mapping-rest.yml") path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_COMPS], "testrest", "mapping-rest.yml")
mapping = utils.file_tool.readFileDict(path, job.m) mapping = utils.file_tool.readFileDict(job, path, job.m)
path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job)
tdata = utils.tdata_tool.getCsvSpec(job.m, path, D.CSV_SPECTYPE_DATA) tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA)
res = utils.file_abstract.mapTdata(job, mapping, tdata, tdata[B.DATA_NODE_STEPS][0], comp) res = utils.file_abstract.mapTdata(job, mapping, tdata, tdata[B.DATA_NODE_STEPS][0], comp)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

33
test/test_71job.py

@ -18,13 +18,24 @@ HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key", TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key",
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv", "test_smokeTestcase"] "test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv", "test_smokeTestcase"]
TEST_FUNCTIONS = ["test_smokeTestcase"] TEST_FUNCTIONS = ["test_00create"]
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"
def test_00create(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = basic.program.createJob()
print(str(job))
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parameter(self): def test_parameter(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
@ -34,7 +45,7 @@ class MyTestCase(unittest.TestCase):
job = Job("unit") job = Job("unit")
args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug", args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug",
"tool" : "job_tool", "function": "reset_TData,load_TData" } "tool" : "job_tool", "function": "reset_TData,load_TData" }
job.par.setParameterArgs(args) job.par.setParameterArgs(job, args)
self.assertEqual(job.hascomponente("TestA"), True) self.assertEqual(job.hascomponente("TestA"), True)
self.assertEqual(job.hasTool("TestA"), False) self.assertEqual(job.hasTool("TestA"), False)
self.assertEqual(job.hasTool("job_tool"), True) self.assertEqual(job.hasTool("job_tool"), True)
@ -45,7 +56,7 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(job.hasFunction("read_TData"), False) self.assertEqual(job.hasFunction("read_TData"), False)
args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug", args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug",
"tool" : "job_tool", "tsdir": os.path.join(HOME_PATH, "test", "lauf", "V0.1", "startjob", "2021-08-21_18-ß2-01")} "tool" : "job_tool", "tsdir": os.path.join(HOME_PATH, "test", "lauf", "V0.1", "startjob", "2021-08-21_18-ß2-01")}
job.par.setParameterArgs(args) job.par.setParameterArgs(job, args)
def test_run(self): def test_run(self):
@ -74,7 +85,7 @@ class MyTestCase(unittest.TestCase):
B.PAR_TCDIR: os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec), B.PAR_TCDIR: os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 1 } "step": 1 }
# "usecase": "TST001", "tstime": "2022-03-17_17-28"} # "usecase": "TST001", "tstime": "2022-03-17_17-28"}
job.par.setParameterArgs(args) job.par.setParameterArgs(job, args)
job.setProgram(program) job.setProgram(program)
init_testcase.startPyJob(job) init_testcase.startPyJob(job)
job.startJob() job.startJob()
@ -102,9 +113,9 @@ class MyTestCase(unittest.TestCase):
# basic parameter # basic parameter
programs = ["copy_precondition", "init_testcase", "copy_postcondition", "execute_testcase", programs = ["copy_precondition", "init_testcase", "copy_postcondition", "execute_testcase",
"collect_testcase", "compare_testcase"] "collect_testcase", "compare_testcase"]
programs = ["copy_precondition", "execute_testcase"] programs = ["execute_testcase"]
testcase = "TC0001" testcase = "TC0001"
timexec = "2022-07-18_21-23-34" timexec = "2022-08-18_14-23-34"
fct = "read_TData" fct = "read_TData"
if "init_testcase" in programs: if "init_testcase" in programs:
program = "init_testcase" program = "init_testcase"
@ -112,7 +123,7 @@ class MyTestCase(unittest.TestCase):
args = {B.PAR_APP: "TESTAPP", B.PAR_ENV: "ENV01", "modus": "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), B.PAR_TCDIR: os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 1} "step": 1}
job.par.setParameterArgs(args) job.par.setParameterArgs(job, args)
job.setProgram(program) job.setProgram(program)
if "copy_precondition" in programs: if "copy_precondition" in programs:
copyAppData(job, program, "tdpreexec") copyAppData(job, program, "tdpreexec")
@ -138,14 +149,14 @@ def copyAppData(job, program, tdsource):
comps = cm.getComponents(program) comps = cm.getComponents(program)
for c in comps: for c in comps:
comp = cm.getComponent(c) comp = cm.getComponent(c)
tdatapath = utils.path_tool.composePattern("{"+tdsource+"}", comp) tdatapath = utils.path_tool.composePattern(job, "{"+tdsource+"}", comp)
envapppath = utils.path_tool.composePattern("{envappdir}", comp) envapppath = utils.path_tool.composePattern(job, "{envappdir}", comp)
if os.path.exists(tdatapath): if os.path.exists(tdatapath):
files = utils.file_tool.getFiles(job.m, tdatapath, ".+\.csv", None) files = utils.file_tool.getFiles(job.m, job, tdatapath, ".+\.csv", None)
for f in files: for f in files:
# shutil.copy() # shutil.copy()
print("cp " + os.path.join(tdatapath, f) + " " + os.path.join(envapppath, f)) print("cp " + os.path.join(tdatapath, f) + " " + os.path.join(envapppath, f))
utils.file_tool.mkPaths(os.path.join(envapppath, f), job.m) utils.file_tool.mkPaths(job, os.path.join(envapppath, f), job.m)
shutil.copy(os.path.join(tdatapath, f), os.path.join(envapppath, f)) shutil.copy(os.path.join(tdatapath, f), os.path.join(envapppath, f))
print(tdatapath) print(tdatapath)

66
test/test_xml.py

@ -1,15 +1,31 @@
import unittest import unittest
import inspect
#import basic.program #import basic.program
import utils.xml1_tool import utils.xml1_tool
import utils.xml1_tool import utils.xml1_tool
import test.testtools
# here you can select single testfunction for developping the tests
# "test_toolhandling", "test_parseSql" -> test of components
TEST_FUNCTIONS = ["test_01addSingle", "test_02addTwo", "test_03addOnePaths", "test_04addTwoPaths",
"test_11file2dict", "test_11file2dict"]
# TEST_FUNCTIONS = ["test_11mapTdata"]
verbose = False
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def xtest_xmlTool(self): mymsg = "--------------------------------------------------------------"
#job = basic.program.Job("unit")
def test_11file2dict(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug",
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", "tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit",
"modus": "unit"} "modus": "unit"}
beispiel_json = {'root': {'@attr': 'xyz', '$': 'inhalt', "b": "bold"}} beispiel_json = {'root': {'@attr': 'xyz', '#text': 'inhalt', "b": "bold"}}
tree = {} tree = {}
tree["root"] = args tree["root"] = args
xml = utils.xml1_tool.dict2xml(tree) xml = utils.xml1_tool.dict2xml(tree)
@ -19,14 +35,26 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(1, 1) self.assertEqual(1, 1)
f = utils.xml1_tool.fcts() f = utils.xml1_tool.fcts()
def xtest_addSingle(self): def test_01addSingle(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
tree = {} tree = {}
# tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', 2, "abc") # tree = utils.xml_tool.fcts.addMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', 2, "abc")
tree = utils.xml1_tool.fcts.addMerkmal(tree, '/root/datensegment/kratz/mm[@name="NAME"]/wert', 2, "abc") tree = utils.xml1_tool.fcts.addMerkmal(tree, '/root/datensegment/kratz/mm[@name="NAME"]/wert', 2, "abc")
self.assertEqual(tree["kratz"]["mm"][0]["wert"], "abc") self.assertEqual(tree["kratz"]["mm"][0]["wert"], "abc")
self.assertEqual(tree["kratz"]["mm"][0]["@name"], "NAME") self.assertEqual(tree["kratz"]["mm"][0]["@name"], "NAME")
def xtest_addTwo(self): def test_02addTwo(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
# a-b-b # a-b-b
# c-a-a c-a-b # c-a-a c-a-b
tree = {} tree = {}
@ -41,8 +69,17 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(tree["kratz"]["mm"][0]["@name"], "NAME") self.assertEqual(tree["kratz"]["mm"][0]["@name"], "NAME")
self.assertEqual(tree["kratz"]["mm"][1]["wert"], "xyz") self.assertEqual(tree["kratz"]["mm"][1]["wert"], "xyz")
self.assertEqual(tree["kratz"]["mm"][1]["@name"], "LAND") self.assertEqual(tree["kratz"]["mm"][1]["@name"], "LAND")
c = utils.xml1_tool.fcts()
xml = c.tidy(baum, 0)
print(xml)
def xtest_addOnePaths(self): def test_03addOnePaths(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
tree = {} tree = {}
print("--------------------------------------------------------------------------------") print("--------------------------------------------------------------------------------")
tree = utils.xml1_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', "abc") tree = utils.xml1_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', "abc")
@ -53,7 +90,13 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["@name"], "NAME") self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["@name"], "NAME")
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["@klasse"], "4711x") self.assertEqual(tree["root"]["datensegment"]["satz"][0]["@klasse"], "4711x")
def xtest_addTwoPaths(self): def test_04addTwoPaths(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
tree = {} tree = {}
print("--------------------------------------------------------------------------------") print("--------------------------------------------------------------------------------")
tree = utils.xml1_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', "abc") tree = utils.xml1_tool.fcts.setMerkmal(tree, '/root/datensegment/satz[@klasse="4711x"]/mm[@name="NAME"]/wert', "abc")
@ -66,7 +109,13 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["@name"], "NAME") self.assertEqual(tree["root"]["datensegment"]["satz"][0]["mm"][0]["@name"], "NAME")
self.assertEqual(tree["root"]["datensegment"]["satz"][0]["@klasse"], "4711x") self.assertEqual(tree["root"]["datensegment"]["satz"][0]["@klasse"], "4711x")
def test_tidy(self): def test_12tidy(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
tree_dict = { "eins": "zwei", "drei": "vier" } tree_dict = { "eins": "zwei", "drei": "vier" }
tree_dict3 = { "eins": { "zwei": { "drei": "vier" } }} tree_dict3 = { "eins": { "zwei": { "drei": "vier" } }}
tree_list = { "eins": [ {"zwei": 2, "drei": 3, "vier": 4 } ] } tree_list = { "eins": [ {"zwei": 2, "drei": 3, "vier": 4 } ] }
@ -98,5 +147,6 @@ class MyTestCase(unittest.TestCase):
print(xml) print(xml)
if __name__ == '__main__': if __name__ == '__main__':
verbose = True
unittest.main() unittest.main()

14
test/testtools.py

@ -46,9 +46,9 @@ conf = {
} }
def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""): def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
job = basic.program.Job.popInstance() #job = basic.program.Job.popInstance()
if not job is None: #if not job is None:
job.stopJob(1) # job.stopJob(1)
if len(pgran) < 1: if len(pgran) < 1:
gran = DEFAULT_GRAN gran = DEFAULT_GRAN
else: else:
@ -79,16 +79,16 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
gran+"dir": path, gran+"dir": path,
"step": 2} "step": 2}
# "usecase": "TST001", "tstime": "2022-03-17_17-28"} # "usecase": "TST001", "tstime": "2022-03-17_17-28"}
job.par.setParameterArgs(args) job.par.setParameterArgs(job, args)
return job return job
def getComp(componentName): def getComp(job, componentName):
comp = basic.component.Component() comp = basic.component.Component()
comp.conf = {} comp.conf = {}
comp.name = componentName comp.name = componentName
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig(job, "comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(job, componentName)
comp.conf = confs["conf"] comp.conf = confs["conf"]
comp.conf[B.SUBJECT_CONN] = conns[0] comp.conf[B.SUBJECT_CONN] = conns[0]
return comp return comp

28
test_executer.py

@ -29,7 +29,7 @@ def getTime():
def startPy(pjob): def startPy(pjob):
myjob = pjob myjob = pjob
myjob.m.setMsg("# # # # # start executer # # # # # ") myjob.m.setMsg("# # # # # start executer # # # # # ")
tdata = utils.tdata_tool.getTestdata() tdata = utils.tdata_tool.getTestdata(myjob)
job = basic.program.Job("unit") job = basic.program.Job("unit")
if not hasattr(myjob.par, B.PAR_STEP): if not hasattr(myjob.par, B.PAR_STEP):
raise Exception("Parameter " + B.PAR_STEP + " is missing") raise Exception("Parameter " + B.PAR_STEP + " is missing")
@ -43,16 +43,16 @@ def startPy(pjob):
if "testsuite" in step["args"][arg]: if "testsuite" in step["args"][arg]:
jobargs = {B.PAR_APP: myjob.par.application, B.PAR_ENV: myjob.par.environment, jobargs = {B.PAR_APP: myjob.par.application, B.PAR_ENV: myjob.par.environment,
B.PAR_TESTSUITE: myjob.par.usecase, B.PAR_TSTIME: utils.date_tool.getActdate(utils.date_tool.F_DIR)} B.PAR_TESTSUITE: myjob.par.usecase, B.PAR_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(job, jobargs)
job.setProgram(step["args"][arg]) job.setProgram(step["args"][arg])
print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TSDIR)) print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TSDIR))
myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TSDIR)) myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TSDIR))
dirname = getattr(job.par, B.PAR_TSDIR) dirname = getattr(job.par, B.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 B.PAR_TESTCASE in step["args"][arg]: if B.PAR_TESTCASE in step["args"][arg]:
@ -62,33 +62,33 @@ def startPy(pjob):
else: else:
jobargs = {B.PAR_APP: myjob.par.application, B.PAR_ENV: myjob.par.environment, jobargs = {B.PAR_APP: myjob.par.application, B.PAR_ENV: myjob.par.environment,
B.PAR_TESTCASE: step["comp"], B.PAR_TCTIME: utils.date_tool.getActdate(utils.date_tool.F_DIR)} B.PAR_TESTCASE: step["comp"], B.PAR_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(job, jobargs)
job.setProgram(step["args"][arg]) job.setProgram(step["args"][arg])
print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TCDIR)) print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TCDIR))
myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TCDIR)) myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TCDIR))
dirname = getattr(job.par, B.PAR_TCDIR) dirname = getattr(job.par, B.PAR_TCDIR)
testcases[step["comp"]] = dirname 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 if arg == "report": # testsuite
basic.program.Job.pushInstance(myjob) #basic.program.Job.pushInstance(myjob)
pass pass
basic.program.Job.pushInstance(myjob) #basic.program.Job.pushInstance(myjob)
setattr(myjob.par, "testcases", testcases) setattr(myjob.par, "testcases", testcases)
# myjob.stopJob(1) # myjob.stopJob(1)
def startStepProgram(step, job, jobargs): def startStepProgram(step, job, jobargs):
myjob = basic.program.Job("unit") # meaning temp myjob = basic.program.Job("unit") # meaning temp
myjob.par.setParameterArgs(jobargs) myjob.par.setParameterArgs(job, jobargs)
myjob.setProgram(step.start) myjob.setProgram(step.start)
myjob.pushInstance(myjob) #myjob.pushInstance(myjob)
myjob.startJob() myjob.startJob()
try: try:
job.m.logInfo(step.start + " starting") job.m.logInfo(step.start + " starting")
@ -112,7 +112,7 @@ def startStepProgram(step, job, jobargs):
job.m.setError(step.start + " aborted") job.m.setError(step.start + " aborted")
finally: finally:
myjob.stopJob(1) myjob.stopJob(1)
myjob.popInstance(myjob) #myjob.popInstance(myjob)
if __name__ == '__main__': if __name__ == '__main__':

3
utils/api_abstract.py

@ -31,7 +31,8 @@ class ApiFcts():
def reset_TData(self, job): def reset_TData(self, job):
pass pass
def setComp(self, comp): def setComp(self, job, comp):
self.job = job
self.comp = comp self.comp = comp
def startCommand(self, comp, args): def startCommand(self, comp, args):

5
utils/config/path.yml

@ -23,6 +23,11 @@ pattern:
postexec: env-post-exec # only for dry unit-test postexec: env-post-exec # only for dry unit-test
debugs: "{job.conf.home}/test/log" debugs: "{job.conf.home}/test/log"
# environment # environment
workbase: "{job.conf.debugs}/workspace"
worklog: "{workbase}/{log}"
workparfile: "{workbase}/PARAMETER_workspace"
workappdir: "{workbase}/{appdir}/{comp.name}"
# environment
envbase: "{job.conf.environment}/{job.par.environment}" envbase: "{job.conf.environment}/{job.par.environment}"
envlog: "{envbase}/{log}" envlog: "{envbase}/{log}"
envparfile: "{envbase}/{parfile}" envparfile: "{envbase}/{parfile}"

14
utils/config_tool.py

@ -41,7 +41,8 @@ def getConfigPath(modul, name, subname="", job=None):
* yaml, json, csv * yaml, json, csv
""" """
if job is None: if job is None:
job = basic.program.Job.getInstance() verify = 24 # job = basic.program.Job.getInstance()
else:
verify = job.getDebugLevel("config_tool")-4 verify = job.getDebugLevel("config_tool")-4
job.debug(verify, "getConfig " + modul + ", " + name) job.debug(verify, "getConfig " + modul + ", " + name)
#TODO path rejoin, config as const #TODO path rejoin, config as const
@ -221,17 +222,20 @@ def hasAttr(o, name):
return False return False
def getConfig(modul, name, subname=""): def getConfig(job, modul, name, subname=""):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
if job is None:
verify = 24
else:
verify = job.getDebugLevel("config_tool")-4 verify = job.getDebugLevel("config_tool")-4
msg = None msg = None
if hasattr(job, "m"): msg = job.m if hasattr(job, "m"): msg = job.m
pathname = getConfigPath(modul, name, subname) pathname = getConfigPath(modul, name, subname, job)
confs = {} confs = {}
job.debug(verify, "getConfig " + pathname) job.debug(verify, "getConfig " + pathname)
if len(pathname) < 1: if len(pathname) < 1:
return confs return confs
doc = utils.file_tool.readFileDict(pathname, msg) doc = utils.file_tool.readFileDict(job, pathname, msg)
if modul == D.DDL_FILENAME: if modul == D.DDL_FILENAME:
# in csv the root is the subname # in csv the root is the subname
# from the Dict-structure of DDL_FILENAME pick the substructure of the subname # from the Dict-structure of DDL_FILENAME pick the substructure of the subname

12
utils/conn_tool.py

@ -9,12 +9,12 @@ import basic.constants as B
import utils.data_const as D import utils.data_const as D
def getConnection(comp, nr): def getConnection(job, comp, nr):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel("conn_tool") verify = job.getDebugLevel("conn_tool")
conn = {} conn = {}
if job.conf.confs.get("tools").get("connsrc") == D.DFILE_TYPE_YML: if job.conf.confs.get("tools").get("connsrc") == D.DFILE_TYPE_YML:
conn = utils.config_tool.getConfig("tool", B.SUBJECT_CONN) conn = utils.config_tool.getConfig(job, "tool", B.SUBJECT_CONN)
xtypes = None xtypes = None
if ("types" in conn["env"][comp]): if ("types" in conn["env"][comp]):
xtypes = conn["env"][comp]["types"] xtypes = conn["env"][comp]["types"]
@ -32,14 +32,14 @@ def getConnection(comp, nr):
return None return None
def getConnections(comp): def getConnections(job, comp):
""" """
it reads the connection-attributes for each instances of this component it reads the connection-attributes for each instances of this component
general attributes are added to the connection-attributes general attributes are added to the connection-attributes
:param comp: :param comp:
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel("conn_tool") verify = job.getDebugLevel("conn_tool")
msg = None msg = None
if hasattr(comp, "m") and comp.m is not None: if hasattr(comp, "m") and comp.m is not None:
@ -52,7 +52,7 @@ def getConnections(comp):
conn = {} conn = {}
conns = [] conns = []
if job.conf.confs.get("tools").get("connsrc") in [D.DFILE_TYPE_YML, D.DFILE_TYPE_JSON, D.DFILE_TYPE_CSV]: if job.conf.confs.get("tools").get("connsrc") in [D.DFILE_TYPE_YML, D.DFILE_TYPE_JSON, D.DFILE_TYPE_CSV]:
conn = utils.config_tool.getConfig("tool", B.SUBJECT_CONN) conn = utils.config_tool.getConfig(job, "tool", B.SUBJECT_CONN)
if not comp in conn["env"]: if not comp in conn["env"]:
job.m.setFatal("Conn-Tool: Comp not configured " + comp) job.m.setFatal("Conn-Tool: Comp not configured " + comp)
elif job.conf.confs.get("tools").get("connsrc") == "flaskdb": elif job.conf.confs.get("tools").get("connsrc") == "flaskdb":

12
utils/css_tool.py

@ -19,8 +19,8 @@ CSS_CLASS = {
} }
} }
def getInlineStyle(filetype, cssclass): def getInlineStyle(job, filetype, cssclass):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("css_tool")) - 1 verify = int(job.getDebugLevel("css_tool")) - 1
# job.debug(verify, "getDiffHeader ") # job.debug(verify, "getDiffHeader ")
if job.conf.confs.get("tools").get("csstyp") == "inline": if job.conf.confs.get("tools").get("csstyp") == "inline":
@ -29,8 +29,8 @@ def getInlineStyle(filetype, cssclass):
out = "class=\"" + cssclass + "\"" out = "class=\"" + cssclass + "\""
return out return out
def getInternalStyle(filetype): def getInternalStyle(job, filetype):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1 verify = int(job.getDebugLevel("match_tool")) - 1
out = "" out = ""
if job.conf.confs.get("tools").get("csstyp") == "internal": if job.conf.confs.get("tools").get("csstyp") == "internal":
@ -55,8 +55,8 @@ def getInternalStyle(filetype):
out += " \n </style>" out += " \n </style>"
return out return out
def getExternalStyle(filetype): def getExternalStyle(job, filetype):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1 verify = int(job.getDebugLevel("match_tool")) - 1
out = "" out = ""
if job.conf.confs.get("tools").get("csstyp") == "external": if job.conf.confs.get("tools").get("csstyp") == "external":

5
utils/db_abstract.py

@ -265,7 +265,8 @@ class DbFcts():
self.comp = None self.comp = None
pass pass
def setComp(self, comp): def setComp(self, job, comp):
self.job = job
self.comp = comp self.comp = comp
def getDbAttributes(self, table): def getDbAttributes(self, table):
@ -355,7 +356,7 @@ class DbFcts():
the ddl are mostly stored as csv in the component-folder """ the ddl are mostly stored as csv in the component-folder """
if (B.DATA_NODE_DDL in self.comp.conf): if (B.DATA_NODE_DDL in self.comp.conf):
return return
conf = utils.config_tool.getConfig(D.DDL_FILENAME, self.comp.name) conf = utils.config_tool.getConfig(job, D.DDL_FILENAME, self.comp.name)
self.comp.conf[B.DATA_NODE_DDL] = {} self.comp.conf[B.DATA_NODE_DDL] = {}
for k in conf[self.comp.name]: for k in conf[self.comp.name]:
self.comp.conf[B.DATA_NODE_DDL][k] = conf[self.comp.name][k] self.comp.conf[B.DATA_NODE_DDL][k] = conf[self.comp.name][k]

14
utils/dbcsv_tool.py

@ -26,10 +26,10 @@ class DbFcts(utils.db_abstract.DbFcts):
statement written in sql """ statement written in sql """
sqlTable = utils.db_abstract.getSqlTable(self.comp, table) sqlTable = utils.db_abstract.getSqlTable(self.comp, table)
header = "" header = ""
path = utils.path_tool.composePattern("{env.dompath}/"+sqlTable+".csv", self.comp) path = utils.path_tool.composePattern(job, "{env.dompath}/"+sqlTable+".csv", self.comp)
print(path) print(path)
tdata = {} tdata = {}
data = utils.tdata_tool.readCsv(self.comp.m, path, self.comp) data = utils.tdata_tool.readCsv(self.comp.m, job, path, self.comp)
tdata[B.DATA_NODE_HEADER] = self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER] tdata[B.DATA_NODE_HEADER] = self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]
if B.DATA_NODE_TABLES in data \ if B.DATA_NODE_TABLES in data \
and table in data[B.DATA_NODE_TABLES]\ and table in data[B.DATA_NODE_TABLES]\
@ -46,12 +46,12 @@ class DbFcts(utils.db_abstract.DbFcts):
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
sqlTable = utils.db_abstract.getSqlTable(self.comp, table) sqlTable = utils.db_abstract.getSqlTable(self.comp, table)
header = "" header = ""
path = utils.path_tool.composePattern("{env.dompath}/"+sqlTable+".csv", self.comp) path = utils.path_tool.composePattern(job, "{env.dompath}/"+sqlTable+".csv", self.comp)
for h in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]: for h in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]:
print(h) print(h)
header += ";"+h header += ";"+h
cmd = header[1:]+"\n" cmd = header[1:]+"\n"
utils.file_tool.writeFileText(self.comp.m, path, cmd) utils.file_tool.writeFileText(self.comp.m, job, path, cmd)
self.comp.m.logInfo(cmd) self.comp.m.logInfo(cmd)
@ -68,7 +68,7 @@ class DbFcts(utils.db_abstract.DbFcts):
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
sqlTable = utils.db_abstract.getSqlTable(self.comp, table) sqlTable = utils.db_abstract.getSqlTable(self.comp, table)
header = "" header = ""
path = utils.path_tool.composePattern("{env.dompath}/"+sqlTable+".csv", self.comp) path = utils.path_tool.composePattern(job, "{env.dompath}/"+sqlTable+".csv", self.comp)
if len(rows) == 0: if len(rows) == 0:
return "" return ""
else: else:
@ -96,14 +96,14 @@ class DbFcts(utils.db_abstract.DbFcts):
rowvalues += ";"+str(self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][h], "")) rowvalues += ";"+str(self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][h], ""))
print("rv " + rowvalues) print("rv " + rowvalues)
cmd += rowvalues+"\n" cmd += rowvalues+"\n"
utils.file_tool.writeFileText(self.comp.m, path, cmd) utils.file_tool.writeFileText(self.comp.m, job, path, cmd)
self.comp.m.logInfo(cmd) self.comp.m.logInfo(cmd)
def getConnector(self): def getConnector(self):
""" add-on-method to get the connector """ add-on-method to get the connector
this method should only called by the class itself """ this method should only called by the class itself """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
return "" return ""

4
utils/dbmysql_tool.py

@ -77,10 +77,10 @@ class DbFcts(utils.db_abstract.DbFcts):
cmd = cmd[0:-1]+";" cmd = cmd[0:-1]+";"
self.comp.m.logInfo(cmd) self.comp.m.logInfo(cmd)
def getConnector(self): def getConnector(self, job):
""" add-on-method to get the connector """ add-on-method to get the connector
this method should only called by the class itself """ this method should only called by the class itself """
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
mydb = mysql.connector.connect( mydb = mysql.connector.connect(
host = "localhost", host = "localhost",
user = "datest", user = "datest",

2
utils/dbrel_tool.py

@ -80,7 +80,7 @@ class DbFcts(utils.db_abstract.DbFcts):
def getConnector(self): def getConnector(self):
""" add-on-method to get the connector """ add-on-method to get the connector
this method should only called by the class itself """ this method should only called by the class itself """
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
mydb = mysql.connector.connect( mydb = mysql.connector.connect(
host = "localhost", host = "localhost",
user = "datest", user = "datest",

8
utils/dbsfile_tool.py

@ -33,7 +33,7 @@ class DbFcts(utils.db_abstract.DbFcts):
# attr = self.getDbAttributes(table) # attr = self.getDbAttributes(table)
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
pattern = "s3a://{hostname}/data/{tenant}/mt/sandboxes/{job.par.usecae}/{job.par.workspace}/{outfile}/VR_+reg+/" pattern = "s3a://{hostname}/data/{tenant}/mt/sandboxes/{job.par.usecae}/{job.par.workspace}/{outfile}/VR_+reg+/"
files = self.comp.composeFileClauses(pattern) files = self.comp.composeFileClauses(job, pattern)
data = [] data = []
for k in files.keys(): for k in files.keys():
sql = files[k] sql = files[k]
@ -57,7 +57,7 @@ class DbFcts(utils.db_abstract.DbFcts):
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
cmd = "DELETE FROM "+table cmd = "DELETE FROM "+table
print("deleteRows "+cmd) print("deleteRows "+cmd)
sqls = self.comp.composeSqlClauses(cmd) sqls = self.comp.composeSqlClauses(job, cmd)
print("deleteRows "+cmd) print("deleteRows "+cmd)
print(sqls) print(sqls)
for k in sqls.keys(): for k in sqls.keys():
@ -74,7 +74,7 @@ class DbFcts(utils.db_abstract.DbFcts):
""" method to insert rows into a database """ method to insert rows into a database
the rows will be interpreted by the ddl of the component the rows will be interpreted by the ddl of the component
""" """
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
spark = self.getConnector() spark = self.getConnector()
df = spark.createDataFrame(rows) df = spark.createDataFrame(rows)
@ -84,7 +84,7 @@ class DbFcts(utils.db_abstract.DbFcts):
def getConnector(self): def getConnector(self):
""" add-on-method to get the connector """ add-on-method to get the connector
this method should only called by the class itself """ this method should only called by the class itself """
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
attr = self.getDbAttributes(B.SVAL_NULL) attr = self.getDbAttributes(B.SVAL_NULL)
spark = None spark = None
if B.ATTR_DB_CONN_JAR in attr: if B.ATTR_DB_CONN_JAR in attr:

8
utils/dbshive_tool.py

@ -34,7 +34,7 @@ class DbFcts(utils.db_abstract.DbFcts):
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
cmd = "SELECT "+",".join(self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]) cmd = "SELECT "+",".join(self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER])
cmd += " FROM "+table cmd += " FROM "+table
sqls = self.comp.composeSqlClauses(cmd) sqls = self.comp.composeSqlClauses(job, cmd)
data = [] data = []
for k in sqls.keys(): for k in sqls.keys():
sql = sqls[k] sql = sqls[k]
@ -61,7 +61,7 @@ class DbFcts(utils.db_abstract.DbFcts):
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
cmd = "DELETE FROM "+table cmd = "DELETE FROM "+table
print("deleteRows "+cmd) print("deleteRows "+cmd)
sqls = self.comp.composeSqlClauses(cmd) sqls = self.comp.composeSqlClauses(job, cmd)
print("deleteRows "+cmd) print("deleteRows "+cmd)
print(sqls) print(sqls)
for k in sqls.keys(): for k in sqls.keys():
@ -78,7 +78,7 @@ class DbFcts(utils.db_abstract.DbFcts):
""" method to insert rows into a database """ method to insert rows into a database
the rows will be interpreted by the ddl of the component the rows will be interpreted by the ddl of the component
""" """
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
spark = self.getConnector() spark = self.getConnector()
df = spark.createDataFrame(rows) df = spark.createDataFrame(rows)
@ -88,7 +88,7 @@ class DbFcts(utils.db_abstract.DbFcts):
def getConnector(self): def getConnector(self):
""" add-on-method to get the connector """ add-on-method to get the connector
this method should only called by the class itself """ this method should only called by the class itself """
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
attr = self.getDbAttributes(B.SVAL_NULL) attr = self.getDbAttributes(B.SVAL_NULL)
spark = None spark = None
if B.ATTR_DB_CONN_JAR in attr: if B.ATTR_DB_CONN_JAR in attr:

6
utils/dbspark_tool.py

@ -42,7 +42,7 @@ class DbFcts(utils.db_abstract.DbFcts):
def deleteRows(self, table): def deleteRows(self, table):
""" method to delete rows from a database """ method to delete rows from a database
statement written in sql """ statement written in sql """
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
cmd = "DELETE FROM "+table+";" cmd = "DELETE FROM "+table+";"
self.comp.m.logInfo(cmd) self.comp.m.logInfo(cmd)
@ -51,7 +51,7 @@ class DbFcts(utils.db_abstract.DbFcts):
""" method to insert rows into a database """ method to insert rows into a database
the rows will be interpreted by the ddl of the component the rows will be interpreted by the ddl of the component
""" """
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
verify = -1+job.getDebugLevel("db_tool") verify = -1+job.getDebugLevel("db_tool")
spark = self.getConnector() spark = self.getConnector()
df = spark.createDataFrame(rows) df = spark.createDataFrame(rows)
@ -61,7 +61,7 @@ class DbFcts(utils.db_abstract.DbFcts):
def getConnector(self): def getConnector(self):
""" add-on-method to get the connector """ add-on-method to get the connector
this method should only called by the class itself """ this method should only called by the class itself """
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
spark = pyspark.SparkSession\ spark = pyspark.SparkSession\
.builder\ .builder\
.appName("datest")\ .appName("datest")\

30
utils/env_tool.py

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

18
utils/file_abstract.py

@ -54,14 +54,14 @@ class FileFcts():
pattern = "" pattern = ""
utils.file_tool.copyFiles(self.job, fileList, srcpath, envpath, pattern) utils.file_tool.copyFiles(self.job, fileList, srcpath, envpath, pattern)
def readEnvFiles(self): def readEnvFiles(self, job):
envpath = "" envpath = ""
pattern = "" pattern = ""
fileList = utils.file_tool.getFiles(self.comp.m, envpath, pattern, self.comp.conf["conn"]) fileList = utils.file_tool.getFiles(self.comp.m, job, envpath, pattern, self.comp.conf["conn"])
# === execute_testcase === # === execute_testcase ===
def create_request(self, tdata, step): def create_request(self, job, tdata, step):
mapping = "" mapping = ""
schema = "" schema = ""
archivpath = "" archivpath = ""
@ -72,28 +72,28 @@ class FileFcts():
continue continue
mapping = o["mapping"] mapping = o["mapping"]
schema = o["schema"] schema = o["schema"]
archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/request", self.comp), filename) # ergebnisse/comp/request ) archivpath = os.path.join(utils.path_tool.composePattern(job, "{tcresult}/request", self.comp), filename) # ergebnisse/comp/request )
#txt = self.createDict() #txt = self.createDict()
utils.file_tool.writeFileText(self.comp.m, archivpath, txt) utils.file_tool.writeFileText(self.comp.m, job, archivpath, txt)
def send_request(self, job, step): def send_request(self, job, step):
archivpath = "" archivpath = ""
filename = step.args["filename"] filename = step.args["filename"]
technique = step.args["technique"] technique = step.args["technique"]
archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/request", self.comp), filename) archivpath = os.path.join(utils.path_tool.composePattern(job, "{tcresult}/request", self.comp), filename)
if technique == "cli": if technique == "cli":
for o in self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_FILE]: for o in self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_FILE]:
if o["name"] != filename: if o["name"] != filename:
continue continue
envpath = o["envpath"] envpath = o["envpath"]
envpath = utils.path_tool.composePattern(envpath, self.comp) envpath = utils.path_tool.composePattern(job, envpath, self.comp)
fct = basic.toolHandling.getCliTool(job, self.comp) fct = basic.toolHandling.getCliTool(job, self.comp)
fct.copy(self.job, archivpath, envpath) fct.copy(self.job, archivpath, envpath)
elif technique == "api": elif technique == "api":
txt = utils.file_tool.readFileText(archivpath, self.comp.m) txt = utils.file_tool.readFileText(job, archivpath, self.comp.m)
fct = basic.toolHandling.getApiTool(job, self.comp) fct = basic.toolHandling.getApiTool(job, self.comp)
response = fct.send(self.job, self.comp, txt) response = fct.send(self.job, self.comp, txt)
archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/response", self.comp), filename) archivpath = os.path.join(utils.path_tool.composePattern(job, "{tcresult}/response", self.comp), filename)
""" """
get_response: get_response:

56
utils/file_tool.py

@ -26,7 +26,7 @@ def getDump(obj):
# if type(obj) == "__dict__" # if type(obj) == "__dict__"
def getFiles(msg, path, pattern, conn): def getFiles(msg, job, path, pattern, conn):
""" """
search filenames in the directory - if conn is set search remote search filenames in the directory - if conn is set search remote
:param msg: -- msg-Objekt :param msg: -- msg-Objekt
@ -37,7 +37,7 @@ def getFiles(msg, path, pattern, conn):
""" """
if conn is not None: if conn is not None:
return getRemoteFiles(msg, path, pattern, conn) return getRemoteFiles(msg, path, pattern, conn)
job = basic.program.Job.getInstance() # job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
out = [] out = []
msg.debug(verify, "getFiles " + path + " , " + pattern) msg.debug(verify, "getFiles " + path + " , " + pattern)
@ -89,7 +89,7 @@ def getRemoteFiles(msg, path, pattern, conn):
pass pass
def getFilesRec(msg, path, pattern): def getFilesRec(msg, job, path, pattern):
""" """
Sucht Dateien im Verzeichnis rekursiv Sucht Dateien im Verzeichnis rekursiv
:param msg: -- msg-Objekt :param msg: -- msg-Objekt
@ -97,7 +97,7 @@ def getFilesRec(msg, path, pattern):
:param pattern: -- Dateiname als Pattern :param pattern: -- Dateiname als Pattern
:return: Array mit gefundenen Dateien, absoluter Pfad :return: Array mit gefundenen Dateien, absoluter Pfad
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
out = [] out = []
msg.debug(verify, "getFilesRec " + path + " , " + pattern) msg.debug(verify, "getFilesRec " + path + " , " + pattern)
@ -110,23 +110,23 @@ def getFilesRec(msg, path, pattern):
return out return out
def getTree(msg, pfad): def getTree(msg, job, pfad):
job = basic.program.Job.getInstance() # job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
msg.debug(verify, "getTree " + pfad ) msg.debug(verify, "getTree " + pfad )
tree = {} tree = {}
files = [] files = []
for f in os.listdir(pfad): for f in os.listdir(pfad):
if os.path.isDir(os.path.join(pfad, f)): if os.path.isDir(os.path.join(pfad, f)):
tree[f] = getTree(msg, os.path.join(pfad, f)) tree[f] = getTree(msg, job, os.path.join(pfad, f))
elif os.path.isFile(os.path.join(pfad, f)): elif os.path.isFile(os.path.join(pfad, f)):
files.append(f) files.append(f)
tree["_files_"] = files tree["_files_"] = files
return tree return tree
def mkPaths(path, msg): def mkPaths(job, path, msg):
job = basic.program.Job.getInstance() # job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
modus = job.conf.confs["paths"]["mode"] modus = job.conf.confs["paths"]["mode"]
dirname = os.path.dirname(path) dirname = os.path.dirname(path)
@ -135,7 +135,7 @@ def mkPaths(path, msg):
os.makedirs(dirname, exist_ok=True) os.makedirs(dirname, exist_ok=True)
def getFileEncoding(msg, path): def getFileEncoding(msg, job, path):
print("--- getFileEncoding "+path) print("--- getFileEncoding "+path)
encodings = ['utf-8', 'iso-8859-1'] # add more encodings = ['utf-8', 'iso-8859-1'] # add more
for e in encodings: for e in encodings:
@ -151,11 +151,11 @@ def getFileEncoding(msg, path):
else: else:
print('opening the file with encoding: %s ' % e) print('opening the file with encoding: %s ' % e)
return e return e
return detectFileEncode(path, msg) return detectFileEncode(job, path, msg)
def detectFileEncode(path, msg): # return "" def detectFileEncode(job, path, msg): # return ""
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
print(path) print(path)
cntIso = 0 cntIso = 0
@ -182,26 +182,26 @@ def detectFileEncode(path, msg): # return ""
return 'utf-8' return 'utf-8'
def readFileLines(path, msg): def readFileLines(job, path, msg):
lines = readFileText(path, msg) lines = readFileText(job, path, msg)
if isinstance(lines, (str)): if isinstance(lines, (str)):
return lines.splitlines() return lines.splitlines()
return [] return []
def readFileText(path, msg): def readFileText(job, path, msg):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
if not os.path.exists(path): if not os.path.exists(path):
return "" return ""
enc = detectFileEncode(path, msg) enc = detectFileEncode(job, path, msg)
with open(path, 'r', encoding=enc) as file: with open(path, 'r', encoding=enc) as file:
text = file.read() text = file.read()
file.close() file.close()
return text return text
def readFileDict(path, msg): def readFileDict(job, path, msg):
""" """
reads and gets general a dict from any kind of filetyp reads and gets general a dict from any kind of filetyp
:param path: with extension of filetype :param path: with extension of filetype
@ -209,12 +209,12 @@ def readFileDict(path, msg):
:return: :return:
""" """
# 20220329 generalize # 20220329 generalize
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
doc = {} doc = {}
if not os.path.exists(path): if not os.path.exists(path):
return doc return doc
enc = detectFileEncode(path, msg) enc = detectFileEncode(job, path, msg)
if D.DFILE_TYPE_YML in path[-4:]: if D.DFILE_TYPE_YML in path[-4:]:
with open(path, 'r', encoding=enc) as file: with open(path, 'r', encoding=enc) as file:
doc = yaml.full_load(file) doc = yaml.full_load(file)
@ -230,7 +230,7 @@ def readFileDict(path, msg):
doc = castOrderedDict(res) doc = castOrderedDict(res)
file.close() file.close()
elif D.DFILE_TYPE_CSV in path[-5:]: elif D.DFILE_TYPE_CSV in path[-5:]:
doc = utils.tdata_tool.getCsvSpec(msg, path, D.CSV_SPECTYPE_CONF) doc = utils.tdata_tool.getCsvSpec(msg, job, path, D.CSV_SPECTYPE_CONF)
return doc return doc
def castOrderedDict(res, job=None, key=""): def castOrderedDict(res, job=None, key=""):
@ -248,18 +248,18 @@ def castOrderedDict(res, job=None, key=""):
return doc return doc
def writeFileText(msg, path, text, enc="utf-8"): def writeFileText(msg, job, path, text, enc="utf-8"):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("file_tool")) verify = int(job.getDebugLevel("file_tool"))
mkPaths(path, msg) mkPaths(job, path, msg)
with open(path, 'w', encoding=enc) as file: with open(path, 'w', encoding=enc) as file:
file.write(text) file.write(text)
file.close() file.close()
def writeFileDict(msg, path, dict, enc="utf-8"): def writeFileDict(msg, job, path, dict, enc="utf-8"):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
mkPaths(path, msg) mkPaths(job, path, msg)
if D.DFILE_TYPE_YML in path[-5:]: if D.DFILE_TYPE_YML in path[-5:]:
with open(path, 'w', encoding=enc) as file: with open(path, 'w', encoding=enc) as file:
yaml.dump(dict, file) yaml.dump(dict, file)

5
utils/flask_tool.py

@ -0,0 +1,5 @@
#!/usr/bin/python
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------

10
utils/i18n_tool.py

@ -25,7 +25,7 @@ class I18n:
def __init__(self): def __init__(self):
self.cache = {} self.cache = {}
self.cache = utils.config_tool.getConfig(P.KEY_TOOL, "i18n") self.cache = utils.config_tool.getConfig(None, P.KEY_TOOL, "i18n")
I18n.__instance = self I18n.__instance = self
pass pass
@ -43,15 +43,13 @@ class I18n:
out = out.format(args) out = out.format(args)
return out return out
def getText(self, key, job=None): def getText(self, key, job):
""" """
this function gets the text depending on language which is set in job.conf this function gets the text depending on language which is set in job.conf
:param key: MUST GIVEN WITH (f"{CONST=}", .. :param key: MUST GIVEN WITH (f"{CONST=}", ..
:return: :return:
return self.cache[language][key] return self.cache[language][key]
""" """
if job is None:
job = basic.program.Job.getInstance()
if "language" in job.conf.confs: if "language" in job.conf.confs:
language = job.conf.confs["language"] language = job.conf.confs["language"]
else: else:
@ -67,9 +65,7 @@ class I18n:
out = self.cache[DEFAULT_LANGUAGE][key] out = self.cache[DEFAULT_LANGUAGE][key]
return out return out
def getAliasList(self, key, job=None): def getAliasList(self, key, job):
if job is None:
jon = basic.program.Job.getInstance()
out = [] out = []
out.append(self.extractText(key)) out.append(self.extractText(key))
key = self.extractKey(key) key = self.extractKey(key)

6
utils/job_tool.py

@ -21,11 +21,11 @@
""" """
from basic.program import Job from basic.program import Job
def hasModul(komp): def hasModul(komp):
job = Job.getInstance() #job = Job.getInstance()
return False return False
def hasFunction(fct): def hasFunction(fct):
job = Job.getInstance() #job = Job.getInstance()
return False return False
def hasTool(tool): def hasTool(tool):
job = Job.getInstance() #job = Job.getInstance()
return False return False

53
utils/match_tool.py

@ -19,7 +19,8 @@ import utils.data_const as D
class Matching(): class Matching():
def __init__(self, comp): def __init__(self, job, comp):
self.job = job
self.comp = comp self.comp = comp
self.elements = {} self.elements = {}
self.matchfiles = {} self.matchfiles = {}
@ -101,13 +102,13 @@ class Matching():
return ddl return ddl
def setDiffHeader(matching): def setDiffHeader(matching):
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1 verify = int(job.getDebugLevel("match_tool")) - 1
job.debug(verify, "getDiffHeader ") job.debug(verify, "getDiffHeader ")
htmltxt = "<!DOCTYPE html>" htmltxt = "<!DOCTYPE html>"
htmltxt += "<html><head>" htmltxt += "<html><head>"
htmltxt += "<title>" + M.MATCH[matching.matchtype]["title"] + "</title>" htmltxt += "<title>" + M.MATCH[matching.matchtype]["title"] + "</title>"
htmltxt += utils.css_tool.getInternalStyle("diffFiles") htmltxt += utils.css_tool.getInternalStyle(job, "diffFiles")
htmltxt += "</head>" htmltxt += "</head>"
htmltxt += "<body>" htmltxt += "<body>"
htmltxt += "<h1>" + M.MATCH[matching.matchtype]["title"] + "</h1>" htmltxt += "<h1>" + M.MATCH[matching.matchtype]["title"] + "</h1>"
@ -118,7 +119,7 @@ class Matching():
matching.htmltext = htmltxt matching.htmltext = htmltxt
def setDiffFooter(self): def setDiffFooter(self):
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 4 verify = int(job.getDebugLevel("match_tool")) - 4
job.debug(verify, "getDiffFooter ") job.debug(verify, "getDiffFooter ")
htmltext = self.htmltext htmltext = self.htmltext
@ -204,7 +205,7 @@ def matchBestfit(matching, path):
def matchRestfit(matching): def matchRestfit(matching):
""" """ """ """
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1 verify = int(job.getDebugLevel("match_tool")) - 1
job.debug(verify, "matchRestfit ") job.debug(verify, "matchRestfit ")
for x in sorted(matching.nomatch, reverse=True): for x in sorted(matching.nomatch, reverse=True):
@ -231,7 +232,7 @@ def extractKeyI(key):
def setMatchkeys(matching, path): def setMatchkeys(matching, path):
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1 verify = int(job.getDebugLevel("match_tool")) - 1
job.debug(verify, "getSimilarity " + path) job.debug(verify, "getSimilarity " + path)
if len(matching.matchkeys) > 0: if len(matching.matchkeys) > 0:
@ -269,7 +270,7 @@ def setMatchkeys(matching, path):
def getSimilarity(matching, rA, rB, i, simorder=M.SIM_DEFAULT): def getSimilarity(matching, rA, rB, i, simorder=M.SIM_DEFAULT):
""" it calculates the similarity between both rows by: """ it calculates the similarity between both rows by:
concat each criteria with single-similarity 00..99 and i with 999..000 """ concat each criteria with single-similarity 00..99 and i with 999..000 """
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1 verify = int(job.getDebugLevel("match_tool")) - 1
job.debug(verify, "getSimilarity ") job.debug(verify, "getSimilarity ")
mBsim = "" mBsim = ""
@ -282,14 +283,14 @@ def getSimilarity(matching, rA, rB, i, simorder=M.SIM_DEFAULT):
continue continue
if M.SIM_TECHNICAL in k: if M.SIM_TECHNICAL in k:
if matching.matchkeys[k][D.DDL_FNAME] in rA and matching.matchkeys[k][D.DDL_FNAME] in rB: if matching.matchkeys[k][D.DDL_FNAME] in rA and matching.matchkeys[k][D.DDL_FNAME] in rB:
mTsim += getStringSimilarity(str(rA[matching.matchkeys[k][D.DDL_FNAME]]), mTsim += getStringSimilarity(job, str(rA[matching.matchkeys[k][D.DDL_FNAME]]),
str(rB[matching.matchkeys[k][D.DDL_FNAME]])) str(rB[matching.matchkeys[k][D.DDL_FNAME]]))
else: else:
mTsim += "00" mTsim += "00"
topTsim += "99" topTsim += "99"
if M.SIM_BUSINESS in k: if M.SIM_BUSINESS in k:
if matching.matchkeys[k][D.DDL_FNAME] in rA and matching.matchkeys[k][D.DDL_FNAME] in rB: if matching.matchkeys[k][D.DDL_FNAME] in rA and matching.matchkeys[k][D.DDL_FNAME] in rB:
mBsim += getStringSimilarity(str(rA[matching.matchkeys[k][D.DDL_FNAME]]), mBsim += getStringSimilarity(job, str(rA[matching.matchkeys[k][D.DDL_FNAME]]),
str(rB[matching.matchkeys[k][D.DDL_FNAME]])) str(rB[matching.matchkeys[k][D.DDL_FNAME]]))
else: else:
mBsim += "55" mBsim += "55"
@ -315,7 +316,7 @@ def matchTree(matching):
:param matching: :param matching:
:return: :return:
""" """
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 4 verify = int(job.getDebugLevel("match_tool")) - 4
job.debug(verify, "..>> start matching " + matching.mode) job.debug(verify, "..>> start matching " + matching.mode)
matchElement(matching, matching.sideA, matching.sideB, "") matchElement(matching, matching.sideA, matching.sideB, "")
@ -326,7 +327,7 @@ def matchTree(matching):
def matchElement(matching, A, B, path): def matchElement(matching, A, B, path):
""" travers through the datatree """ """ travers through the datatree """
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 4 verify = int(job.getDebugLevel("match_tool")) - 4
job.debug(verify, "matchElem " + path + " A " + str(type(A)) + " B " + str(type(B))) job.debug(verify, "matchElem " + path + " A " + str(type(A)) + " B " + str(type(B)))
if ((A is not None) and (isinstance(A, list))) \ if ((A is not None) and (isinstance(A, list))) \
@ -339,8 +340,8 @@ def matchElement(matching, A, B, path):
return matching return matching
def getStringSimilarity(strA, strB): def getStringSimilarity(job, strA, strB):
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1 verify = int(job.getDebugLevel("match_tool")) - 1
job.debug(verify, "getStringSimilarity " + strA + " ?= " + strB) job.debug(verify, "getStringSimilarity " + strA + " ?= " + strB)
if (strA == strB): return "99" if (strA == strB): return "99"
@ -351,10 +352,10 @@ def getStringSimilarity(strA, strB):
def getEvaluation(matching, type, acceptance, sideA, sideB): def getEvaluation(matching, type, acceptance, sideA, sideB):
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1 verify = int(job.getDebugLevel("match_tool")) - 1
job.debug(verify, "getEvaluation " + str(sideA) + " ?= " + str(sideB)) job.debug(verify, "getEvaluation " + str(sideA) + " ?= " + str(sideB))
match = getStringSimilarity(str(sideA), str(sideB)) match = getStringSimilarity(job, str(sideA), str(sideB))
classA = "novalue" classA = "novalue"
classB = "novalue" classB = "novalue"
result = "test" result = "test"
@ -372,7 +373,7 @@ def getEvaluation(matching, type, acceptance, sideA, sideB):
def matchDict(matching, sideA, sideB, path): def matchDict(matching, sideA, sideB, path):
""" travers through the datatree """ """ travers through the datatree """
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 4 verify = int(job.getDebugLevel("match_tool")) - 4
job.debug(verify, "matchDict " + path) job.debug(verify, "matchDict " + path)
if (sideA is not None): if (sideA is not None):
@ -406,7 +407,7 @@ def matchDict(matching, sideA, sideB, path):
def matchArray(matching, sideA, sideB, path): def matchArray(matching, sideA, sideB, path):
""" matches the datarows of the datatree """ """ matches the datarows of the datatree """
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 4 verify = int(job.getDebugLevel("match_tool")) - 4
job.debug(verify, "matchArray " + path + "\n.." + matching.htmltext) job.debug(verify, "matchArray " + path + "\n.." + matching.htmltext)
matching.sideA = sideA matching.sideA = sideA
@ -431,7 +432,7 @@ def matchArray(matching, sideA, sideB, path):
def compareRows(matching, path): def compareRows(matching, path):
""" traverse through matched rows """ """ traverse through matched rows """
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 1 verify = int(job.getDebugLevel("match_tool")) - 1
ddl = matching.getTableDdl(path) ddl = matching.getTableDdl(path)
report = utils.report_tool.Report.getInstance() report = utils.report_tool.Report.getInstance()
@ -465,7 +466,7 @@ def compareRows(matching, path):
def markRow(matching, header, row, side): def markRow(matching, header, row, side):
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 4 verify = int(job.getDebugLevel("match_tool")) - 4
text = "" text = ""
cssClass = "" cssClass = ""
@ -481,8 +482,8 @@ def markRow(matching, header, row, side):
res = getEvaluation(matching, f[D.DDL_TYPE], f[D.DDL_ACCEPTANCE], "", row[f[D.DDL_FNAME]]) res = getEvaluation(matching, f[D.DDL_TYPE], f[D.DDL_ACCEPTANCE], "", row[f[D.DDL_FNAME]])
val = str(row[f[D.DDL_FNAME]]) val = str(row[f[D.DDL_FNAME]])
cssClass = res[2] cssClass = res[2]
text += "<td " + utils.css_tool.getInlineStyle("diffFiles", cssClass) + ">" + val + "</td>" text += "<td " + utils.css_tool.getInlineStyle(job, "diffFiles", cssClass) + ">" + val + "</td>"
text = "<tr><td " + utils.css_tool.getInlineStyle("diffFiles", cssClass) + ">" \ text = "<tr><td " + utils.css_tool.getInlineStyle(job, "diffFiles", cssClass) + ">" \
+ M.MATCH[M.MATCH[matching.matchtype][side]]["short"] + "</td>" + text + "</tr>" + M.MATCH[M.MATCH[matching.matchtype][side]]["short"] + "</td>" + text + "</tr>"
matching.difftext += text matching.difftext += text
return text return text
@ -490,7 +491,7 @@ def markRow(matching, header, row, side):
def compareRow(matching, header, rA, rB): def compareRow(matching, header, rA, rB):
""" traverse through matched rows """ """ traverse through matched rows """
job = basic.program.Job.getInstance() job = matching.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 4 verify = int(job.getDebugLevel("match_tool")) - 4
allident = True allident = True
textA = "" textA = ""
@ -529,13 +530,13 @@ def compareRow(matching, header, rA, rB):
matching.setCssClass("result1") matching.setCssClass("result1")
elif (match == "hard"): elif (match == "hard"):
allident = False allident = False
textA += "<td " + utils.css_tool.getInlineStyle("diffFiles", classA) + ">" + valA + "</td>" textA += "<td " + utils.css_tool.getInlineStyle(job, "diffFiles", classA) + ">" + valA + "</td>"
textB += "<td " + utils.css_tool.getInlineStyle("diffFiles", classB) + ">" + valB + "</td>" textB += "<td " + utils.css_tool.getInlineStyle(job, "diffFiles", classB) + ">" + valB + "</td>"
matching.setCssClass("result3") matching.setCssClass("result3")
else: else:
allident = False allident = False
textA += "<td " + utils.css_tool.getInlineStyle("diffFiles", classA) + ">" + valA + " (" + match + ")</td>" textA += "<td " + utils.css_tool.getInlineStyle(job, "diffFiles", classA) + ">" + valA + " (" + match + ")</td>"
textB += "<td " + utils.css_tool.getInlineStyle("diffFiles", classB) + ">" + valB + " (" + match + ")</td>" textB += "<td " + utils.css_tool.getInlineStyle(job, "diffFiles", classB) + ">" + valB + " (" + match + ")</td>"
matching.setCssClass("result1") matching.setCssClass("result1")
if allident: if allident:
return "<tr><td/>" + textA + "</tr>" return "<tr><td/>" + textA + "</tr>"

59
utils/path_tool.py

@ -15,14 +15,41 @@ import utils.path_const as P
TOOL_NAME = "path_tool" TOOL_NAME = "path_tool"
def getKeyValue(key, comp=None): def getHome():
home = os.getcwd()
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]
return home
def getBasisConfigPath():
home = os.getcwd()
a = home.split(os.path.sep)
for i in range(0, len(a)):
path = os.path.sep.join(a[0:-i])
path = os.path.join(path, "config", B.BASIS_FILE)
for format in utils.config_tool.CONFIG_FORMAT:
path += "."+format
if os.path.exists(path):
return path
def getKeyValue(job, key, comp=None):
""" """
this function gets the value for the key which relates to an attribute in the job or in the component this function gets the value for the key which relates to an attribute in the job or in the component
:param key: :param key:
:param comp: :param comp:
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(TOOL_NAME)-4 verify = job.getDebugLevel(TOOL_NAME)-4
pt = PathConf.getInstance() pt = PathConf.getInstance()
job.debug(verify, "getKeyValue " + key) job.debug(verify, "getKeyValue " + key)
@ -53,7 +80,7 @@ def getKeyValue(key, comp=None):
return "xx-"+key+"-xx" return "xx-"+key+"-xx"
def composePath(pathname, comp): def composePath(job, pathname, comp):
""" """
this function composes a concrete path by the structured pathname 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. - the key of pathname is declared in path_const and the structure is configurated in config/path.yml.
@ -61,18 +88,18 @@ def composePath(pathname, comp):
:param comp: :param comp:
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(TOOL_NAME) 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))
if pt.pattern[pathname]: if pt.pattern[pathname]:
return composePattern(pt.pattern[pathname], comp) return composePattern(job, pt.pattern[pathname], comp)
else: else:
job.debug(verify, "in Pattern nicht vorhanden: " + pathname) job.debug(verify, "in Pattern nicht vorhanden: " + pathname)
def composePattern(pattern, comp): def composePattern(job, pattern, comp):
""" """
the function composes the pattern to the standardarized path with the attributes the function composes the pattern to the standardarized path with the attributes
which are stored in the job and the component which are stored in the job and the component
@ -81,23 +108,23 @@ def composePattern(pattern, comp):
:param comp: :param comp:
:return: path :return: path
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(TOOL_NAME) verify = job.getDebugLevel(TOOL_NAME)
verbose = False verbose = True
job.debug(verify, "composePattern " + pattern) job.debug(verify, "composePattern " + pattern)
max=5 max=5
l = re.findall('\{.*?\}', pattern) l = re.findall('\{.*?\}', pattern)
job.debug(verify, l) job.debug(verify, l)
for pat in l: for pat in l:
if verbose: print(str(max) + ": " + pattern + ": " + pat) if verbose: print(str(max) + ": " + pattern + ": " + pat)
pit = getKeyValue(pat[1:-1], comp) pit = getKeyValue(job, pat[1:-1], comp)
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit) job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
pattern = pattern.replace(pat, pit) pattern = pattern.replace(pat, pit)
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit) job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
while ("{" in pattern): while ("{" in pattern):
max = max-1 max = max-1
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit) job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
pattern = composePattern(pattern, comp) pattern = composePattern(job, pattern, comp)
job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit) job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit)
if (max < 3) : if (max < 3) :
break break
@ -149,7 +176,7 @@ def rejoinPath(a, b="", c="", d="", e="", f=""):
return out return out
def extractPattern(pathtyp, comp=None): def extractPattern(job, pathtyp, comp=None):
""" """
this function extracts recoursively all parts of the pathstrucure as key and gets the values from the this function extracts recoursively all parts of the pathstrucure as key and gets the values from the
job-parameter and job-configuration job-parameter and job-configuration
@ -157,7 +184,7 @@ def extractPattern(pathtyp, comp=None):
:param comp: :param comp:
:return: dictionary of all part (key) with their valuess :return: dictionary of all part (key) with their valuess
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
verify = job.getDebugLevel(TOOL_NAME) verify = job.getDebugLevel(TOOL_NAME)
out = [] out = []
pt = PathConf.getInstance() pt = PathConf.getInstance()
@ -169,13 +196,13 @@ def extractPattern(pathtyp, comp=None):
pre = work[0:i] pre = work[0:i]
pat = work[i+1:j] pat = work[i+1:j]
job.debug(verify, work + " von " + str(i) + "-" + str(j) + " pre " + pre + "pat " + pat) job.debug(verify, work + " von " + str(i) + "-" + str(j) + " pre " + pre + "pat " + pat)
pit = getKeyValue(pat, comp) pit = getKeyValue(job, pat, comp)
tup = (pre, pat, pit) tup = (pre, pat, pit)
out.append(tup) out.append(tup)
work = work[j+1:] work = work[j+1:]
return out return out
def extractPath(pathtyp, path): def extractPath(job, pathtyp, path):
""" """
this function extracts parts of a concrete structered path and stores the parts 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 as attributes into the actual job. So these attributes can read from the concrete
@ -185,7 +212,7 @@ def extractPath(pathtyp, path):
:param path: the concrete path - it should be the directory in the parameter of the job :param path: the concrete path - it should be the directory in the parameter of the job
:return: :return:
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
patterlist = extractPattern(pathtyp) patterlist = extractPattern(pathtyp)
verbose = False verbose = False
work = path work = path
@ -245,7 +272,7 @@ class PathConf:
__instance = None __instance = None
def __init__(self): def __init__(self):
print('init pathConf') print('init pathConf')
confs = utils.config_tool.getConfig("tool", "path") confs = utils.config_tool.getConfig(None, "tool", "path")
self.pattern = confs["pattern"] self.pattern = confs["pattern"]
print(self.pattern) print(self.pattern)
PathConf.__instance = self PathConf.__instance = self

29
utils/report_tool.py

@ -48,7 +48,7 @@ class Report:
else: else:
return Report() return Report()
def __init__(self): def __init__(self, job):
""" """
:param report: matchtype :param report: matchtype
:param comp: optional on matching :param comp: optional on matching
@ -68,7 +68,8 @@ class Report:
paths : p with links to row-results paths : p with links to row-results
matching : table complete match for artefact-result resp. only diff for other matches matching : table complete match for artefact-result resp. only diff for other matches
""" """
job = basic.program.Job.getInstance() #job = basic.program.Job.getInstance()
self.job = job
self.report = {} self.report = {}
self.report["testcases"] = [] self.report["testcases"] = []
self.testcase = "" self.testcase = ""
@ -99,7 +100,7 @@ class Report:
self.report[testcase][component][artefact][matchtype]["diff"] = diffTable self.report[testcase][component][artefact][matchtype]["diff"] = diffTable
def getTitle(self, testcase="", component="", artefact="", matchtype=""): def getTitle(self, testcase="", component="", artefact="", matchtype=""):
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
if len(matchtype) > 1: if len(matchtype) > 1:
html = "<title>"+M.MATCH[matchtype]["title"]+"</title></head><body><h1>"+M.MATCH[matchtype]["title"]+"</h1>" html = "<title>"+M.MATCH[matchtype]["title"]+"</title></head><body><h1>"+M.MATCH[matchtype]["title"]+"</h1>"
elif len(testcase) > 1: elif len(testcase) > 1:
@ -154,11 +155,11 @@ class Report:
return cssClass return cssClass
def getHeader(self): def getHeader(self):
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel(TOOL_NAME))-1 verify = int(job.getDebugLevel(TOOL_NAME))-1
htmltxt = "<!DOCTYPE html>" htmltxt = "<!DOCTYPE html>"
htmltxt += "<html><head>" htmltxt += "<html><head>"
htmltxt += utils.css_tool.getInternalStyle("diffFiles") htmltxt += utils.css_tool.getInternalStyle(job, "diffFiles")
return htmltxt return htmltxt
def getOverviewHead(self, testcase=""): def getOverviewHead(self, testcase=""):
@ -189,18 +190,18 @@ class Report:
return html return html
def getComponentHead(self, testcase="", component="", artefact="", matchtype=""): def getComponentHead(self, testcase="", component="", artefact="", matchtype=""):
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
html = "<h2 id=\""+testcase+"_"+component+"\">"+REP_COMP+" "+component+"</h2>" html = "<h2 id=\""+testcase+"_"+component+"\">"+REP_COMP+" "+component+"</h2>"
return html return html
def getArtefactBlock(self, testcase, component, artefact, matchtype=""): def getArtefactBlock(self, testcase, component, artefact, matchtype=""):
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
html = "<h3>"+REP_ART+" "+artefact+"</h3><p>" html = "<h3>"+REP_ART+" "+artefact+"</h3><p>"
for match in self.report[testcase][component][artefact]: for match in self.report[testcase][component][artefact]:
cssClass = self.getCssClass(testcase, component, artefact, match) cssClass = self.getCssClass(testcase, component, artefact, match)
path = self.getFilepath(testcase, component, artefact, match) path = self.getFilepath(testcase, component, artefact, match)
path = path.replace(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], os.path.join("..", "..")) path = path.replace(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], os.path.join("..", ".."))
html += " <a href=\""+path+"\" "+utils.css_tool.getInlineStyle("resultFile", cssClass)+">"+M.MATCH[match]["filename"]+"<a> " html += " <a href=\""+path+"\" "+utils.css_tool.getInlineStyle(job, "resultFile", cssClass)+">"+M.MATCH[match]["filename"]+"<a> "
html += "</p>" html += "</p>"
if len(matchtype) < 1: if len(matchtype) < 1:
matchtype = M.MATCH_POSTCOND matchtype = M.MATCH_POSTCOND
@ -217,7 +218,7 @@ class Report:
def getFilepath(self, testcase, component, artefact, matchtype): def getFilepath(self, testcase, component, artefact, matchtype):
cm = basic.componentHandling.ComponentManager.getInstance("init") cm = basic.componentHandling.ComponentManager.getInstance("init")
comp = cm.getComponent(component) comp = cm.getComponent(component)
path = os.path.join(utils.path_tool.composePattern("{tcresult}", comp), artefact+"_"+M.MATCH[matchtype]["filename"]+".html") path = os.path.join(utils.path_tool.composePattern(self.job, "{tcresult}", comp), artefact+"_"+M.MATCH[matchtype]["filename"]+".html")
return path return path
def getComparisonBlock(self, testcase, component, artefact, matchtype): def getComparisonBlock(self, testcase, component, artefact, matchtype):
@ -225,7 +226,7 @@ class Report:
return html return html
def reportTestcase(self, testcase): def reportTestcase(self, testcase):
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel(TOOL_NAME)) - 1 verify = int(job.getDebugLevel(TOOL_NAME)) - 1
html = self.getHeader() html = self.getHeader()
html += self.getTitle(testcase) html += self.getTitle(testcase)
@ -242,7 +243,7 @@ class Report:
return html return html
def extractTestcase(self, testcase, html): def extractTestcase(self, testcase, html):
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel(TOOL_NAME)) - 1 verify = int(job.getDebugLevel(TOOL_NAME)) - 1
if not testcase in self.report: if not testcase in self.report:
self.report = {} self.report = {}
@ -256,7 +257,7 @@ class Report:
self.report[testcase]["block"] = block self.report[testcase]["block"] = block
def reportTestsuite(self): def reportTestsuite(self):
job = basic.program.Job.getInstance() job = self.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel(TOOL_NAME)) - 1 verify = int(job.getDebugLevel(TOOL_NAME)) - 1
testinstances = getattr(job.par, B.PAR_TESTCASES) testinstances = getattr(job.par, B.PAR_TESTCASES)
html = self.getHeader() html = self.getHeader()
@ -273,13 +274,13 @@ class Report:
return html return html
def report_testsuite(tcpath): def report_testsuite(job, tcpath):
""" """
creates header creates header
:param tcpath: :param tcpath:
:return: html-code with result-codes of each component :return: html-code with result-codes of each component
""" """
job = basic.program.Job.getInstance() # job = basic.program.Job.getInstance()
verify = -0+job.getDebugLevel(TOOL_NAME) verify = -0+job.getDebugLevel(TOOL_NAME)
job.debug(verify, "writeDataTable " + str(tcpath)) job.debug(verify, "writeDataTable " + str(tcpath))

44
utils/tdata_tool.py

@ -28,8 +28,6 @@ def getTestdata(job=None):
for the testcase resp testsuite of the job for the testcase resp testsuite of the job
:return: :return:
""" """
if job is None:
job = basic.program.Job.getInstance()
if "testcase" in job.program: if "testcase" in job.program:
return collectTestdata(B.PAR_TESTCASE, getattr(job.par, B.PAR_TESTCASE), job) return collectTestdata(B.PAR_TESTCASE, getattr(job.par, B.PAR_TESTCASE), job)
else: else:
@ -50,9 +48,9 @@ def collectTestdata(gran, testentity, job):
basispath = utils.path_tool.rejoinPath(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA], testentity) basispath = utils.path_tool.rejoinPath(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA], testentity)
pathname = utils.config_tool.getConfigPath(P.KEY_TESTSUITE, getattr(job.par, B.PAR_TESTSUITE), "", job) pathname = utils.config_tool.getConfigPath(P.KEY_TESTSUITE, getattr(job.par, B.PAR_TESTSUITE), "", job)
if pathname[-3:] == D.DFILE_TYPE_CSV: if pathname[-3:] == D.DFILE_TYPE_CSV:
tdata = getCsvSpec(job.m, pathname, D.CSV_SPECTYPE_DATA) tdata = getCsvSpec(job.m, job, pathname, D.CSV_SPECTYPE_DATA)
else: else:
tdata = utils.file_tool.readFileDict(pathname, job.m) tdata = utils.file_tool.readFileDict(job, pathname, job.m)
# get explicit specdata of includes # get explicit specdata of includes
if D.CSV_BLOCK_IMPORT in tdata: if D.CSV_BLOCK_IMPORT in tdata:
for pathname in tdata[D.CSV_BLOCK_IMPORT]: for pathname in tdata[D.CSV_BLOCK_IMPORT]:
@ -60,16 +58,16 @@ def collectTestdata(gran, testentity, job):
if job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA] not in pathname: if job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA] not in pathname:
pathname = utils.path_tool.rejoinPath(basispath, pathname) pathname = utils.path_tool.rejoinPath(basispath, pathname)
if pathname[-3:] == D.DFILE_TYPE_CSV: if pathname[-3:] == D.DFILE_TYPE_CSV:
data = getCsvSpec(job.m, pathname, D.CSV_SPECTYPE_DATA) data = getCsvSpec(job.m, job, pathname, D.CSV_SPECTYPE_DATA)
else: else:
data = utils.file_tool.readFileDict(pathname, job.m) data = utils.file_tool.readFileDict(job, pathname, job.m)
for table in data[D.CSV_BLOCK_TABLES]: for table in data[D.CSV_BLOCK_TABLES]:
if table in tdata[D.CSV_BLOCK_TABLES]: if table in tdata[D.CSV_BLOCK_TABLES]:
print("Fehler") print("Fehler")
tdata[D.CSV_BLOCK_TABLES][table] = data[D.CSV_BLOCK_TABLES][table] tdata[D.CSV_BLOCK_TABLES][table] = data[D.CSV_BLOCK_TABLES][table]
# get implicit specdata of spec-library # get implicit specdata of spec-library
for prefix in list_blocks[D.DFILE_TABLE_PREFIX]: for prefix in list_blocks[D.DFILE_TABLE_PREFIX]:
files = utils.file_tool.getFiles(job.m, basispath, prefix, None) files = utils.file_tool.getFiles(job.m, job, basispath, prefix, None)
if len(files) < 0: if len(files) < 0:
continue continue
for f in files: for f in files:
@ -77,9 +75,9 @@ def collectTestdata(gran, testentity, job):
continue continue
pathname = utils.path_tool.rejoinPath(basispath, f) pathname = utils.path_tool.rejoinPath(basispath, f)
if pathname[-3:] == D.DFILE_TYPE_CSV: if pathname[-3:] == D.DFILE_TYPE_CSV:
data = getCsvSpec(job.m, pathname, D.CSV_SPECTYPE_DATA) data = getCsvSpec(job.m, job, pathname, D.CSV_SPECTYPE_DATA)
else: else:
data = utils.file_tool.readFileDict(pathname, job.m) data = utils.file_tool.readFileDict(job, pathname, job.m)
for table in data[D.CSV_BLOCK_TABLES]: for table in data[D.CSV_BLOCK_TABLES]:
if table in tdata[D.CSV_BLOCK_TABLES]: if table in tdata[D.CSV_BLOCK_TABLES]:
print("Fehler") print("Fehler")
@ -92,24 +90,20 @@ def collectTestdata(gran, testentity, job):
def setBlockLists(job): def setBlockLists(job):
for block in D.LIST_BLOCK_CONST + D.LIST_ATTR_CONST + D.LIST_DFNAME_CONST: for block in D.LIST_BLOCK_CONST + D.LIST_ATTR_CONST + D.LIST_DFNAME_CONST:
list = utils.i18n_tool.I18n.getInstance().getAliasList(block+"='"+eval("D."+block)+"'") list = utils.i18n_tool.I18n.getInstance().getAliasList(block+"='"+eval("D."+block)+"'", job)
#list.append(eval("D."+block)) #list.append(eval("D."+block))
list_blocks[eval("D." + block)] = [] list_blocks[eval("D." + block)] = []
for x in list: for x in list:
list_blocks[eval("D." + block)].append(x.lower()) list_blocks[eval("D." + block)].append(x.lower())
def readCsv(msg, filename, comp, aliasNode="", job=None): def readCsv(msg, job, filename, comp, aliasNode=""):
if job is None: lines = utils.file_tool.readFileLines(job, filename, msg)
job = basic.program.Job.getInstance()
lines = utils.file_tool.readFileLines(filename, msg)
print("readCsv "+filename) print("readCsv "+filename)
return parseCsv(msg, filename, lines, comp, aliasNode, job) return parseCsv(msg, job, filename, lines, comp, aliasNode)
def parseCsv(msg, filename, lines, comp, aliasNode="", job=None): def parseCsv(msg, job, filename, lines, comp, aliasNode=""):
if job is None:
job = basic.program.Job.getInstance()
if len(list_blocks) < 1: if len(list_blocks) < 1:
setBlockLists(job) setBlockLists(job)
tdata = {} tdata = {}
@ -133,7 +127,7 @@ def extractAliasNode(filename, comp, job):
return "" return ""
def getCsvSpec(msg, filename, ttype, job=None): def getCsvSpec(msg, job, filename, ttype):
""" """
reads the specification from a csv-file and maps it into the internal data-structure reads the specification from a csv-file and maps it into the internal data-structure
:param msg: :param msg:
@ -142,14 +136,14 @@ def getCsvSpec(msg, filename, ttype, job=None):
:param job: :param job:
:return: :return:
""" """
if job is None: #if job is None:
job = basic.program.Job.getInstance() # job = basic.program.Job.getInstance()
lines = utils.file_tool.readFileLines(filename, msg) lines = utils.file_tool.readFileLines(job, filename, msg)
tdata = {} # the result tdata = {} # the result
return parseCsvSpec(msg, lines, ttype, tdata, job) return parseCsvSpec(msg, lines, ttype, tdata, job)
def parseCsvSpec(msg, lines, ttype, tdata, job=None): def parseCsvSpec(msg, lines, ttype, tdata, job):
""" """
:param msg: :param msg:
@ -158,8 +152,6 @@ def parseCsvSpec(msg, lines, ttype, tdata, job=None):
:param job: :param job:
:return: :return:
""" """
if job is None:
job = basic.program.Job.getInstance()
if len(list_blocks) < 1: if len(list_blocks) < 1:
setBlockLists(job) setBlockLists(job)
status = "start" status = "start"
@ -384,7 +376,7 @@ def writeCsvData(filename, tdata, comp, job):
for k in tdata[B.DATA_NODE_TABLES]: for k in tdata[B.DATA_NODE_TABLES]:
text += buildCsvData(tdata[B.DATA_NODE_TABLES][k], k, job) text += buildCsvData(tdata[B.DATA_NODE_TABLES][k], k, job)
text += "\n" text += "\n"
utils.file_tool.writeFileText(comp.m, filename, text) utils.file_tool.writeFileText(comp.m, job, filename, text)
def buildCsvData(tdata, table, job=None): def buildCsvData(tdata, table, job=None):

757
utils/xml1_tool.py

@ -1,757 +0,0 @@
#import dpath.util
import json
import yaml
import re
import datetime
import utils.tdata_tool
import os, sys, json
import xmltodict
import pprint
#class fcts:
def dict2xml(tree):
out = xmltodict.unparse(tree, pretty=True)
return out
def xml2dict(xmlstring):
tree = {}
pp = pprint.PrettyPrinter(indent=4)
tree = xmlstring.parse(xmlstring)
return tree
"""
Register-Meldung erstellen
"""
class register():
def __init__(self):
self.absender = Absender()
self.vrfelder = Vrfelder()
pass
def schreibeRegister(self, content, regAdr):
ausgabe = {}
content["vrfelder"] = self.vrfelder
content["absender"] = self.absender.keys[regAdr]
#
ausgabe = self.schreibeProtokoll(ausgabe, content)
print( "ausgabe vorher: " + str( ausgabe))
ausgabe = self.schreibeAbsender(ausgabe, content, regAdr)
print("ausgabe vorher: "+str(ausgabe))
ausgabe = self.schreibeEmpfaenger(ausgabe, content)
print("ausgabe vorher: "+str(ausgabe))
ausgabe = self.schreibeMetadaten(ausgabe, content)
print("ausgabe vorher: "+str(ausgabe))
ausgabe = self.schreibeSegmentkopf(ausgabe, content)
print("ausgabe vorher: "+str(ausgabe))
ausgabe["nachricht"]["datensegment"] = []
for row in content["tabelle"]["person"][B.DATA_NODE_DATA]:
print ("foreach row")
print (row)
satz = {}
satz = self.schreibeSegmentsatz(satz, content, row["_lfdNR"])
# print("ausgabe vorher: "+str(ausgabe))*
ausgabe["nachricht"]["datensegment"].append(satz["datensegment"])
return ausgabe
""" Fuellt und ordnet Protokollknoten ein"""
def schreibeProtokoll(self, ausgabe, content):
ausgabe["protokoll"] = self.setProtokoll(content)["protokoll"]
return ausgabe
def setProtokoll(self, content):
ausgabe = {}
d = datetime.datetime.now()
ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/datum', d.strftime("%Y%m%d"))
ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/uhrzeit', d.strftime("%H%M%S"))
ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/anwendung/anwendungsname', "Anwendungsname")
ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/anwendung/version', "Version")
ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/anwendung/hersteller', "StBA")
ausgabe = fcts.setMerkmal(ausgabe, '/protokoll/dokumentinstanz/ressourceID[@klasse="SDFMETA"]', "--RessourceID")
return ausgabe
""" Fuellt und ordnet Absenderknoten ein"""
def schreibeAbsender(self, ausgabe, content, regAdr):
ausgabe["absender"] = self.setAbsender(content, regAdr)
return ausgabe
def setAbsender(self, content, regAdr):
ausgabe = {}
for feld in Absender.FELDER:
ausgabe = fcts.setMerkmalContent(ausgabe, content, 0, feld)
return ausgabe
""" Fuellt und ordnet Empfaengerknoten ein"""
def schreibeEmpfaenger(self, ausgabe, content):
ausgabe["empfaenger"] = self.setEmpfaenger(content)["empfaenger"]
return ausgabe
def setEmpfaenger(self, content):
ausgabe = {}
ausgabe = fcts.setMerkmal(ausgabe, '/empfaenger/kennung[@klasse="STAID"]', '99')
return ausgabe
""" Fuellt und ordnet Metadatenknoten ein"""
def schreibeMetadaten(self, ausgabe, content):
nachricht = self.setMetadaten(content)
for knoten in nachricht:
if knoten != "datensegment":
ausgabe[knoten] = nachricht[knoten]
return ausgabe
def setMetadaten(self, content):
ausgabe = {}
d = datetime.datetime.now()
ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/erhebung/kennung[@klasse="ERHID"]', 'ERHEBUNG_KENNUNG')
ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/erhebung/ressource[@klasse="SDFMETA"]', 'ERHEBUNG_RESSOURCE_1')
ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/erhebung/ressource[@klasse="SDF-ERZEUGUNG"]', 'ERHEBUNG_RESSOURCE_2')
ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/berichtszeitraum/jahr', d.strftime("%Y"))
ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/berichtsempfaenger/kennung[@klasse ="STAID"]', 'BERICHTSEMPFÄNGER_KENNUNG')
ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/datenattribute/attribute::dezimalzeichen', 'DEZIMAL_ZEICHEN')
ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/datenattribute/attribute::tausender-trennzeichen', 'TAUSENDER_TRENNZEICHEN')
ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/hmm[@name="BerichtseinheitID"]/wert', 'BERICHTSEINHEIT_ID')
return ausgabe
def schreibeSegmentkopf(self, ausgabe, content, ):
ausgabe = fcts.setMerkmal(ausgabe, '/nachricht/datensegment/meldungsID', 'MELDUNGS_ID')
return ausgabe
def schreibeSegmentsatz(self, ausgabe, content, index):
for feld in Person.FELDER:
ausgabe = fcts.setMerkmalContent(ausgabe, content, index, feld)
return ausgabe
class Absender():
FELDER = ("ABSENDER_KENNUNG", "ABSENDER_IDENTITÄT", "ABSENDER_TELEFON", "ABSENDER_EMAIL", "ABSENDER_FAX", "ABSENDER_URL", "BERICHTSEINHEIT_ID", "REGNAME")
def __init__(self):
content = utils.tdata_tool.readCsv("testdaten/allgemein/absender.csv", "keys")
self.keys = content["tabelle"]["absender"]["_keys"]
class Vrfelder():
def __init__(self):
with open(r'src/config/vrFelder.yml') as file:
content = yaml.full_load(file)
self.conf = content
def getVrfeld(self, feld):
print("gerVrfeld "+feld)
if feld in self.conf["config"]:
print("gerVrfeld treffer"+feld)
return self.conf["config"][feld]
pass
class Anschrift():
FELDER = ("GEMSCHL", "HNR", "HNR_BUCHST", "HNR_TEILNR", "HNR_UNST", "ORTSTEIL", "ORTSTEIL_POST", "PLZ", "STOCKNR_WHG", "STR", "STRSCHL", "WOHNORT", "ZUSATZ")
class Person():
FELDER = ("IDNR", "DR", "FAMNAME", "FAMNAME_AE", "FAMNAME_BEST", "FAMNAME_ZUS", "FAMNAME_VOR", "FAMNAME_UNST", "GEB_DAT", "GEBNAME", "GEBNAME_BEST1", "GEBNAME_BEST2", "GEBNAME_UNST", "GEBSTAAT", "GEB_ORT", "GESCHLECHT", "STAATSANG", "VORNAME", "VORNAME_AE")
"""
Werkzeuge, um Register-Merkmale zu erstellen, setzen, ...
"""
class fcts:
#+MULTI_NODE = ("mm", "hmm", "omm", "erhebung")
MULTI_NODE = ("erhebung")
#+ARRAY_NODE = ("satz", "ressource")
ARRAY_NODE = ("mm", "hmm", "omm", "satz", "ressource")
def isLastGroup(pfad, knoten):
if (pfad[(pfad.find(knoten)+len(knoten)+4):].find("[@") > 1):
return False
return True
def getNodename(knotenname):
if ("[@" in knotenname):
return knotenname[0:knotenname.find("[@")]
return knotenname
def getKeyname(knotenname):
if ("[@" in knotenname):
return knotenname[knotenname.find("[@")+1:knotenname.find("=")]
return knotenname
def setArrayElem(array, elem):
# sets or appends the element/key-val into the array
for k in array:
if (elem in array):
return array
array.append(elem)
def getTidyTab(self, depth=0):
tab = ""
# print("depth "+str(depth))
for i in range(0, depth):
tab += "\t"
return tab
def hasTidyAttr(self, tree):
first = True
if isinstance(tree, dict):
for x in tree:
if first and isinstance(tree[x], dict):
return self.hasTidyAttr(tree[x])
elif first and isinstance(tree[x], list):
return self.hasTidyAttr(tree[x])
elif x[0:1] == "@":
return True
else:
return False
if isinstance(tree, list):
for x in tree:
if first and isinstance(x, dict):
return self.hasTidyAttr(x)
elif first and isinstance(x, list):
return self.hasTidyAttr(x)
elif x[0:1] == "@":
return True
else:
return False
elif tree[0:1] == "@":
return True
return False
def getTidyAttr(self, tree, x, depth=0):
xml = ""
attr = ""
if isinstance(tree, dict):
for y in tree:
if isinstance(y, dict):
return ""
elif isinstance(y, list):
attr = self.getTidyAttr(y, x, depth)
elif y[0:1] == "@":
attr += " "+y[1:]+"="+tree[y]
elif len(attr) > 1:
xml = "<"+x+attr+">"+y+"</"+x+">"
return xml
else:
return ""
elif isinstance(tree, dict):
for y in tree:
pass
return ""
def getTidyDict(self, tree, x, depth=0):
xml = ""
tab = self.getTidyTab(depth)
newTree = {}
attr = ""
for y in tree:
if y[0:1] == "@":
attr = " " + y[1:] + "=\"" + tree[y] + "\""
else:
newTree[y] = tree[y]
if len(newTree) > 0:
xml += tab + "<" + x + attr + ">\n" + self.tidy(newTree, depth + 1) + tab + "</" + x + ">\n"
else:
xml += tab + "<" + x + attr + "/>\n"
return xml
def tidy(self, tree, depth=0):
verify = 0
xml = ""
tab = self.getTidyTab(depth)
hasa = self.hasTidyAttr(tree)
if verify: print("getTidy "+str(type(tree))+" hasAttr "+str(hasa))
if isinstance(tree, dict):
for x in tree:
if verify: print("dict " + str(x))
if isinstance(tree[x], dict):
hasa = self.hasTidyAttr(tree[x])
newTree = {}
attr = ""
for y in tree[x]:
if verify: print("y-for "+str(y))
if y[0:1] == "@":
attr = " " + y[1:] + "=\"" + tree[x][y] + "\""
else:
newTree[y] = tree[x][y]
if len(newTree) > 0:
xml += tab + "<" + x + attr + ">\n" + self.tidy(newTree, depth + 1) + tab + "</" + x + ">\n"
else:
xml += tab + "<" + x + attr + "/>\n"
elif isinstance(tree[x], list):
hasa = self.hasTidyAttr(tree[x])
if hasa:
xml += tab + "<" + x + self.tidy(tree[x], depth) + "</" + x + ">\n"
else:
xml += tab + "<" + x + ">\n" + self.tidy(tree[x], depth + 1) + tab + "</" + x + ">\n"
elif x[0:1] == "@":
attr = " " + x[1:] + "=\"" + tree[x] + "\""
elif x == "#text":
xml = str(tree[x])
return xml
else:
xml += tab + "<" + x + ">" + str(tree[x]) + "</" + x + ">\n"
elif isinstance(tree, list):
for x in tree:
if verify: print("list " + str(x))
if isinstance(x, dict):
newTree = {}
attr = ""
text = False
hasa = self.hasTidyAttr(x)
for y in x:
if verify: print("y-for "+str(y))
if y[0:1] == "@":
attr = " " + y[1:] + "=\"" + x[y] + "\""
elif y == "#text":
text = x[y]
else:
newTree[y] = x[y]
if text and len(newTree) > 0 and len(attr) > 0:
xml += "" + attr + ">" + self.tidy(newTree, depth + 1)
elif len(newTree) > 0 and len(attr) > 0:
xml += "" + attr + ">\n" + self.tidy(newTree, depth + 1) + tab
elif len(attr) > 0:
if not isinstance(x, dict):
xml += tab + "<296" + x + attr + "/>\n"
else:
xml += attr + ">"+text
else:
xml += self.tidy(newTree, depth)
else:
xml += tab + "<" + x + ">\n" + self.tidy(x, depth) + tab + "</" + x + ">"
else:
xml += "<" + str(tree) + ">"
return xml
def addMerkmal(baum, pfad, index, wert):
"""
Eingabe:
baum inklusive Elternknoten
pfad kompletter Pfad von Wurzel bis Blatt
index auf den Pfad
wert einzutragender Wert
Verarbeitung
basis der zu bearbeitende Knotenname extrahiert von Attributen
elem zu bearbeitender Knoten
zu betrachtende Fälle:
a: basis intendiert ein Array:
b: basis intendiert ein Dictionary:
c: basis ist ein einfacher Knoten
Weiter zu betrachten hinsichtlich Komplexität des Knotens
.a einfacher Knoten
.b Knoten mit Attribut als Blatt (anode+bnode) oder mit Unterknoten (nur anode)
Weiter zu betrachten hinsichtlich Pfadposition
..a: Blatt - Wert eintragen und
..b: im Pfad - weiterer rekursiver Aufruf
Ausgabe:
baum inklusive Elternknoten
"""
logdebug = 3 # Schalter zur Debug-Einstellung innerhalb der Funktion
if logdebug >= 1: print("--- addMerkmal "+str(index)+" "+pfad+" "+wert)
if logdebug >= 3: print("--- addMerkmal "+str(baum))
# # # # # # # # # # # # # # # # # # # #
# basis der zu bearbeitende Knotenname extrahiert von Attributen
# elem zu bearbeitender Knoten
elem = {}
a = pfad.strip('/').split('/')
anode = None # optional fuer Attribute
bnode = None # optional fuer direkte Wertzuordnung #text
basis = "" # Knotenname - ohne Attribute
if ("[@" in a[index]):
if logdebug >= 1: print("0b")
basis = a[index][0:a[index].find("[@")]
attribs = a[index][a[index].find("[@")+1:a[index].find("]")]
aname = attribs[0:attribs.find("=")]
aval = attribs[attribs.find("=")+2:-1]
if logdebug >= 3 : print("0b "+basis+" : "+aname+" = "+aval)
aarr = [aname , aval]
anode = {}
anode[aname] = aval
if (index == len(a)-1):
barr = ["#text", wert]
bnode = {}
bnode["#text"] = wert
if logdebug >= 3 : print("0b "+basis+" "+str(anode)+" "+str(bnode))
else:
basis = a[index]
if logdebug >= 3 : print("0b "+basis+" "+str(anode)+" "+str(bnode))
if (basis in baum):
elem[basis] = baum[basis]
nindex = index+1
if logdebug >= 1: print("1 "+a[index]+" "+wert+" "+str(baum))
# # # # # # # # # # # # # # # # # # # #
# zu betrachtende Fälle:
# a: basis intendiert ein Array:
# b: basis intendiert ein Dictionary:
# c: basis ist ein einfacher Knoten
# Weiter zu betrachten hinsichtlich Komplexität des Knotens
# .a einfacher Knoten
# .b Knoten mit Attribut als Blatt (anode+bnode) oder mit Unterknoten (nur anode)
# Weiter zu betrachten hinsichtlich Pfadposition
# ..a: Blatt - Wert eintragen und
# ..b: im Pfad - weiterer rekursiver Aufruf
#
# # # Fall a : Array
if (basis in fcts.ARRAY_NODE):
# Weiter zu betrachten
# .a einfacher Knoten
# .b Knoten mit Attribut als Blatt (anode+bnode) oder mit Unterknoten (nur anode)
# Weiter zu betrachten hinsichtlich Pfadposition
# ..a: Blatt - Wert eintragen und
# ...a zusaetzliches Blatt
# ...b ueberschriebenes Blatt OPEN
# ..b: im Pfad - weiterer rekursiver Aufruf
# ...a expandierter Pfad
# ...b fortgefuehrter Pfad
existKnoten = "N"
hatAttr = "N"
istWert = "N"
hatWert = "N"
expand = "N"
lastidx = 0
if logdebug >= 1: print("a: ARRAY "+a[index-1]+"-"+basis+" "+str(baum))
if (basis in baum):
# ggf. zu bearbeitendes ELEM erzeugen
if (isinstance(baum[basis], dict)):
print ("200 dict vorhanden")
if (len(baum[basis].keys()) <1):
elem[basis] = []
elem[basis].append({})
if (isinstance(baum[basis], list)):
print ("201 array vorhanden "+str(baum[basis]))
#if baum[basis]
existKnoten = "J"
elem[basis] = baum[basis]
else:
print ("203 neues array")
elem[basis] = []
elem[basis].append({})
existKnoten = "N"
xnode = {}
if (anode):
hatAttr = "J"
xnode = {} # Komplexitaetsfaelle in xnode setzen
if logdebug >= 3: print("a-b "+basis+" "+str(anode))
##elem[basis].append(anode)
#if (not aarr[0] in elem[basis]): #+
# if logdebug >= 3: print("a-b "+basis+" anode ergaenzt "+str(anode))
# #-elem[basis].append(anode)
xnode = anode
if (bnode): # a-b-a
istWert = "J"
if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx))
if logdebug >= 3: print("-->a-b-a-b> kompl. Blatt "+basis+" "+str(bnode))
#-elem[basis].append(bnode)
elem[basis][0][aarr[0]] = aarr[1]
elem[basis][0][barr[0]] = barr[1]
baum[basis] = elem[basis]
if logdebug >= 3: print("<--a-b-a-b< kompl. Blatt "+basis+" "+str(elem))
return baum
# weitere Fallunterscheidung: unterster Komplexknoten erweitern, vorherige durchlaufen
subnode = fcts.getNodename(a[nindex])
parentkey = fcts.getKeyname(a[index-1])
realnode = subnode
aridx = -1
if (basis in elem):
for x in elem[basis]:
print("x: "+str(x)+" "+str(len(x.keys())))
if len(x.keys()) > 0:
print ("x ist")
aridx += 1
# aridx -= 1
lastidx = aridx
print ("## Faluntersuchung parentkey "+parentkey+" aridx "+str(aridx)+" subnode "+subnode)
if ((aridx < 0)): # a-b-b-a
elem[basis][0][realnode] = {}
elem[basis][0][realnode][aarr[0]] = aarr[1]
if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx))
if logdebug >= 3: print("-->a-b-b-a> kompl. Pfad init " +basis+" "+parentkey+" " + realnode + " " + wert +" "+str(nindex)+" "+str(baum))
insnode = fcts.addMerkmal(elem[basis][0][realnode], pfad, nindex, wert)
if logdebug >= 3: print("<--a-b-b-a< kompl. Pfad init " + basis+" "+str(insnode)+"-set-0-"+str(elem[basis][0]))
elem[basis][0] = insnode
baum[basis] = elem[basis]
return baum ##
if fcts.isLastGroup(pfad, basis): # a-b-b-a expandierter Pfad
subnode = fcts.getNodename(a[nindex])
if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx))
if logdebug >= 3: print("-->a-b-b-a> kompl. Pfaderw "+subnode+" "+str(nindex)+" "+str(anode)+" "+str(baum))
insnode = fcts.addMerkmal(anode, pfad, nindex, wert)
if logdebug >= 3: print("<--a-b-b-a< kompl. Pfaderw. " + basis + " "+str(insnode)+"-ins-"+str(elem[basis][0]))
elem[basis].append(insnode)
baum[basis] = elem[basis]
return baum
else:
# hier soll in dem Knoten weiternavigiert werden
# satz[@klasse="1"]/mm[@name="2"]...
# basis = satz, subnode = mm
# baum = {satz: [{ @klasse : 1, mm : [{ @name : 0, ..
subnode = fcts.getNodename(a[nindex])
realnode = subnode
if "[@" in subnode:
realnode = a[nindex+1]
if logdebug >= 3:
print (basis)
print (elem)
print (baum)
aridx = 0
if (basis in baum):
aridx = len(baum[basis])-1
#if (aridx >= 0) and ():
# elem[basis] = []
# elem[basis].append(anode)
# .b Knoten mit Attribut als Blatt (anode+bnode) oder mit Unterknoten (nur anode)
# Weiter zu betrachten hinsichtlich Pfadposition
# ..a: Blatt - Wert eintragen und #-DONE-#
# ...a zusaetzliches Blatt #-OPEN-#
# ...b ueberschriebenes Blatt #-DONE-#
# ..b: im Pfad - weiterer rekursiver Aufruf
# ...a initialer Pfadposition #-DONE-#
# ...b expandierter Pfad
# ...c fortgefuehrter Pfad
if (aridx > 0 and logdebug >= 3):
print (basis+" ++ "+str(aridx)+" "+subnode)
print(str(baum[basis]))
print(str(baum[basis][aridx]))
if ((aridx > 0) and (realnode in baum[basis][aridx].keys())):
elem[basis] = []
#elem[basis].append(elem[basis][aridx][realnode])
if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx))
if logdebug >= 3: print("-->a-b-b-c> kompl. Pfad " +basis+" "+ realnode + " " + wert + " " + str(nindex) + " " + str(aridx)+" "+str(baum))
insnode = fcts.addMerkmal(elem[basis][aridx], pfad, nindex, wert)[realnode]
if logdebug >= 3: print("<--a-b-b-c< kompl. Pfad " + basis+" "+str(insnode)+"-set-"+str(elem[basis][aridx][realnode]))
elem[basis][aridx][realnode] = insnode
else:
#elem[basis] = []
#elem[basis].append(anode)
if logdebug >= 3: print("existKnoten "+existKnoten+" hatAttr "+hatAttr+" istWert "+istWert+" hatWert "+ hatWert+" expand "+expand+" lastidx "+str(lastidx))
if logdebug >= 3: print("-->a-b-b-b> kompl. Pfad " +basis+" "+ realnode + " " + wert + " " + str(nindex) + " " + str(aridx)+" "+str(baum))
insnode = fcts.addMerkmal(elem[basis][lastidx], pfad, nindex, wert)
if logdebug >= 3: print("<--a-b-b-b< kompl. Pfad " + basis+" "+str(insnode)+"-set-"+str(elem[basis][aridx]))
#elem[basis].append(insnode)
pass
baum[basis] = elem[basis]
return baum
# unerreichbar, da schon im else returned
#if logdebug >= 3:
# print("-->a-b-b> kompl. Pfad "+basis+" "+str(nindex))
# print("-->a-b-b> kompl. Pfad "+realnode+" "+str(nindex)+" "+str(baum))
# print("-->a-b-b> kompl. Pfad "+realnode+" "+str(nindex)+" "+str(elem))
#if not subnode in elem[basis][0]:
# elem[basis][0][realnode] = {}
# elem[basis][0][realnode][aarr[0]] = aarr[1]
# elem[basis][0] = fcts.addMerkmal(elem[basis][0][realnode], pfad, nindex, wert)
#elif (len(elem[basis]) > 0):
# elem[basis].append(fcts.addMerkmal(xnode, pfad, nindex, wert))
#+elem[basis].append(fcts.addMerkmal(xnode, pfad, nindex, wert))
#if logdebug >= 3:
# print (basis)
# print(baum)
# print(elem)
# print("<--a-b-b< kompl. Pfad "+basis+""+str(baum))
#baum[basis] = elem[basis]
#return baum ##
else:
if logdebug >= 3: print("-->a-a-b> einf. Pfad "+str(nindex)+" "+str(baum))
return baum
##### Fall 3ab ## Dict
elif (basis in fcts.MULTI_NODE):
if logdebug >= 1: print("b: DICT "+basis)
if (not basis in baum):
print ("elem angelegt")
elem[basis] = {}
if (anode ):
if logdebug >= 3: print("b-b "+basis+" "+str(anode))
elem[basis][aarr[0]] = aarr[1]
if (bnode):
elem[basis][barr[0]] = barr[1]
baum[basis] = elem[basis]
#elem[basis].append(bnode)
if logdebug >= 3: print("<<--b-b-a< kompl. Blatt "+basis+" "+str(index)+" "+str(elem))
return baum
if ("[@" in a[index+1]):
subbasis = a[index+1][0:a[index+1].find("[@")]
if logdebug >= 3: print("-->b-b-b> kompl. Pfad "+basis+" "+str(index)+" "+str(elem))
elem[basis] = fcts.addMerkmal(elem[basis], pfad, nindex, wert)
baum[basis] = elem[basis]
if logdebug >= 3: print("<--b-b-b< kompl. Pfad "+basis+" "+str(index)+" "+str(baum))
return baum
else:
subbasis = a[index+1]
if logdebug >= 3: print("-->b-a-b> einf. Pfad "+basis+" "+str(index)+" "+str(elem))
elem[basis][subbasis] = fcts.addMerkmal({}, pfad, nindex, wert)
baum[basis] = elem[basis]
if logdebug >= 3: print("<--b-a-b< einf. Pfad "+basis+" "+str(index)+" "+str(elem))
return baum
# baum[basis] = elem[basis]
return baum[basis]
###### Fall einfach + vorhanden
else:
if (basis in baum):
elem[basis] = baum[basis]
else:
elem[basis] = {}
if logdebug >= 1: print("c: EINFACH "+a[index-1]+"-"+basis+" "+str(baum))
if (1 == len(a)-index):
if logdebug >= 3 : print("3b "+basis+" "+str(anode)+" "+str(bnode))
if (anode):
elem[basis] = {}
elem[basis][aarr[0]] = aarr[1]
if logdebug >= 3 : print("3b1")
if (bnode):
elem[basis][barr[0]] = barr[1]
baum[basis] = elem[basis]
if logdebug >= 3 : print("<<-- c-b-a kompl. Blatt "+basis+" "+str(baum))
return baum
elem[basis] = {}
elem[basis] = wert
baum[basis] = elem[basis]
if logdebug >= 3 : print("<<-- c-a-a einf. Blatt "+basis+" "+str(anode)+" "+str(baum))
return baum
if (anode):
if logdebug >= 3: print("-->c-b-b> kompl. Pfad "+basis+" "+nindex)
elem[basis] = fcts.addMerkmal(elem[basis], pfad, nindex, wert)
baum[basis] = elem[basis]
if logdebug >= 3: print("<--c-b-b< kompl. Pfad "+basis+" "+nindex+" "+str(baum))
return baum[basis][basis] ##
if logdebug >= 3: print("-->c-a-b> einf. Pfad "+basis)
baum[basis] = fcts.addMerkmal(elem[basis], pfad, nindex, wert)
if logdebug >= 3: print("<--c-a-b< einf. Pfad "+basis+" "+str(index)+" "+str(baum))
return baum
# -----------------------------------------
def setMerkmal(baum, pfad, wert):
logdebug = 3 # Schalter zur Debug-Einstellung innerhalb der Funktion
if logdebug >= 1: print("----------------------------------------- setMerkmal ---------------------")
if logdebug >= 1: print("setMerkmal "+pfad+" "+wert)
#MULTI_NODE = ("mm", "hmm", "omm", "ressource")
elem = baum
if logdebug >= 2 : print ("setMerkmal "+pfad+" "+wert)
a = pfad.strip('/').split('/')
if ("[@" in a[0]):
basis = a[0][0:a[0].find("[@")]
else:
basis = a[0]
if (1 == len(a)):
baum[basis] = wert
return baum
if (basis in baum):
elem = baum[basis]
else:
elem = {}
# for i in range(0, len(a)):
if logdebug >= 1: print("setMerkmal "+basis+" "+str(elem))
baum = fcts.addMerkmal(baum, pfad, 0, wert)
if logdebug >= 1: print("setMerkmal "+basis+" "+str(baum))
if True:
return baum
if (1 == len(a)):
elem[a[0]] = wert
for i in range(0, len(a)):
if logdebug >= 3 : print("for "+str(i)+" "+a[i])
if ("[@" in a[i]):
basis = a[i][0:a[i].find("[@")]
else:
basis = a[i]
print ("basis "+basis )
#if (a[i] in elem):
if ((not basis in fcts.MULTI_NODE) and (basis in elem)):
if logdebug >= 3 : print("a "+basis)
elem = elem[basis]
else:
if ("[@" in a[i]):
if logdebug >= 3 : print("b "+a[i])
node = a[i][0:a[i].find("[@")]
attribs = a[i][a[i].find("[@")+1:a[i].find("]")]
aname = attribs[0:attribs.find("=")]
aval = attribs[attribs.find("=")+2:-1]
if logdebug >= 3 : print("b "+node+" : "+aname+" = "+aval)
if (node in elem):
if logdebug >= 3 : print("b "+node+" in elem ")
#if logdebug >= 3 : print(json.dumps(elem[node]))
if ("dict" in str(type(elem[node]))):
if logdebug >= 3 : print(node +" elem[node] ist dict")
xnode = elem[node]
elem[node] = []
elem[node].append(xnode)
else:
if logdebug >= 3 : print(node+" elem[node] ist nicht dict"+str(type(elem[node])))
pnode = {}
pnode[aname] = aval
print (str(i)+" ?= "+str(len(a)))
if (i == len(a)-1):
pnode["#text"] = wert
elem[node].append(pnode)
else:
elem[node] = {}
elem = elem[node]
elem[aname] = aval
if (i == len(a)-1):
elem["#text"] = wert
elif (i == len(a)-1):
if logdebug >= 3 : print("c "+a[i])
elem[a[i]] = wert
else:
if logdebug >= 3 : print("d "+a[i])
elem[str(a[i])] = {}
elem = elem[str(a[i])]
return baum
def setMerkmalContent(baum, content, index, feld):
logdebug = 1 # Schalter zur Debug-Einstellung innerhalb der Funktion
if logdebug >= 1 : print ("setMerkmalContent "+feld+" "+content["absender"]["REGNAME"])
vrfeld = content["vrfelder"].getVrfeld(feld)
if logdebug >= 2 : print(type(vrfeld))
if logdebug >= 2 : print(json.dumps(vrfeld))
tabelle = "#"
#print (type(vrfeld)+" "+str(vrfeld))
if (("tabelle" in vrfeld.keys()) and (vrfeld["tabelle"] == "absender")):
if logdebug >= 2 : print ("absender")
pass
elif (not "Register" in vrfeld):
if logdebug >= 2 : print ("kein Register")
return baum
elif (vrfeld["Register"].find(content["absender"]["REGNAME"])<0):
if logdebug >= 2 : print("verboten ")
return baum
if (not ("tabelle" in vrfeld.keys())):
if logdebug >= 2 : print ("keine tabelle")
return baum
elif (vrfeld["tabelle"][0:1] == "#"):
if logdebug >= 2 : print ("# tabelle")
return baum
xpath = vrfeld["Xpath"]
tabelle = vrfeld["tabelle"]
if logdebug >= 3 : print ("args "+tabelle+" "+xpath)
# pfadkennung ersetzen
if (xpath.find('${')>0):
ersatz = xpath[xpath.find('${')+2:xpath.find('}')]
npath = xpath[0:xpath.find('${')]+content["absender"][ersatz]+xpath[xpath.find('}')+1:]
else:
npath = xpath
if logdebug >= 2 : print ("npath "+npath)
npath = npath.replace('nachricht/', '')
if logdebug >= 2 : print ("npath "+npath)
if (tabelle == "absender"):
baum = fcts.setMerkmal(baum, npath, content["absender"][feld])
return baum
# Wert ermitteln aus Content
if logdebug >= 3 : print (str(index) +" tabelle "+str(content))
if (not content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1]):
if logdebug >= 2 : print ("Zeile fehlt")
return baum
if logdebug >= 3 : print (content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1])
if (not feld in content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1].keys()):
if logdebug >= 2 : print ("Feld fehlt")
return baum
wert = content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1][feld]
baum = fcts.setMerkmal(baum, npath, wert)
#print("ausgabe "+str(baum))
return baum
def test():
print("test in fcts")
class merkmal:
def __init__(self):
self.merkmale = "loadyaml"

5
utils/zip_tool.py

@ -10,15 +10,14 @@ def untarFolder(target, targetFile):
tar_file.close() tar_file.close()
pass pass
def openNewTarFile(target, targetFile): def openNewTarFile(job, target, targetFile):
job = basic.program.Job.getInstance()
tarfilename = os.path.join(target, targetFile) tarfilename = os.path.join(target, targetFile)
if os.path.exists(tarfilename): if os.path.exists(tarfilename):
os.remove(tarfilename) os.remove(tarfilename)
job.m.logInfo("Archiv angelegt "+tarfilename) job.m.logInfo("Archiv angelegt "+tarfilename)
return tarfile.open(tarfilename, 'w:gz') return tarfile.open(tarfilename, 'w:gz')
def appendFolderIntoTarFile(source, sourceFolder, tarFile): def appendFolderIntoTarFile(job, source, sourceFolder, tarFile):
workFolder = os.path.join(source, sourceFolder) workFolder = os.path.join(source, sourceFolder)
for folderName, subfolders, filenames in os.walk(workFolder): for folderName, subfolders, filenames in os.walk(workFolder):
for filename in filenames: for filename in filenames:

Loading…
Cancel
Save