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.

157 lines
5.9 KiB

2 years ago
import unittest
import os
import inspect
3 years ago
import utils.path_tool
2 years ago
import basic.program
import basic.constants as B
import test.constants
2 years ago
import test.testtools
import utils.path_const as P
3 years ago
HOME_PATH = test.constants.HOME_PATH
2 years ago
OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_key", "test_rejoinPath", "test_rejoinPath", "test_composePath", "test_composePattern",
"test_extractPath", "test_extractPattern"]
#TEST_FUNCTIONS = [ "test_extractPath"]
3 years ago
class MyTestCase(unittest.TestCase):
2 years ago
mymsg = "--------------------------------------------------------------"
2 years ago
def setTestPaths(self, job):
# here you can overwrite your workspace-configuration in order to get stable unittests
job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_HOME] = "home/unittest"
job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA] = "home/unittest/tdata"
job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV] = "home/unittest/env"
job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV] = "home/unittest/archiv"
pass
2 years ago
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_key(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
res = utils.path_tool.getKeyValue("job.par."+B.PAR_ENV, None)
self.assertEqual(res, test.testtools.DEFAULT_ENV)
cnttest += 1
for par in [B.ATTR_PATH_TDATA, B.ATTR_PATH_ARCHIV, B.ATTR_PATH_ENV, B.ATTR_PATH_PROGRAM]:
res = utils.path_tool.getKeyValue("job.conf."+par, None)
self.assertIn(HOME_PATH, res)
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
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 = utils.path_tool.rejoinPath("home", "ulrich")
self.assertEqual(res, "/home/ulrich")
cnttest += 1
res = utils.path_tool.rejoinPath("opt")
self.assertEqual(res, "/opt")
cnttest += 1
res = utils.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()
pt = utils.path_tool.PathConf()
2 years ago
self.setTestPaths(job)
self.setPathConfig(pt)
# tests
path = utils.path_tool.composePath(P.P_ENVBASE, None)
self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path)
self.assertIn(getattr(job.par, B.PAR_ENV), path)
cnttest += 2
path = utils.path_tool.composePath(P.P_TCLOG, None)
self.assertIn(job.conf.confs[B.SUBJECT_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_composePattern(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()
pt = utils.path_tool.PathConf()
self.setTestPaths(job)
self.setPathConfig(pt)
# tests
path = utils.path_tool.composePattern("{"+P.P_ENVBASE+"}", None)
self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path)
self.assertIn(getattr(job.par, B.PAR_ENV), 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 = utils.path_tool.PathConf()
job = test.testtools.getJob("ts", test.testtools.DEFAULT_APP, test.testtools.DEFAULT_ENV, "2021-08-21_18-ß2-01")
r = utils.path_tool.extractPattern("tsbase" )
3 years ago
self.assertEqual(r[0][1], "job.conf.archiv")
2 years ago
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 = utils.path_tool.PathConf()
r = utils.path_tool.extractPath("tsbase" , os.path.join(HOME_PATH, "test","conf","lauf","testlauf","startjob_2021-08-21_10-02-01"))
print("r " + str(r))
#print(vars(job.par))
2 years ago
#self.assertEqual(job.par.release, "V0.1")
3 years ago
self.assertEqual(job.par.usecase, "startjob")
2 years ago
self.assertEqual(job.par.tstime, "2021-08-21_10-02-01")
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_zzz(self):
print(MyTestCase.mymsg)
3 years ago
if __name__ == '__main__':
unittest.main()