# # # ---------------------------------------------------------- """ 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 """ # 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 tools.job_tool as job_tool import model.catalog import tools.job_const as J import tools.step_tool PROGRAM_NAME = "start_dialog" JOB_PROC = "proc" verbose = False def startPyJob(job): # for debugging write setattr(job.par, "tool", "job_tool") # check if an actual job is stored childArgs = job_tool.read_child_args(job) if childArgs is None: childArgs = initDialog(job) else: childDialog(job) pass def getChoice(job, choiselist, description): """ to choise one of the list or exit the program :param job: :param choiselist: :param description: :return: """ index = 0 if isinstance(choiselist, dict): choiselist = list(choiselist.keys()) if len(choiselist) == 0: raise Exception("Keine Auswahl zu: "+description) if len(choiselist) == 1: return choiselist[0] print("+------------- "+description+" ----------") print('| | {:2d} : {:60s}'.format(0, "exit")) for k in choiselist: index += 1 print('| | {:2d} : {:60s}'.format(index, k)) print("+-----------------------------------------------") choice = input("Auswahl 1-" + str(index) + ": ") if verbose: print("auswahl "+str(choice)) if not choice.isnumeric(): 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) getChoice(job, choiselist, description) else: if verbose: print("treffer "+str(choiselist)) return choiselist[int(choice) - 1] def initDialog(job): """ dialog to initialize a child-process :param job: :return: """ # which process args = {} verify = job.getDebugLevel("job_tool") if JOB_PROC not in args: args[JOB_PROC] = getChoice(job, J.LIST_PROC, "Welchen Prozess starten") args[B.PAR_GRAN] = "" args[B.PAR_USER] = job_tool.getUser() args[B.PAR_PROJ] = job_tool.getUserProject() args[B.PAR_STEP] = "" job.m.logTrace(verify, args[JOB_PROC]) # """ print("JOB_PROC "+args[JOB_PROC]) if args[JOB_PROC] == J.PROC_TP_EXECUTION: args[B.PAR_GRAN] = B.PAR_TESTPLAN args[B.PAR_STEP] = tools.step_tool.getNextStepID(job, 0, "", args[B.PAR_GRAN]) args[B.PAR_PROGRAM] = J.PROG_TEST_EXECUTER elif args[JOB_PROC] in [J.PROC_TS_STEPWISE, J.PROC_TS_EXECUTION]: args[B.PAR_GRAN] = B.PAR_TESTSUITE args[B.PAR_STEP] = tools.step_tool.getNextStepID(job, 0, "", args[B.PAR_GRAN]) if args[JOB_PROC] == J.PROC_TS_EXECUTION: args[B.PAR_PROGRAM] = J.PROG_TEST_EXECUTER else: args[B.PAR_PROGRAM] = J.PROG_TS_INIT # elif args[JOB_PROC] in [J.PROC_TC_STEPWISE, J.PROC_TC_EXECUTION]: elif args[JOB_PROC] == J.PROC_TC_EXECUTION: print("JOB_PROC - 111 " + args[JOB_PROC]) args[B.PAR_GRAN] = B.PAR_TESTCASE args[B.PAR_STEP] = tools.step_tool.getNextStepID(job, 0, "", args[B.PAR_GRAN]) args[B.PAR_PROGRAM] = J.PROG_TEST_EXECUTER elif args[JOB_PROC] == J.PROC_TC_STEPWISE: print("JOB_PROC - 116 " + args[JOB_PROC]) args[B.PAR_GRAN] = B.PAR_TESTCASE args[B.PAR_STEP] = tools.step_tool.getNextStepID(job, 0, "", args[B.PAR_GRAN]) args[B.PAR_PROGRAM] = J.PROG_TC_INIT elif args[JOB_PROC] == J.PROC_REDO_EXECUTION: args[B.PAR_PROGRAM] = getChoice(job, J.LIST_TS_PROGS + J.LIST_TC_PROGS, "Welches Programm starten") elif args[JOB_PROC] == J.PROC_SINGLE_JOB: args[B.PAR_PROGRAM] = getChoice(job, J.LIST_SERVICE_PROG, "Welches Programm starten") else: args[B.PAR_GRAN] = "" # args[B.PAR_GRAN] = "" # """2 catalog = model.catalog.Catalog.getInstance() setattr(job.par, B.SUBJECT_PROJECT, "TESTPROJ") programDef = catalog.getValue(job, basic.program.CTLG_NAME, args[B.PAR_PROGRAM], "") job.m.logTrace(verify, "programdefinition "+str(programDef)) print("programdefinition "+str(programDef)) if verbose: print("programdefinition "+args[B.PAR_PROGRAM]+" "+str(programDef)) #for p in programDef[basic.program.CTLG_PARDEF]: print(str(args)) for p in [B.PAR_PROJ, B.PAR_GRAN, B.PAR_APP, J.ARG_TESTELEM, B.PAR_COMP, B.PAR_ENV, B.PAR_TESTPLAN, B.PAR_TESTSUITE, B.PAR_TESTCASE, B.PAR_TSTIME, B.PAR_TCTIME, B.PAR_TPTIME, B.PAR_VAR]: if p in args and len(args[p]) > 0: continue if p not in programDef[basic.program.CTLG_PARDEF]: continue if programDef[basic.program.CTLG_PARDEF][p] != "args": args[p] = programDef[basic.program.CTLG_PARDEF][p] continue print("+ bearbeite "+p) if programDef[basic.program.CTLG_PARDEF][p] == "args": description = "" job.m.logDebug(verify, "to select "+p) if p == B.PAR_GRAN: description = J.CHOICE_GRAN choiceList = J.LIST_GRAN elif p == B.PAR_APP: description = J.CHOICE_APP choiceList = job_tool.select_application(job, programDef, args[B.PAR_PROJ]) elif p == B.PAR_TESTPLAN or p == J.ARG_TESTELEM and args[B.PAR_GRAN] in [J.GRAN_TP, B.PAR_TESTPLAN]: description = J.CHOICE_TP choiceList = job_tool.select_testplan(job, programDef, args) p = B.PAR_TESTPLAN if J.ARG_TESTELEM in programDef[basic.program.CTLG_PARDEF]: args[J.ARG_TESTELEM] = p elif p == B.PAR_TESTSUITE or p == J.ARG_TESTELEM and args[B.PAR_GRAN] in [J.GRAN_TS, B.PAR_TESTSUITE]: description = J.CHOICE_TS choiceList = job_tool.select_testsuite(job, programDef, args) p = B.PAR_TESTSUITE if J.ARG_TESTELEM in programDef[basic.program.CTLG_PARDEF]: args[J.ARG_TESTELEM] = p elif p == B.PAR_TESTCASE or p == J.ARG_TESTELEM and args[B.PAR_GRAN] in [J.GRAN_TC, B.PAR_TESTCASE]: description = J.CHOICE_TC choiceList = job_tool.select_testcase(job, programDef, args) p = B.PAR_TESTCASE if J.ARG_TESTELEM in programDef[basic.program.CTLG_PARDEF]: args[J.ARG_TESTELEM] = p elif p == B.PAR_COMP: description = J.CHOICE_ENV choiceList = job_tool.select_components(job, programDef, args[B.PAR_PROJ], args[B.PAR_APP]) choiceAll = ",".join(choiceList) choiceList.append(choiceAll) elif p == B.PAR_ENV: description = J.CHOICE_ENV choiceList = job_tool.select_environment(job, programDef, args[B.PAR_PROJ]) elif p in [B.PAR_TESTPLAN, B.PAR_TESTSUITE, B.PAR_TESTCASE]: if args[JOB_PROC] == J.PROC_REDO_EXECUTION: description = J.CHOICE_ARCHIV choiceList = job_tool.select_archiv(job, programDef, args[B.PAR_GRAN], args[B.PAR_APP]) else: args[B.PAR_STEP] = "1" description = J.CHOICE_SPEC choiceList = job_tool.select_spec(job, programDef, args[B.PAR_GRAN], args) elif p in [B.PAR_TSTIME, B.PAR_TCTIME] and args[JOB_PROC] in [J.PROC_REDO_EXECUTION]: description = J.CHOICE_TIME choiceList = job_tool.select_testtime(job, programDef, args[B.PAR_GRAN], args) elif p == B.PAR_VAR: description = J.CHOICE_VARIANT choiceList = job_tool.select_variant(job, programDef, args[B.PAR_GRAN], args) else: continue if choiceList is None: job.m.logError(verify, "choiceList in None "+p) args[p] = getChoice(job, choiceList, description) job.m.logDebug(verify, args) job_tool.write_child_args(job, args) job_tool.start_child_process(job, args) childDialog(job) def childDialog(job): """ dialog to manage the child-process :param job: :return: """ args = job_tool.read_child_args(job) print("+-----------------------------------------------") for p in args: if p in [JOB_PROC]: continue if len(args[p]) < 1: continue print('+ {:12s} : {:60s}'.format(p, str(args[p]))) print("+-----------------------------------------------") initDialog(job) if __name__ == '__main__': 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)