Browse Source

start-dialog

refactor
Ulrich 2 years ago
parent
commit
a03c68d3b3
  1. 40
      catalog/programs.csv
  2. 152
      start_dialog.py
  3. 212
      test/test_71job.py
  4. 9
      test/testtools.py
  5. 5
      tools/date_tool.py
  6. 4
      tools/job_const.py
  7. 33
      tools/job_tool.py
  8. 8
      tools/value_tool.py

40
catalog/programs.csv

@ -1,21 +1,23 @@
_key;name;;;;;;;;;;;;;
table:programs;name;objtype;objname;time;env;app;variant;pardef;pfilesource;pfiletarget;dirname;basedir;loglevel;logpath
;test_executer;tp,ts,tc;m;m;m;m;o;;;;{objtype}dir;{objtype}base;info;{job.par.wsdir}/{log}/log_{job.start}.txt
;init_testsuite;ts;m;o;m;m;o;;envparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;execute_testsuite;ts;m;m;m;m;o;;tsparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;collect_testsuite;ts;m;m;m;m;o;;tsparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;finish_testsuite;ts;m;m;m;m;o;;tsparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;unzip_testsuite;ts;m;m;m;m;o;;;;;;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;init_testcase;tc;m;o;m;m;o;;tsparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt
;exec_testcase;tc;m;m;m;m;o;;tcparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt
;collect_testcase;tc;m;m;m;m;o;;tcparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt
;compare_testcase;tc;m;m;m;m;o;;tcparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt
;check_environment;env;;;m;;o;"{""par"":{""application"":""service"",""environment"":""args"",""variant"":""""}}";;envparfile;envdir;envbase;info;{job.par.envdir}/{log}/log_{job.start}.txt
;check_specification;tp,ts,tc;o;;;;n;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt
;check_configuration;ws;o;;;o;n;"{""par"":{""application"":""args"",""environment"":""Testserver"",""variant"":""""}}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt
;make_workspace;ws;;;_;;n;"{""par"":{""application"":""service"",""environment"":""Testserver"",""variant"":""""}}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt
;unit_tester;ws;o;;d;;n;"{""par"":{""application"":""service"",""environment"":""Testserver"",""variant"":""""}}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt
;declare_expection;ts,tc;m;m;m;m;o;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt
;clean_workspace;ws;o ;;_;;n;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt
;start_dialog;ws;input;;input;input;input;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/log_{job.start}.txt
;web_start;ws;;;;;n;;;;wsdir;wsbase;warn;{job.par.wsdir}/{log}/log_{job.start}.txt
;test_executer;tp,ts,tc;m;m;m;m;o;"{""gran"":""args"",""application"":""args"",""environment"":""args"",""testelem"":""args"",""variant"":""args""}";;;{objtype}dir;{objtype}base;info;{job.par.wsdir}/{log}/log_{job.start}.txt
;init_testsuite;ts;m;o;m;m;o;"{""gran"":""testsuite"",""application"":""args"",""environment"":""args"",""testsuite"":""args"",""variant"":""args""}";envparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;execute_testsuite;ts;m;m;m;m;o;"{""gran"":""testsuite"",""application"":""args"",""environment"":""args"",""testsuite"":""args"",""tstime"":""args"",""variant"":""args""}";tsparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;collect_testsuite;ts;m;m;m;m;o;"{""gran"":""testsuite"",""application"":""args"",""environment"":""args"",""testsuite"":""args"",""tstime"":""args"",""variant"":""args""}";tsparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;finish_testsuite;ts;m;m;m;m;o;"{""gran"":""testsuite"",""application"":""args"",""environment"":""args"",""testsuite"":""args"",""tstime"":""args"",""variant"":""args""}";tsparfile;tsparfile;tsdir;tsbase;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;unzip_testsuite;ts;m;m;m;m;o;"{""gran"":""testsuite"",""application"":""args"",""environment"":""args"",""testsuite"":""args"",""tstime"":""args"",""variant"":""args""}";;;;;info;{job.par.tsdir}/{log}/{job.program}_{job.start}.txt
;init_testcase;tc;m;o;m;m;o;"{""gran"":""testcase"",""application"":""args"",""environment"":""args"",""testcase"":""args"",""tctime"":""args"",""variant"":""args""}";tsparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt
;exec_testcase;tc;m;m;m;m;o;"{""gran"":""testcase"",""application"":""args"",""environment"":""args"",""testcase"":""args"",""tctime"":""args"",""variant"":""args""}";tcparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt
;collect_testcase;tc;m;m;m;m;o;"{""gran"":""testcase"",""application"":""args"",""environment"":""args"",""testcase"":""args"",""tctime"":""args"",""variant"":""args""}";tcparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt
;compare_testcase;tc;m;m;m;m;o;"{""gran"":""testcase"",""application"":""args"",""environment"":""args"",""testcase"":""args"",""tctime"":""args"",""variant"":""args""}";tcparfile;tcparfile;tcdir;tcbase;info;{job.par.tcdir}/{log}/{job.program}_{job.start}.txt
;check_environment;env;;;m;;o;"{""application"":""args"",""environment"":""args""}";;envparfile;envdir;envbase;info;{job.par.envdir}/{log}/{job.program}_{job.start}.txt
;check_specification;tp,ts,tc;o;;;;n;"{""gran"":""args"",""application"":""args"",""environment"":""args"",""testcase"":""args"",""tctime"":""args"",""variant"":""args""}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/{job.program}_{job.start}.txt
;check_configuration;ws;o;;;o;n;"{""application"":""args"",""environment"":""args""}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/{job.program}_{job.start}.txt
;make_workspace;ws;;;_;;n;"{""application"":""service"",""environment"":""Testserver""}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/{job.program}_{job.start}.txt
;unit_tester;ws;o;;d;;n;"{""application"":""service"",""environment"":""Testserver""}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/{job.program}_{job.start}.txt
;declare_expection;ts,tc;m;m;m;m;o;"{""application"":""service"",""environment"":""Testserver""}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/{job.program}_{job.start}.txt
;clean_workspace;ws;o ;;_;;n;"{""application"":""service"",""environment"":""Testserver""}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/{job.program}_{job.start}.txt
;start_dialog;ws;input;;input;input;input;"{""gran"":""service"",""application"":""select-app"",""environment"":""select-env""}";;;wsdir;wsbase;info;{job.par.wsdir}/{log}/{job.program}_{job.start}.txt
;web_start;ws;;;;;n;"{""application"":""service"",""environment"":""Testserver""}";;;wsdir;wsbase;warn;{job.par.wsdir}/{log}/{job.program}_{job.start}.txt
;unzip_result;tp,ts,tc;o;;;;n;"{""par"":{""application"":""service"",""environment"":""Testserver"",""variant"":""""}}";;;wsdir;wsbase;info;{wsbase}/{log}/{job.program}_{job.start}.txt
;sync_model;;;;;;;;;;wsdir;wsbase;info;{job.par.wsdir}/{log}/{job.program}_{job.start}.txt

1 _key name
2 table:programs name objtype objname time env app variant pardef pfilesource pfiletarget dirname basedir loglevel logpath
3 test_executer tp,ts,tc m m m m o {"gran":"args","application":"args","environment":"args","testelem":"args","variant":"args"} {objtype}dir {objtype}base info {job.par.wsdir}/{log}/log_{job.start}.txt
4 init_testsuite ts m o m m o {"gran":"testsuite","application":"args","environment":"args","testsuite":"args","variant":"args"} envparfile tsparfile tsdir tsbase info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
5 execute_testsuite ts m m m m o {"gran":"testsuite","application":"args","environment":"args","testsuite":"args","tstime":"args","variant":"args"} tsparfile tsparfile tsdir tsbase info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
6 collect_testsuite ts m m m m o {"gran":"testsuite","application":"args","environment":"args","testsuite":"args","tstime":"args","variant":"args"} tsparfile tsparfile tsdir tsbase info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
7 finish_testsuite ts m m m m o {"gran":"testsuite","application":"args","environment":"args","testsuite":"args","tstime":"args","variant":"args"} tsparfile tsparfile tsdir tsbase info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
8 unzip_testsuite ts m m m m o {"gran":"testsuite","application":"args","environment":"args","testsuite":"args","tstime":"args","variant":"args"} info {job.par.tsdir}/{log}/{job.program}_{job.start}.txt
9 init_testcase tc m o m m o {"gran":"testcase","application":"args","environment":"args","testcase":"args","tctime":"args","variant":"args"} tsparfile tcparfile tcdir tcbase info {job.par.tcdir}/{log}/{job.program}_{job.start}.txt
10 exec_testcase tc m m m m o {"gran":"testcase","application":"args","environment":"args","testcase":"args","tctime":"args","variant":"args"} tcparfile tcparfile tcdir tcbase info {job.par.tcdir}/{log}/{job.program}_{job.start}.txt
11 collect_testcase tc m m m m o {"gran":"testcase","application":"args","environment":"args","testcase":"args","tctime":"args","variant":"args"} tcparfile tcparfile tcdir tcbase info {job.par.tcdir}/{log}/{job.program}_{job.start}.txt
12 compare_testcase tc m m m m o {"gran":"testcase","application":"args","environment":"args","testcase":"args","tctime":"args","variant":"args"} tcparfile tcparfile tcdir tcbase info {job.par.tcdir}/{log}/{job.program}_{job.start}.txt
13 check_environment env m o {"par":{"application":"service","environment":"args","variant":""}} {"application":"args","environment":"args"} envparfile envdir envbase info {job.par.envdir}/{log}/log_{job.start}.txt {job.par.envdir}/{log}/{job.program}_{job.start}.txt
14 check_specification tp,ts,tc o n {"gran":"args","application":"args","environment":"args","testcase":"args","tctime":"args","variant":"args"} wsdir wsbase info {job.par.wsdir}/{log}/log_{job.start}.txt {job.par.wsdir}/{log}/{job.program}_{job.start}.txt
15 check_configuration ws o o n {"par":{"application":"args","environment":"Testserver","variant":""}} {"application":"args","environment":"args"} wsdir wsbase info {job.par.wsdir}/{log}/log_{job.start}.txt {job.par.wsdir}/{log}/{job.program}_{job.start}.txt
16 make_workspace ws _ n {"par":{"application":"service","environment":"Testserver","variant":""}} {"application":"service","environment":"Testserver"} wsdir wsbase info {job.par.wsdir}/{log}/log_{job.start}.txt {job.par.wsdir}/{log}/{job.program}_{job.start}.txt
17 unit_tester ws o d n {"par":{"application":"service","environment":"Testserver","variant":""}} {"application":"service","environment":"Testserver"} wsdir wsbase info {job.par.wsdir}/{log}/log_{job.start}.txt {job.par.wsdir}/{log}/{job.program}_{job.start}.txt
18 declare_expection ts,tc m m m m o {"application":"service","environment":"Testserver"} wsdir wsbase info {job.par.wsdir}/{log}/log_{job.start}.txt {job.par.wsdir}/{log}/{job.program}_{job.start}.txt
19 clean_workspace ws o _ n {"application":"service","environment":"Testserver"} wsdir wsbase info {job.par.wsdir}/{log}/log_{job.start}.txt {job.par.wsdir}/{log}/{job.program}_{job.start}.txt
20 start_dialog ws input input input input {"gran":"service","application":"select-app","environment":"select-env"} wsdir wsbase info {job.par.wsdir}/{log}/log_{job.start}.txt {job.par.wsdir}/{log}/{job.program}_{job.start}.txt
21 web_start ws n {"application":"service","environment":"Testserver"} wsdir wsbase warn {job.par.wsdir}/{log}/log_{job.start}.txt {job.par.wsdir}/{log}/{job.program}_{job.start}.txt
22 unzip_result tp,ts,tc o n {"par":{"application":"service","environment":"Testserver","variant":""}} wsdir wsbase info {wsbase}/{log}/{job.program}_{job.start}.txt
23 sync_model wsdir wsbase info {job.par.wsdir}/{log}/{job.program}_{job.start}.txt

152
start_dialog.py

@ -23,20 +23,21 @@ import io
import sys
import basic.program
import basic.constants as B
import tools.job_tool
import tools.job_tool as job_tool
import model.catalog
import tools.job_const as J
PROGRAM_NAME = "start_dialog"
VERIFY = False
verbose = False
def startPyJob(job):
# for debugging write
setattr(job.par, "tool", "job_tool")
# check if an actual job is stored
childArgs = tools.job_tool.read_child_args(job)
childArgs = job_tool.read_child_args(job)
if childArgs is None:
childArgs = initDialog(job)
else:
childDialog(job)
pass
def getChoice(job, choiselist, description):
@ -48,6 +49,12 @@ def getChoice(job, choiselist, 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:
@ -55,6 +62,7 @@ def getChoice(job, choiselist, description):
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)
@ -65,6 +73,7 @@ def getChoice(job, choiselist, description):
print("FEHLER Fehleingabe "+choice)
getChoice(job, choiselist, description)
else:
if verbose: print("treffer "+str(choiselist))
return choiselist[int(choice) - 1]
@ -75,54 +84,125 @@ def initDialog(job, args={}):
:return:
"""
# which process
verify = job.m.getLogLevel("job_tool")
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["proc"] = getChoice(job, J.LIST_PROC, "Welchen Prozess starten")
args[J.MODEL_GRAN] = ""
args[B.PAR_USER] = job_tool.getUser()
args[B.PAR_PROJ] = job_tool.getUserProject()
args[B.PAR_STEP] = ""
job.m.logTrace(verify, args["proc"])
# """
if args["proc"] == J.PROC_TP_EXECUTION:
#args[J.MODEL_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_PROGRAM] = J.PROG_TEST_EXECUTER
elif args["proc"] in [J.PROC_TS_STEPWISE, J.PROC_TS_EXECUTION]:
#args[J.MODEL_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
if args["proc"] == J.PROC_TS_EXECUTION:
args[B.PAR_PROGRAM] = J.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_PROGRAM] = J.PROG_TS_INIT
elif args["proc"] in [J.PROC_TC_STEPWISE, J.PROC_TC_EXECUTION]:
#args[J.MODEL_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
if args["proc"] == J.PROC_TC_EXECUTION:
args[B.PAR_PROGRAM] = J.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,
args[B.PAR_PROGRAM] = J.PROG_TC_INIT
elif args["proc"] == J.PROC_REDO_EXECUTION:
args[B.PAR_PROGRAM] = getChoice(job, J.LIST_TS_PROGS + J.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")
elif args["proc"] == J.PROC_SINGLE_JOB:
args[B.PAR_PROGRAM] = getChoice(job, J.LIST_SERVICE_PROG, "Welches Programm starten")
else:
args["gran"] = ""
args[J.MODEL_GRAN] = ""
args[J.MODEL_GRAN] = ""
# """2
catalog = model.catalog.Catalog.getInstance()
programDef = catalog.getValue(job, basic.program.CTLG_NAME, args[B.PAR_PROGRAM], "")
job.m.logTrace(verify, "programdefinition "+str(programDef))
if verbose: print("programdefinition "+args[B.PAR_PROGRAM]+" "+str(programDef))
for p in programDef[basic.program.CTLG_PARDEF]:
if p in args:
print("p "+p+" ist "+args[p])
job.m.logTrace(verify, "progCtlog "+p+":")
job.m.logTrace(verify, args)
if verbose: print(" "+p+" "+str(args))
if p in args and len(args[p]) > 0:
if verbose: print("arg: " + p+" "+args[p])
job.m.logDebug(verify, "progArg "+p+" ist "+args[p])
elif 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 == J.ARG_TESTELEM:
if verbose: print("testelem "+args[B.PAR_GRAN])
if 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
elif 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
elif 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
else:
raise Exception("unknown testgranularity "+args[B.PAR_GRAN])
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["proc"] == J.PROC_REDO_EXECUTION:
description = J.CHOICE_ARCHIV
choiceList = job_tool.select_archiv(job, programDef, args[J.MODEL_GRAN], args[B.PAR_APP])
else:
args[B.PAR_STEP] = "1"
description = J.CHOICE_SPEC
choiceList = job_tool.select_spec(job, programDef, args[J.MODEL_GRAN], args)
elif p in [B.PAR_TSTIME, B.PAR_TCTIME] and args["proc"] in [J.PROC_REDO_EXECUTION]:
description = J.CHOICE_TIME
choiceList = job_tool.select_testtime(job, programDef, args[J.MODEL_GRAN], args)
elif p == B.PAR_VAR:
description = J.CHOICE_VARIANT
choiceList = job_tool.select_variant(job, programDef, args[J.MODEL_GRAN], args)
else:
continue
if choiceList is None:
job.m.logError(verify, "choiceList in None "+p)
args[p] = getChoice(job, choiceList, description)
else:
args[p] = programDef[basic.program.CTLG_PARDEF][p]
print("p "+p+" jetzt " + args[p])
print(str(args))
job.m.logDebug(verify, "p "+p+" jetzt ")
job.m.logDebug(verify, args[p])
job.m.logDebug(verify, args)
job_tool.write_child_args(job, args)
job_tool.start_child_process(job, args)
childDialog(job)
def childDialog(job, args):
def childDialog(job):
"""
dialog to manage the child-process
:param job:
:return:
"""
pass
args = job_tool.read_child_args(job)
print("+-----------------------------------------------")
for p in args:
if p in ["proc"]:
continue
if len(args[p]) < 1:
continue
print('+ {:12s} : {:60s}'.format(p, args[p]))
print("+-----------------------------------------------")
initDialog(job)
if __name__ == '__main__':
job = basic.program.Job(PROGRAM_NAME)

212
test/test_71job.py

@ -2,9 +2,9 @@ import unittest
import os
import inspect
import shutil
"""
import execute_testcase
import utils.path_tool
import tools.path_tool
from basic.program import Job
from basic.componentHandling import ComponentManager
import basic.step
@ -12,211 +12,37 @@ import init_testcase
import test_executer
import test.constants
import basic.constants as B
import test.constants as T
import basic.componentHandling
import utils.file_tool
import tools.file_tool
"""
import basic.program
import tools.job_tool as job_tool
import test.constants as T
import test.testtools
HOME_PATH = test.constants.HOME_PATH
HOME_PATH = T.HOME_PATH
PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key",
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv", "test_smokeTestcase"]
TEST_FUNCTIONS = ["test_smokeTestcase"]
#TEST_FUNCTIONS = [ "test_smokeTestcase"]
TEST_FUNCTIONS = ["test_actProgram"]
PROGRAM_NAME = "unit_tester"
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_01create(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))
args = { "application" : "TESTAPP" , "environment" : "ENV01", "step": "2", "tcdir": "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-12-08"}
job.par.setParameterArgs(job, args)
self.assertEqual(getattr(job.par, B.PAR_TESTCASE), "TC0001")
self.assertEqual(getattr(job.par, B.PAR_TCTIME), "2022-09-10_12-12-08")
job.setProgram("init_testcase")
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_00create(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
#
# start a webflask-job - a temp. job for responding an html-request, - with session-parameter?
args = {}
job = basic.program.Job("webflask", args)
print(str(job.par))
args = { B.PAR_APP: "TESTAPP" , B.PAR_ENV: "ENV01", B.PAR_STEP: "2",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-12-08"}
job = basic.program.Job("unit", args)
print(str(job))
#job.par.setParameterArgs(job, args)
self.assertEqual(hasattr(job.par, B.PAR_TESTCASE), False)
self.assertEqual(hasattr(job.par, B.PAR_TCTIME), False)
self.assertEqual(True, hasattr(job, "m"))
msg = job.m
self.assertNotIn("testdata", msg.logfile.name)
#
# start a testing-job as unit-test - without log ?! - artifacts would be saved in tcdir
# in unit-tests often there is a dir not necessary
args = { B.PAR_APP: "TESTAPP" , B.PAR_ENV: "ENV01", B.PAR_STEP: "1", B.PAR_MODUS: "unit",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-12-08"}
job = basic.program.Job("init_testcase", args)
print(str(job))
self.assertEqual(getattr(job.par, B.PAR_TESTCASE), "TC0001")
self.assertEqual(getattr(job.par, B.PAR_TCTIME), "2022-09-10_12-12-08")
self.assertEqual(hasattr(job, "m"), True)
self.assertNotIn("testdata", msg.logfile.name)
args = { B.PAR_APP: "TESTAPP" , B.PAR_ENV: "ENV01", B.PAR_STEP: "1",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-22-08"}
job = basic.program.Job("init_testcase", args)
print(str(job))
self.assertEqual(getattr(job.par, B.PAR_TESTCASE), "TC0001")
self.assertEqual(getattr(job.par, B.PAR_TCTIME), "2022-09-10_12-22-08")
self.assertEqual(hasattr(job, "m"), True)
self.assertNotIn("testdata", msg.logfile.name)
#
# start a job for workspace-reorganization - appending to central log
args = { B.PAR_APP: "TESTAPP",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-22-08"}
job = basic.program.Job("declare_result", args)
print(str(job.par))
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parameter(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = Job("unit")
args = { "application" : "TEST" , "environment" : "ENV01", B.PAR_MODUS : "unit", "loglevel" : "debug",
"tool" : "job_tool", "function": "reset_TData,load_TData" }
job.par.setParameterArgs(job, args)
self.assertEqual(job.hascomponente("TestA"), True)
self.assertEqual(job.hasTool("TestA"), False)
self.assertEqual(job.hasTool("job_tool"), True)
self.assertEqual(job.getDebugLevel("file_tool"), 23)
self.assertEqual(job.getDebugLevel("job_tool"), 23)
self.assertEqual(job.hasFunction("reset_TData"), True)
self.assertEqual(job.hasFunction("load_TData"), True)
self.assertEqual(job.hasFunction("read_TData"), False)
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")}
job.par.setParameterArgs(job, args)
def test_run(self):
def test_actProgram(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
programs = ["init_testcase"]
testcase = "TC0001"
timexec = "2022-06-28_21-23-34"
fct = "read_TData"
# os.system("python "+os.path.join(HOME_PATH, "check_environment.py")+" -a TEST -e ENV01")
# os.system("python "+os.path.join(HOME_PATH, "init_testsuite.py")+" -a TEST -e ENV01 "
# "-ts "+os.path.join(HOME_PATH, "test","lauf","V0.1","implement_2021-08-28_23-50-51")+" -dt csv -ds implement -dn firstunit")
#os.system(PYTHON_CMD+" "+os.path.join(HOME_PATH,"init_testcase.py")+" -a TEST -e ENV01 "
# "-tc "+os.path.join(HOME_PATH,"test","lauf","V0.1","TC0001","2021-08-28_23-50-51")+" -dt csv -ds implement -dn TC0001")
#args = { "application": "TEST", "environment": "ENV01", "modus": "unit",
# "tool": "job_tool", "tsdir": os.path.join(HOME_PATH,"test","conf","lauf","V0.1","TC0001_2021-08-28_23-50-51")}
#"loglevel": "debug", "tdtyp": "dir",
# "tdsrc": "TC0001", "tdname": "xxx",
if "init_testcase" in programs:
program = "init_testcase"
job = Job("unit")
args = { B.PAR_APP: "TESTAPP", B.PAR_ENV: "ENV01", "modus": "unit", B.PAR_FCT: fct,
B.PAR_TCDIR: os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 1 }
# "usecase": "TST001", "tstime": "2022-03-17_17-28"}
job.par.setParameterArgs(job, args)
job.setProgram(program)
init_testcase.startPyJob(job)
job.startJob()
#test_executer.start(job)
job.stopJob(1)
def test_smokeTestcase(self):
"""
the functions starts a test-roundtrip with dry unit-tests
1. simulate the test-object - copy results from testdata_preconditions into local env-directory
2. init_testcase - databases as csv in local env-directory
3. simulate the test-object - copy results from testdata_postconditions into local env-directory
4. execute_testcase - send=copy to local env-directory
- receive=read from local env-directory
5. collect_testcase - read from local env-directory
6. compare_testcase -
:return:
"""
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
# basic parameter
programs = ["copy_precondition", "init_testcase", "copy_postcondition", "execute_testcase",
"collect_testcase", "compare_testcase"]
programs = ["execute_testcase"]
testcase = "TC0001"
timexec = "2022-09-17_08-23-34"
fct = "read_TData"
if "init_testcase" in programs:
program = "init_testcase"
ujob = Job("unit", {})
args = {B.PAR_APP: "TESTAPP", B.PAR_ENV: "ENV01",
B.PAR_TCDIR: os.path.join(ujob.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 1}
job = Job("init_testcase", args)
if "copy_precondition" in programs:
copyAppData(job, program, "tdpreexec")
pass
job.startJob()
init_testcase.startPyJob(job)
job.stopJob(1)
if "execute_testcase" in programs:
program = "execute_testcase"
step = basic.step.Step()
step.start = "execute_testcase"
ujob = Job("unit", {})
args = {B.PAR_APP: "TESTAPP", B.PAR_ENV: "ENV01",
B.PAR_TCDIR: os.path.join(ujob.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 2}
job = Job("execute_testcase", args)
job.startJob()
execute_testcase.startPyJob(job)
job.stopJob(1)
print("fertig")
def copyAppData(job, program, tdsource):
cm = basic.componentHandling.ComponentManager.getInstance(job, "init")
print("cm " + str(cm))
cm.initComponents()
comps = cm.getComponents(program)
for c in comps:
comp = cm.getComponent(c)
tdatapath = utils.path_tool.composePattern(job, "{"+tdsource+"}", comp)
envapppath = utils.path_tool.composePattern(job, "{envappdir}", comp)
if os.path.exists(tdatapath):
files = utils.file_tool.getFiles(job.m, job, tdatapath, ".+\.csv", None)
for f in files:
# shutil.copy()
print("cp " + os.path.join(tdatapath, f) + " " + os.path.join(envapppath, f))
utils.file_tool.mkPaths(job, os.path.join(envapppath, f), job.m)
shutil.copy(os.path.join(tdatapath, f), os.path.join(envapppath, f))
print(tdatapath)
job = test.testtools.getTestJob()
print("test_actProgram ++++++++++++++++++")
print("job "+str(job.__dict__))
args = job_tool.read_child_args(job)
print("args "+str(args))
job_tool.start_child_process(job, args)
if __name__ == '__main__':

9
test/testtools.py

@ -82,6 +82,15 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
job = basic.program.Job("unit_tester", "", args)
return job
def getTestJob():
args = {}
args[B.PAR_PROGRAM] = "unit_tester"
args[B.PAR_APP] = "service"
args[B.PAR_PROJ] = "TESTAPP"
args[B.PAR_ENV] = "Testserver"
job = basic.program.Job(args[B.PAR_PROGRAM], "", args)
return job
def getComp(job, componentName=""):
comp = basic.component.Component()

5
tools/date_tool.py

@ -19,8 +19,9 @@ MONTH_EN = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct"
MONTH_DE = ["jan", "feb", "mar", "apr", "mai", "jun", "jul", "aug", "sep", "okt", "nov", "dez"]
F_TIME_DEFAULT = F_DIR
def getActdate(format):
return getFormatdate(datetime.datetime.now(), format)
def getActdate(format, diffDays=0):
actDate = datetime.datetime.now() + datetime.timedelta(days=diffDays)
return getFormatdate(actDate, format)
def getFormatdate(date, format):

4
tools/job_const.py

@ -37,6 +37,7 @@ GRAN_TC = "Testfall"
LIST_GRAN = [GRAN_TP, GRAN_TS, GRAN_TC]
MODEL_PROC = "proc"
MODEL_GRAN = "gran"
ARG_TESTELEM = "testelem"
MODEL_APP = B.PAR_APP
MODEL_ENV = B.PAR_ENV
MODEL_COMP = B.PAR_COMP
@ -46,6 +47,9 @@ CHOICE_GRAN = "Testgranularitaet auswaehlen"
CHOICE_APP = "Anwendung auswaehlen"
CHOICE_ENV = "Umgebung auswaehlen"
CHOICE_SPEC = "Testspezifikation auswaehlen"
CHOICE_TP = "Testplan auswaehlen"
CHOICE_TS = "Testsuite auswaehlen"
CHOICE_TC = "Testfall auswaehlen"
CHOICE_ARCHIV = "Testausfuehrung auswaehlen"
CHOICE_TIME = "Testzeit auswaehlen"
CHOICE_VARIANT = "Testvariante auswaehlen"

33
tools/job_tool.py

@ -26,10 +26,13 @@ import sys
import json
import basic.program
import basic.constants as B
import tools.job_const as J
import check_environment
import check_specification
import check_configuration
import tools.job_const as J
import clean_workspace
import init_testsuite
import test_executer
try:
import collect_testcase
@ -37,8 +40,6 @@ try:
import execute_testcase
import finish_testsuite
import init_testcase
import init_testsuite
import test_executer
except Exception as e:
pass
import tools.path_tool
@ -97,9 +98,11 @@ def read_child_args(job):
def write_child_args(job, childArgs):
path = getActChildPath(job)
if os.path.exists(path):
sys.path.remove()
tools.file_tool.writeFileDict(job, path, childArgs)
print("job "+str(job.__dict__))
print("path "+path)
print("args "+str(childArgs))
tools.file_tool.writeFileDict(job.m, job, path, childArgs)
def start_child_process(job, args):
"""
@ -111,14 +114,14 @@ def start_child_process(job, args):
verifiy = job.getDebugLevel("job_tool")
job.m.logDebug(verifiy, "start_child_process")
job.m.logTrace(verifiy, args)
print(str(args))
print("args "+str(args))
path = tools.path_tool.getActualJsonPath(job)
tools.file_tool.writeFileDict(job.m, job, path, args)
childArgs = {}
for p in args:
if p in B.LIST_MAIN_PAR:
childArgs[p] = args[p]
if p in [B.PAR_USER]:
if p in [B.PAR_USER, B.PAR_STEP, B.PAR_PROJ]:
childArgs[p] = args[p]
if p in [B.PAR_TESTCASE, B.PAR_TCTIME]:
childArgs[B.PAR_TCTIME] = date_tool.getActdate(date_tool.F_LOG)
@ -166,6 +169,8 @@ def start_child_process(job, args):
check_configuration.startPyJob(childJob)
elif args[B.PAR_PROGRAM] == "check_specification":
check_specification.startPyJob(childJob)
elif args[B.PAR_PROGRAM] == "clean_workspace":
clean_workspace.startPyJob(childJob)
childJob.stopJob(1)
return childJob
@ -201,7 +206,6 @@ def select_environment(job, programDef, project):
read environments and select one of them
:return:
"""
print("selectr env "+project)
projList = [project]
envs = model.environment.select_environments(job, projList)
return list(envs.keys())
@ -265,3 +269,14 @@ def select_variant(job, programDef, gran, args):
raise Exception("for gran "+gran+" variant can not be selected")
print("select no spec "+gran)
def select_testplan(job, programDef, args):
outList = []
return outList
def select_testsuite(job, programDef, args):
outList = []
return outList
def select_testcase(job, programDef, args):
outList = model.testcase.select_testcases(job, [args[B.PAR_PROJ]], [args[B.PAR_APP]])
return outList

8
tools/value_tool.py

@ -56,10 +56,14 @@ def get_key_value(job, key, comp=None):
if verify: job.debug(verify, "getKeyValue " + key)
if DOM_JOB == key[0:3]:
a = key.split(".")
if DOM_PAR == a[1]:
if len(a) > 1:
k = a[1]
else:
k = key
if DOM_PAR == k:
val = job.getParameter(a[2])
return val
elif DOM_CONF == a[1]:
elif DOM_CONF == k:
val = job.conf[B.SUBJECT_PATH][a[2]]
if verify: job.debug(verify, val)
return val

Loading…
Cancel
Save