|
|
@ -1,258 +1,52 @@ |
|
|
|
#!/usr/bin/python |
|
|
|
# program to execute programs for a testcases or for a testsuite |
|
|
|
# PARAM from INPUT: --granularity --application --environment --testcase/testsuite |
|
|
|
# main functions |
|
|
|
# + input_param() : cache-actjob --> user-input --> local-param |
|
|
|
# + start_job() : local-param --> cache-actjob --> start-param |
|
|
|
# --------------------------------------------------- |
|
|
|
|
|
|
|
# |
|
|
|
# |
|
|
|
# ---------------------------------------------------------- |
|
|
|
""" |
|
|
|
|
|
|
|
This program is created for the business-test on the level of unit testing. |
|
|
|
On this level there is an intensive test-set up to a carthesian product possible. |
|
|
|
The test-specification is written in a yaml-config in the data-directory. |
|
|
|
workflow: |
|
|
|
1. generate test-cases with all inputs into a csv-file of the spec-yaml |
|
|
|
2. run the csv-file and collect all results into a new result-csv-file with all inputs and outputs |
|
|
|
3. check the result-csv-file and declare it as a target-results |
|
|
|
OR instead 2 and 3 on test-first-strategy: |
|
|
|
3. create manually the target-result with your inputs and the target system-outputs |
|
|
|
4. run and compare the actual-result with the target-result |
|
|
|
5. at the end you get an xls-sheet like your result-csv-file |
|
|
|
but additionally with comparsion-result as detailed result and the only counts of passed and failed tests |
|
|
|
as minimum-result which can be inserted into management-tools |
|
|
|
""" |
|
|
|
import os.path |
|
|
|
import json |
|
|
|
import re |
|
|
|
|
|
|
|
# Press the green button in the gutter to run the script. |
|
|
|
import importlib |
|
|
|
import os, glob |
|
|
|
import io |
|
|
|
import sys |
|
|
|
import basic.program |
|
|
|
import basic.constants as B |
|
|
|
import utils.job_tool |
|
|
|
import utils.file_tool |
|
|
|
import utils.data_const as D |
|
|
|
import utils.date_tool |
|
|
|
import utils.path_tool |
|
|
|
import utils.path_const as P |
|
|
|
|
|
|
|
tempJob = {} |
|
|
|
import tools.job_tool |
|
|
|
import model.catalog |
|
|
|
|
|
|
|
PROGRAM_NAME = "service" |
|
|
|
PROGRAM_NAME = "start_dialog" |
|
|
|
|
|
|
|
DLG_TESTCASE = "Testfall" |
|
|
|
DLG_TESTSUITE = "Testsuite" |
|
|
|
DLG_COMPLETE = "Komplettausfuehrung" |
|
|
|
LIST_DLG_GRAN = [DLG_TESTCASE, DLG_TESTSUITE] |
|
|
|
DLG_START_QUESTION = "was soll getestet werden" |
|
|
|
# DLG_TESTPLAN = "Testplan" |
|
|
|
DLG_ENVIRONMENT = "Umgebung" |
|
|
|
DLG_APPLICATION = "Anwendung" |
|
|
|
DLG_REDO = "wiederholen" |
|
|
|
DLG_CONTINUE = "fortsetzen" |
|
|
|
DLG_DUMMY_STEP = "Dummy-Schritt" |
|
|
|
DLG_NEWJOB = "neuer Job" |
|
|
|
VERIFY = False |
|
|
|
|
|
|
|
JOB_NR = { |
|
|
|
DLG_TESTSUITE : { |
|
|
|
"start": "init_testsuite", |
|
|
|
"init_testsuite": { |
|
|
|
"jobnr": "0" }, |
|
|
|
"execute_testsuite": { |
|
|
|
"jobnr": "1"}, |
|
|
|
"collect_testsuite": { |
|
|
|
"jobnr": "2"}, |
|
|
|
"compare_testsuite": { |
|
|
|
"jobnr": "3"}, |
|
|
|
"finish_testsuite": { |
|
|
|
"jobnr": "4"} |
|
|
|
}, |
|
|
|
DLG_TESTCASE: { |
|
|
|
"start": "init_testcase", |
|
|
|
"init_testcase": { |
|
|
|
"jobnr": "5" }, |
|
|
|
"execute_testcase": { |
|
|
|
"jobnr": "6" }, |
|
|
|
"collect_testcase": { |
|
|
|
"jobnr": "7" }, |
|
|
|
"copy_appdummy": { |
|
|
|
"jobnr": "8" }, |
|
|
|
"compare_testcase": { |
|
|
|
"jobnr": "9" }, |
|
|
|
}, |
|
|
|
"check_environment": { |
|
|
|
"jobnr": "10" }, |
|
|
|
"test_executer": { |
|
|
|
"jobnr": "11"}, |
|
|
|
} |
|
|
|
|
|
|
|
JOB_LIST = [ |
|
|
|
"init_testsuite", # 0 |
|
|
|
"execute_testsuite", # 1 |
|
|
|
"collect_testsuite", # 2 |
|
|
|
"compare_testsuite", # 3 |
|
|
|
"finish_testsuite", # 4 |
|
|
|
"init_testcase", # 5 |
|
|
|
"execute_testcase", # 6 |
|
|
|
"collect_testcase", # 7 |
|
|
|
"copy_appdummy", # 8 |
|
|
|
"compare_testcase", # 9 |
|
|
|
"check_environment", # 10 |
|
|
|
"test_executer" # 11 |
|
|
|
] |
|
|
|
|
|
|
|
appList = [] |
|
|
|
envList = [] |
|
|
|
entities = {} |
|
|
|
entities[DLG_TESTCASE] = {} |
|
|
|
entities[DLG_TESTSUITE] = {} |
|
|
|
def startPyJob(job): |
|
|
|
# check if an actual job is stored |
|
|
|
childArgs = tools.job_tool.read_child_args(job) |
|
|
|
if childArgs is None: |
|
|
|
childArgs = initDialog(job) |
|
|
|
pass |
|
|
|
|
|
|
|
def readContext(job): |
|
|
|
for k in job.conf.confs[B.SUBJECT_APPS]: |
|
|
|
appList.append(k) |
|
|
|
path = job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV] |
|
|
|
if os.path.exists(path): |
|
|
|
for d in os.listdir(path): |
|
|
|
print ("-- "+d) |
|
|
|
if not os.path.isdir(os.path.join(path, d)): |
|
|
|
continue |
|
|
|
if d[0:1] == "_": |
|
|
|
continue |
|
|
|
envList.append(d) |
|
|
|
path = job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA] |
|
|
|
if os.path.exists(path): |
|
|
|
for d in os.listdir(path): |
|
|
|
print("tdata path "+d) |
|
|
|
if not os.path.isdir(os.path.join(path, d)): |
|
|
|
print("continue a") |
|
|
|
continue |
|
|
|
if d[0:1] == "_": |
|
|
|
print("continue b") |
|
|
|
continue |
|
|
|
specpath = os.path.join(path, d, D.DFILE_TESTCASE_NAME + ".csv") |
|
|
|
readSpec(job, d, DLG_TESTCASE, specpath) |
|
|
|
specpath = os.path.join(path, d, D.DFILE_TESTSUITE_NAME + ".csv") |
|
|
|
readSpec(job, d, DLG_TESTSUITE, specpath) |
|
|
|
|
|
|
|
def readSpec(job, testentity, testgran, specpath): |
|
|
|
print("spec "+specpath) |
|
|
|
if not os.path.isfile(specpath): |
|
|
|
print("continue c") |
|
|
|
return |
|
|
|
text = utils.file_tool.readFileText(job, specpath, job.m) |
|
|
|
print("-----------\n"+text+"\n------------------") |
|
|
|
if re.match(r".*?depricated;[jJyY]", text): |
|
|
|
return |
|
|
|
if re.match(r".*\nhead:application;", text): |
|
|
|
print("## app gematcht") |
|
|
|
res = re.search(r".*head:application;(.+)\n", text) |
|
|
|
apps = res.group(1).replace(";", ",").split(",") |
|
|
|
print("# "+str(apps)) |
|
|
|
for a in apps: |
|
|
|
if len(a) < 1: |
|
|
|
break |
|
|
|
if a not in entities[testgran]: |
|
|
|
entities[testgran][a] = [] |
|
|
|
print(a+" in "+testentity+" "+testgran+" -- "+str(entities)) |
|
|
|
entities[testgran][a].append(testentity) |
|
|
|
|
|
|
|
def printProc(job, process): |
|
|
|
print("--------------------------------------------------") |
|
|
|
for k in process: |
|
|
|
print("| {0:15s} : {1}".format(k, process[k])) |
|
|
|
print("--------------------------------------------------") |
|
|
|
|
|
|
|
|
|
|
|
def restartActualProcess(job): |
|
|
|
""" |
|
|
|
check if an actual process is open |
|
|
|
:return: |
|
|
|
""" |
|
|
|
path = utils.path_tool.getActualJsonPath(job) |
|
|
|
if os.path.exists(path): |
|
|
|
actProc = utils.file_tool.readFileDict(job, path, job.m) |
|
|
|
print("restartActJob "+str(actProc)) |
|
|
|
printProc(job, actProc) |
|
|
|
step = int(actProc["step"]) |
|
|
|
if actProc["program"] == "test_executer": |
|
|
|
if step > 5: |
|
|
|
dialogProcess(job) |
|
|
|
else: |
|
|
|
actProc["step"] = str(step+1) |
|
|
|
utils.job_tool.startProcess(job, actProc) |
|
|
|
restartActualProcess(job) |
|
|
|
selection = [DLG_NEWJOB, DLG_REDO] |
|
|
|
|
|
|
|
nr = int(JOB_NR[actProc["gran"]][actProc["program"]]["jobnr"]) |
|
|
|
if (actProc["gran"] == DLG_TESTSUITE and nr < 4) or (actProc["gran"] == DLG_TESTCASE and nr < 9): |
|
|
|
selection.append(DLG_CONTINUE) |
|
|
|
if nr == 7: |
|
|
|
selection.append(DLG_DUMMY_STEP) |
|
|
|
choice = getChoice(job, selection, DLG_ENVIRONMENT) |
|
|
|
print(choice) |
|
|
|
if choice == DLG_REDO: |
|
|
|
utils.job_tool.startProcess(job, actProc) |
|
|
|
restartActualProcess(job) |
|
|
|
elif choice == DLG_DUMMY_STEP: |
|
|
|
actProc["program"] = JOB_LIST[nr+1] |
|
|
|
utils.job_tool.startProcess(job, actProc) |
|
|
|
restartActualProcess(job) |
|
|
|
elif choice == DLG_CONTINUE: |
|
|
|
if nr == 7: |
|
|
|
nr = 9 |
|
|
|
else: |
|
|
|
nr += 1 |
|
|
|
print (" act nr "+str(nr)) |
|
|
|
actProc["step"] = str(step + 1) |
|
|
|
actProc["program"] = JOB_LIST[nr] |
|
|
|
utils.job_tool.startProcess(job, actProc) |
|
|
|
elif choice == DLG_NEWJOB: |
|
|
|
dialogProcess(job) |
|
|
|
else: |
|
|
|
dialogProcess(job) |
|
|
|
|
|
|
|
|
|
|
|
def dialogProcess(job): |
|
|
|
def getChoice(job, choiselist, description): |
|
|
|
""" |
|
|
|
dialog for selection and starting a process |
|
|
|
to choise one of the list or exit the program |
|
|
|
:param job: |
|
|
|
:param choiselist: |
|
|
|
:param description: |
|
|
|
:return: |
|
|
|
""" |
|
|
|
process = {} |
|
|
|
index = 0 |
|
|
|
print("create new process") |
|
|
|
selection = [] |
|
|
|
selection = LIST_DLG_GRAN |
|
|
|
if DLG_TESTCASE + " - " + DLG_COMPLETE not in selection: |
|
|
|
selection.append(DLG_TESTCASE + " - " + DLG_COMPLETE) |
|
|
|
if DLG_TESTSUITE + " - " + DLG_COMPLETE not in selection: |
|
|
|
selection.append(DLG_TESTSUITE + " - " + DLG_COMPLETE) |
|
|
|
choice = getChoice(job, LIST_DLG_GRAN, DLG_START_QUESTION) |
|
|
|
if DLG_COMPLETE in choice: |
|
|
|
process["gran"] = choice[0:-3-len(DLG_COMPLETE)] |
|
|
|
process["program"] = "test_executer" |
|
|
|
process["step"] = 1 |
|
|
|
else: |
|
|
|
process["gran"] = choice |
|
|
|
process["program"] = JOB_NR[process["gran"]]["start"] |
|
|
|
process["step"] = 1 |
|
|
|
if len(appList) == 1: |
|
|
|
process["app"] = appList[0] |
|
|
|
else: |
|
|
|
process["app"] = getChoice(job, appList, DLG_ENVIRONMENT) |
|
|
|
# |
|
|
|
if len(envList) == 1: |
|
|
|
process["env"] = envList[0] |
|
|
|
else: |
|
|
|
process["env"] = getChoice(job, envList, DLG_ENVIRONMENT) |
|
|
|
# |
|
|
|
if len(entities[process["gran"]][process["app"]]) == 1: |
|
|
|
process["entity"] = entities[process["gran"]][process["app"]][0] |
|
|
|
else: |
|
|
|
process["entity"] = getChoice(job, entities[process["gran"]][process["app"]], process["gran"]) |
|
|
|
print(str(process)) |
|
|
|
setattr(job.par, B.PAR_ENV, process["env"]) |
|
|
|
setattr(job.par, B.PAR_APP, process["app"]) |
|
|
|
if process["gran"] == DLG_TESTCASE: |
|
|
|
setattr(job.par, B.PAR_TESTCASE, process["entity"]) |
|
|
|
setattr(job.par, B.PAR_TCTIME, utils.date_tool.getActdate(utils.date_tool.F_DIR)) |
|
|
|
path = utils.path_tool.composePattern(job, "{"+P.P_TCBASE+"}", None) |
|
|
|
process[B.PAR_TCDIR] = path |
|
|
|
elif process["gran"] == DLG_TESTSUITE: |
|
|
|
setattr(job.par, B.PAR_TESTSUITE, process["entity"]) |
|
|
|
setattr(job.par, B.PAR_TSTIME, utils.date_tool.getActdate(utils.date_tool.F_DIR)) |
|
|
|
path = utils.path_tool.composePattern(job, "{"+P.P_TSBASE+"}", None) |
|
|
|
process[B.PAR_TSDIR] = path |
|
|
|
utils.job_tool.startProcess(job, process) |
|
|
|
restartActualProcess(job) |
|
|
|
|
|
|
|
def getChoice(job, choiselist, description): |
|
|
|
index = 0 |
|
|
|
print("+------------- "+description+" ----------") |
|
|
|
print('| | {:2d} : {:60s}'.format(0, "exit")) |
|
|
@ -265,6 +59,7 @@ def getChoice(job, choiselist, description): |
|
|
|
print("FEHLER Fehleingabe "+choice) |
|
|
|
getChoice(job, choiselist, description) |
|
|
|
elif int(choice) < 1: |
|
|
|
job.stopJob(0) |
|
|
|
exit(0) |
|
|
|
elif int(choice) > index: |
|
|
|
print("FEHLER Fehleingabe "+choice) |
|
|
@ -273,8 +68,70 @@ def getChoice(job, choiselist, description): |
|
|
|
return choiselist[int(choice) - 1] |
|
|
|
|
|
|
|
|
|
|
|
def initDialog(job, args={}): |
|
|
|
""" |
|
|
|
dialog to initialize a child-process |
|
|
|
:param job: |
|
|
|
:return: |
|
|
|
""" |
|
|
|
# which process |
|
|
|
if "proc" not in args: |
|
|
|
args["proc"] = getChoice(job, tools.job_tool.LIST_PROC, "Welchen Prozess starten") |
|
|
|
args["gran"] = "" |
|
|
|
args[B.PAR_USER] = tools.job_tool.getUser() |
|
|
|
args[B.PAR_PROJ] = tools.job_tool.getUserProject() |
|
|
|
args[B.PAR_STEP] = "" |
|
|
|
if args["proc"] == tools.job_tool.PROC_TP_EXECUTION: |
|
|
|
args["gran"] = B.PAR_TESTPLAN |
|
|
|
args[B.PAR_STEP] = "1" |
|
|
|
args[B.PAR_PROGRAM] = tools.job_tool.PROG_TEST_EXECUTER |
|
|
|
elif args["proc"] in [tools.job_tool.PROC_TS_STEPWISE, tools.job_tool.PROC_TS_EXECUTION]: |
|
|
|
args["gran"] = B.PAR_TESTSUITE |
|
|
|
args[B.PAR_STEP] = "1" |
|
|
|
if args["proc"] == tools.job_tool.PROC_TS_EXECUTION: |
|
|
|
args[B.PAR_PROGRAM] = tools.job_tool.PROG_TEST_EXECUTER |
|
|
|
else: |
|
|
|
args[B.PAR_PROGRAM] = tools.job_tool.PROG_TS_INIT |
|
|
|
elif args["proc"] in [tools.job_tool.PROC_TC_STEPWISE, tools.job_tool.PROC_TC_EXECUTION]: |
|
|
|
args["gran"] = B.PAR_TESTCASE |
|
|
|
args[B.PAR_STEP] = "1" |
|
|
|
if args["proc"] == tools.job_tool.PROC_TC_EXECUTION: |
|
|
|
args[B.PAR_PROGRAM] = tools.job_tool.PROG_TEST_EXECUTER |
|
|
|
else: |
|
|
|
args[B.PAR_PROGRAM] = tools.job_tool.PROG_TC_INIT |
|
|
|
elif args["proc"] == tools.job_tool.PROC_REDO_EXECUTION: |
|
|
|
args[B.PAR_PROGRAM] = getChoice(job, tools.job_tool.LIST_TS_PROGS + tools.job_tool.LIST_TC_PROGS, |
|
|
|
"Welches Programm starten") |
|
|
|
elif args["proc"] == tools.job_tool.PROC_SINGLE_JOB: |
|
|
|
args[B.PAR_PROGRAM] = getChoice(job, tools.job_tool.LIST_SERVICE_PROG, "Welches Programm starten") |
|
|
|
else: |
|
|
|
args["gran"] = "" |
|
|
|
catalog = model.catalog.Catalog.getInstance() |
|
|
|
programDef = catalog.getValue(job, basic.program.CTLG_NAME, args[B.PAR_PROGRAM], "") |
|
|
|
for p in programDef[basic.program.CTLG_PARDEF]: |
|
|
|
if p in args: |
|
|
|
print("p "+p+" ist "+args[p]) |
|
|
|
else: |
|
|
|
args[p] = programDef[basic.program.CTLG_PARDEF][p] |
|
|
|
print("p "+p+" jetzt " + args[p]) |
|
|
|
print(str(args)) |
|
|
|
|
|
|
|
def childDialog(job, args): |
|
|
|
""" |
|
|
|
dialog to manage the child-process |
|
|
|
:param job: |
|
|
|
:return: |
|
|
|
""" |
|
|
|
pass |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
job = basic.program.Job(PROGRAM_NAME, {}) |
|
|
|
readContext(job) |
|
|
|
restartActualProcess(job) |
|
|
|
job = basic.program.Job(PROGRAM_NAME) |
|
|
|
# TODO to move to job_tool |
|
|
|
args = {} |
|
|
|
if isinstance(job.programDef[basic.program.CTLG_PARDEF], dict): |
|
|
|
for p in job.programDef[basic.program.CTLG_PARDEF]: |
|
|
|
args[p] = job.programDef[basic.program.CTLG_PARDEF][p] |
|
|
|
job.setParameter(args) |
|
|
|
job.startJob() |
|
|
|
startPyJob(job) |
|
|
|
job.stopJob(0) |
|
|
|