Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
5.1 KiB

3 years ago
#
# ---------------------------------------------------------------------
"""
the issue of this tool is to transform extern data to the internal structure and the internal structure into extern data - i.e. mostly test-results.
* * * * * * * *
the testdata have several elements
* parameter (-td --tdata) : to identify which testdata should be loaded
* source (db: dbname / dir: filename) : always structured in a table (easy to specify) with columns
* node : where the rows are
* action : what should be done - default insert
+ fields : dates in relation of a reference<day or a formula
* interface : configured in components and used in comparison with attributes to each field:
* ignored - if it should be ignored on differences, it is necessary on technical ID-fields
* id-field - necessary
* * * * * * * *
the testdata itself which are written in different artifacts of modern applications are mostly stored as tree
- so as xml, json, always with plain data in the leaf. So the intern structure should be also a tree - in python: dictionary.
"""
import ulrich.program
import csv
def getSourcefile(filename):
pass
def getTestdata():
job = ulrich.program.Job.getInstance()
reftyp = getattr(job.par, "tdtyp")
source = getattr(job.par, "tdsrc")
criteria = getattr(job.par, "tdname")
tdata = {"reftyp": reftyp, "source": source, "criteria": criteria}
if reftyp == "db":
# read data-structure with sourcename
# connect to source
# select with all data with datastructure
job.m.setInfo("Test-Data readed from " + reftyp + " for " + criteria)
elif reftyp == "csv":
# read file in testdata
job.m.logInfo("Test-Data readed from " + reftyp + " for " + criteria)
else:
job.m.setFatal("test-Data: reftyp " + reftyp + " is not implemented")
return tdata
def readCsv(filename):
job = ulrich.program.Job.getInstance()
verify = -1+job.getDebugLevel("tdata_tool")
job.debug(verify, "readCsv " + filename)
fields = []
nodes = []
columns = []
output = {}
state = 0
data = []
cnt = 0
with open(filename, 'r') as file:
lines = file.read().splitlines()
for line in lines:
# while (line := file.readline().rstrip()):
fields = line.split(';')
testline = line.replace(";", "")
job.debug(verify, str(state) + " line " + line + " :" + str(len(fields)) + ": " + str(fields))
if len(testline) < 2 and state < 1:
state = 0
elif fields[0].lower() == "node":
state = 2
columns = []
cnt = len(fields)
job.debug(verify, str(state) + " cnt " + str(cnt))
j = 0
for i in range(2, cnt-1):
job.debug(verify, str(i) + " cnt " + str(fields[i]))
if len(fields[i]) > 0:
columns.append(fields[i])
j = j + 1
cnt = j
job.debug(verify, str(state) + " " + str(cnt) + " cols " + str(columns))
elif state >= 2 and len(testline) > 2:
if state == 2:
nodes = fields[0].split(":")
job.debug(verify, str(state) + " nodes " + str(nodes))
state = 3
row = {}
for i in range(2, cnt-1):
row[columns[i-2]] = fields[i]
job.debug(verify, str(state) + " row " + str(row))
data.append(row)
elif state == 3:
job.debug(verify, "structure " + str(state) + ": " + str(nodes))
output = setSubnode(0, nodes, data, output)
data = []
state = 0
print(str(output))
print(str(output))
output = setSubnode(0, nodes, data, output)
print(str(output))
file.close()
return output
def setSubnode(i, nodes, data, tree):
print("setSubnode " + str(i) + ": " + ": " + str(tree))
if i >= len(nodes):
print("setSubnode a " + str(i))
tree["data"] = data
elif tree is not None and nodes[i] in tree.keys():
print("setSubnode b " + str(i))
tree[nodes[i]] = setSubnode(i+1, nodes, data, tree[nodes[i]])
else:
print("setSubnode c " + str(i))
tree[nodes[i]] = setSubnode((i + 1), nodes, data, {})
return tree
def getDataStructure(comp):
# gets data-structure from the vml in the component-folder
job = ulrich.program.Job.getInstance()
verify = -1+job.getDebugLevel("tdata_tool")
job.debug(verify, "getDataStructure " + comp)
def normalizeDataRow(dstruct, xpathtupel, row, referencedate):
# normalize data of the row if necessary
# raw-value is saved as new field with _raw as suffix
job = ulrich.program.Job.getInstance()
verify = -1+job.getDebugLevel("tdata_tool")
job.debug(verify, "calcDataRow " + row)
def writeDataTable(teststatus, tdata, comp):
"""
writes the testdata into a csv-file for documentation of the test-run
:param teststatus:
:param tdata:
:param comp: if specific else None
:return:
"""
job = ulrich.program.Job.getInstance()
verify = -1+job.getDebugLevel("tdata_tool")
job.debug(verify, "writeDataTable " + str(comp))