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.
 
 
 

165 lines
7.2 KiB

import unittest
import os
import inspect
import shutil
import utils.path_tool
from basic.program import Job
from basic.componentHandling import ComponentManager
import basic.step
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
HOME_PATH = test.constants.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_00create"]
class MyTestCase(unittest.TestCase):
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):
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", "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):
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-08-18_14-23-34"
fct = "read_TData"
if "init_testcase" in programs:
program = "init_testcase"
job = Job("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),
"step": 1}
job.par.setParameterArgs(job, args)
job.setProgram(program)
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"
job = Job("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),
"step": 2}
test_executer.startStepProgram(step, job, args)
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)
if __name__ == '__main__':
unittest.main()