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.
 
 
 

117 lines
4.4 KiB

import unittest
import os
import inspect
import tools.path_tool
import basic.program
import basic.constants as B
import test.constants
import test.testtools
import tools.path_const as P
HOME_PATH = test.constants.HOME_PATH
DATA_PATH = test.constants.DATA_PATH
OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_rejoinPath", "test_rejoinPath", "test_extractPattern"]
#TEST_FUNCTIONS = ["test_key", "test_extractPath", "test_composePath"]
verbose = True
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def setTestPaths(self, job):
# here you can overwrite your workspace-configuration in order to get stable unittests
job.conf[B.TOPIC_PATH][B.ATTR_PATH_HOME] = "home/unittest"
job.conf[B.TOPIC_PATH][B.ATTR_PATH_TDATA] = "home/unittest/tdata"
job.conf[B.TOPIC_PATH][B.ATTR_PATH_ENV] = "home/unittest/env"
job.conf[B.TOPIC_PATH][B.ATTR_PATH_ARCHIV] = "home/unittest/archiv"
pass
def setPathConfig(self, pt):
# here you can overwrite your workspace-configuration in order to get stable unittests
paths = pt.getInstance()
paths.pattern[P.P_ENVBASE] = "{job.conf.environment}/{job.par.environment}"
def test_rejoinPath(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
if OS_SYSTEM == "linux":
res = tools.path_tool.rejoinPath("home", "ulrich")
self.assertEqual(res, "/home/ulrich")
cnttest += 1
res = tools.path_tool.rejoinPath("opt")
self.assertEqual(res, "/opt")
cnttest += 1
res = tools.path_tool.rejoinPath("http://domain.com", "application", "function")
self.assertEqual(res, "http://domain.com/application/function")
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_composePath(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
# set the relevant datastrutures
job = test.testtools.getJob()
comp = test.testtools.getComp(job, "testrest")
pt = tools.path_tool.PathConf(job)
self.setTestPaths(job)
self.setPathConfig(pt)
# tests
path = tools.path_tool.compose_path(job, P.P_ENVBASE, None)
self.assertIn(job.conf[B.TOPIC_PATH][B.ATTR_PATH_ENV], path)
self.assertIn(getattr(job.par, B.PAR_ENV), path)
cnttest += 2
path = tools.path_tool.compose_path(job, P.P_TCLOG, None)
self.assertIn(job.conf[B.TOPIC_PATH][B.ATTR_PATH_ARCHIV], path)
self.assertIn(getattr(job.par, B.PAR_TESTCASE), path)
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_extractPattern(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
pt = tools.path_tool.PathConf(job)
job = test.testtools.getJob("ts", test.testtools.DEFAULT_APP, test.testtools.DEFAULT_ENV, "2021-08-21_18-ß2-01")
r = tools.path_tool.extractPattern(job, "tsbase" )
self.assertEqual(r[0][1], "job.conf.archiv")
self.assertEqual(r[1][1], P.KEY_TESTSUITE)
self.assertEqual(r[1][2], "testlauf")
cnttest += 3
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_extractPath(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
pt = tools.path_tool.PathConf(job)
r = tools.path_tool.extractPath(job, "tsbase" , os.path.join(DATA_PATH, "lauf", "testlauf", "startjob_2021-08-21_10-02-01"))
if verbose: print("r " + str(r))
self.assertEqual(job.par.usecase, "startjob")
self.assertEqual(job.par.tstime, "2021-08-21_10-02-01")
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_zzz(self):
if verbose: print(MyTestCase.mymsg)
if __name__ == '__main__':
unittest.main()