Browse Source

unit-tests with main program

master
Ulrich Carmesin 2 years ago
parent
commit
cae2beaa60
  1. 19
      test/constants.py
  2. 52
      test/test_01date.py
  3. 39
      test/test_02css.py
  4. 12
      test/test_03path.py
  5. 3
      test/test_04config.py
  6. 27
      test/test_05conn.py
  7. 2
      test/test_06file.py
  8. 12
      test/test_07catalog.py
  9. 0
      test/test_11component.py
  10. 16
      test/test_12toolhandling.py
  11. 21
      test/test_21tdata.py
  12. 106
      test/test_22compare.py
  13. 0
      test/test_22report.py
  14. 7
      test/test_31db.py
  15. 78
      test/test_71job.py
  16. 23
      test/test_conn.py
  17. 2
      test/test_xml.py
  18. 2
      test/testtools.py
  19. 49
      unit_run.py

19
test/constants.py

@ -1,4 +1,17 @@
HOME_PATH = "/home/ulrich/6_Projekte/Programme/datest" """
DATA_PATH = "/home/ulrich/6_Projekte/Programme/data" constants
COMP_PATH = "/home/ulrich/6_Projekte/Programme/data/components" """
import os
home = os.getcwd()
prgdir = ""
if home[-6:] == "datest":
prgdir = home[-6:]
home = home[0:-7]
elif home[-7:] == "program":
prgdir = home[-7:]
home = home[0:-8]
HOME_PATH = home
DATA_PATH = os.path.join(home, "data")
PROG_PATH = os.path.join(home, prgdir)
COMP_PATH = os.path.join(home, prgdir, "components")
OS_SYSTEM = "linux" OS_SYSTEM = "linux"

52
test/test_date.py → test/test_01date.py

@ -3,72 +3,90 @@ import inspect
import unittest import unittest
import datetime import datetime
import utils.date_tool import utils.date_tool
import test.abstractTestcase
#TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"] TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"]
TEST_FUNCTIONS = ["test_parseFormula"] #TEST_FUNCTIONS = ["test_parseFormula"]
verbose = True
class MyTestCase(unittest.TestCase):
# class MyTestCase(unittest.TestCase):
class MyTestCase(test.abstractTestcase.MyTestCase):
TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"]
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"
"""
def runTest(self):
# -> Optional[unittest.result.TestResult]:
suite = unittest.TestSuite()
#suite.addTest(MyTestCase("test_dateformat"))
for t in TEST_FUNCTIONS:
suite.addTest(MyTestCase(t))
unittest.TextTestRunner().run(suite)
#suite = unittest.defaultTestLoader.loadTestsFromTestCase("MyTestCase")
if verbose: print("run own test " + str(suite))
"""
def test_dateformat(self): def test_dateformat(self, result=None):
if verbose: print(str(result))
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
if verbose: print("test_dateformat -------")
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
stime = datetime.datetime.now() stime = datetime.datetime.now()
print(stime) if verbose: print(stime)
tdate = (2022, 2, 10) tdate = (2022, 2, 10)
sdate = datetime.datetime(tdate[0], tdate[1],tdate[2], 3, 32, 23) sdate = datetime.datetime(tdate[0], tdate[1],tdate[2], 3, 32, 23)
sdate = datetime.datetime(stime) #sdate = datetime.datetime(stime)
print(sdate) if verbose: print(sdate)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parseFormula(self): def test_parseFormula(self, result=None):
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
res = utils.date_tool.parseFormula("{(21.12.2012 +1Y)}") res = utils.date_tool.parseFormula("{(21.12.2012 +1Y)}")
print(str(res)) if verbose: print(str(res))
self.assertEqual(res[0], 2013) self.assertEqual(res[0], 2013)
self.assertEqual(res[3], 0) self.assertEqual(res[3], 0)
res = utils.date_tool.parseFormula("{(21.12.2012 +1Y -1M)}") res = utils.date_tool.parseFormula("{(21.12.2012 +1Y -1M)}")
print(str(res)) if verbose: print(str(res))
self.assertEqual(res[0], 2013) self.assertEqual(res[0], 2013)
self.assertEqual(res[1], 11) self.assertEqual(res[1], 11)
self.assertEqual(res[3], 0) self.assertEqual(res[3], 0)
res = utils.date_tool.parseFormula("{(21.12.2012 +1 Jahre +20 Tage)}") res = utils.date_tool.parseFormula("{(21.12.2012 +1 Jahre +20 Tage)}")
print(str(res)) if verbose: print(str(res))
self.assertEqual(res[0], 2014) self.assertEqual(res[0], 2014)
self.assertEqual(res[1], 1) self.assertEqual(res[1], 1)
self.assertEqual(res[2], 10) self.assertEqual(res[2], 10)
self.assertEqual(res[3], 0) self.assertEqual(res[3], 0)
res = utils.date_tool.parseFormula("{(21.12.2012_11:12:43 +1Y)}") res = utils.date_tool.parseFormula("{(21.12.2012_11:12:43 +1Y)}")
print(str(res)) if verbose: print(str(res))
self.assertEqual(res[0], 2013) self.assertEqual(res[0], 2013)
self.assertEqual(res[5], 43) self.assertEqual(res[5], 43)
res = utils.date_tool.parseFormula("{(21.12.2012 -60M)}") res = utils.date_tool.parseFormula("{(21.12.2012 -60M)}")
print(str(res)) if verbose: print(str(res))
self.assertEqual(res[0], 2007) self.assertEqual(res[0], 2007)
self.assertEqual(res[1], 12) self.assertEqual(res[1], 12)
self.assertEqual(res[3], 0) self.assertEqual(res[3], 0)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parseDate(self): def test_parseDate(self, result=None):
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
res = utils.date_tool.parseDate("21.12.2012") res = utils.date_tool.parseDate("21.12.2012")
print(str(res)) if verbose: print(str(res))
self.assertEqual(res[0], 2012) self.assertEqual(res[0], 2012)
self.assertEqual(res[3], 0) self.assertEqual(res[3], 0)
res = utils.date_tool.parseDate("{(21.12.2012 +1Y)}") res = utils.date_tool.parseDate("{(21.12.2012 +1Y)}")
print(str(res)) if verbose: print(str(res))
self.assertEqual(res[0], 2012) self.assertEqual(res[0], 2013)
self.assertEqual(res[3], 0) self.assertEqual(res[3], 0)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

39
test/test_css.py → test/test_02css.py

@ -1,20 +1,30 @@
"""
unit-test
"""
import unittest import unittest
import utils.css_tool import utils.css_tool
import basic.program import basic.program
import json import json
# the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function
TEST_FUNCTIONS = ["test_01css"]
#TEST_FUNCTIONS = ["test_01css"]
# with this variable you can switch prints on and off
verbose = False
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def runTest(self): def runTest(self):
self.test_css() self.test_css()
def test_css(self): def test_01css(self):
job = basic.program.Job("unit") job = basic.program.Job("unit")
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug",
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", "tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit",
"modus": "unit"} "modus": "unit"}
job.par.setParameterArgs(args) job.par.setParameterArgs(args)
print("eeeeeeeee") if verbose: print("eeeeeeeee")
print(json.dumps(job.conf.confs)) if verbose: print(json.dumps(job.conf.confs))
# ------- inline --------------- # ------- inline ---------------
job.conf.setConfig("tools.csstyp", "inline") job.conf.setConfig("tools.csstyp", "inline")
job.conf.confs.get("tools")["csstyp"] == "inline" job.conf.confs.get("tools")["csstyp"] == "inline"
@ -40,38 +50,39 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(len(text), 15) self.assertEqual(len(text), 15)
self.assertEqual(("class" in text), True) self.assertEqual(("class" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles") text = utils.css_tool.getInternalStyle("diffFiles")
print(text) if verbose: print(text)
self.assertEqual(len(text), 262) self.assertEqual(len(text), 262)
self.assertEqual(("<style>" in text), True) self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("resultFile") text = utils.css_tool.getInternalStyle("resultFile")
print(text) if verbose: print(text)
self.assertEqual(len(text), 283) self.assertEqual(len(text), 283)
self.assertEqual(("<style>" in text), True) self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles,resultFile") text = utils.css_tool.getInternalStyle("diffFiles,resultFile")
print(text) if verbose: print(text)
self.assertEqual(len(text), 465) self.assertEqual(len(text), 465)
self.assertEqual(("<style>" in text), True) self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles") text = utils.css_tool.getExternalStyle("diffFiles")
self.assertEqual(len(text), 0) self.assertEqual(len(text), 0)
print(text) if verbose: print(text)
print(str(len(text))) if verbose: print(str(len(text)))
# ------- external --------------- # ------- external ---------------
job.conf.setConfig("tools.csstyp", "external") job.conf.setConfig("tools.csstyp", "external")
text = utils.css_tool.getInlineStyle("diffFiles", "diffA") text = utils.css_tool.getInlineStyle("diffFiles", "diffA")
self.assertEqual(len(text), 13) self.assertEqual(len(text), 13)
self.assertEqual(("class" in text), True) self.assertEqual(("class" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles") text = utils.css_tool.getInternalStyle("diffFiles")
print(text) if verbose: print(text)
self.assertEqual(len(text), 55) self.assertEqual(len(text), 55)
self.assertEqual(("<link " in text and "stylesheet" in text), True) self.assertEqual(("<link " in text and "stylesheet" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles") text = utils.css_tool.getExternalStyle("diffFiles")
self.assertEqual(len(text), 216) self.assertEqual(len(text), 216)
print(text) if verbose: print(text)
print(str(len(text))) if verbose: print(str(len(text)))
text = utils.css_tool.getExternalStyle("diffFiles,resultFile") text = utils.css_tool.getExternalStyle("diffFiles,resultFile")
self.assertEqual(len(text), 449) self.assertEqual(len(text), 449)
print(text) if verbose: print(text)
print(str(len(text))) if verbose: print(str(len(text)))
if __name__ == '__main__': if __name__ == '__main__':
verbose = True
unittest.main() unittest.main()

12
test/test_path.py → test/test_03path.py

@ -16,6 +16,7 @@ OS_SYSTEM = test.constants.OS_SYSTEM
TEST_FUNCTIONS = ["test_key", "test_rejoinPath", "test_rejoinPath", "test_composePath", "test_composePattern", TEST_FUNCTIONS = ["test_key", "test_rejoinPath", "test_rejoinPath", "test_composePath", "test_composePattern",
"test_extractPath", "test_extractPattern"] "test_extractPath", "test_extractPattern"]
#TEST_FUNCTIONS = [ "test_extractPath"] #TEST_FUNCTIONS = [ "test_extractPath"]
verbose = True
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"
@ -44,9 +45,10 @@ class MyTestCase(unittest.TestCase):
res = utils.path_tool.getKeyValue("job.par."+B.PAR_ENV, None) res = utils.path_tool.getKeyValue("job.par."+B.PAR_ENV, None)
self.assertEqual(res, test.testtools.DEFAULT_ENV) self.assertEqual(res, test.testtools.DEFAULT_ENV)
cnttest += 1 cnttest += 1
for par in [B.ATTR_PATH_TDATA, B.ATTR_PATH_ARCHIV, B.ATTR_PATH_ENV, B.ATTR_PATH_PROGRAM]: for par in [B.ATTR_PATH_ARCHIV, B.ATTR_PATH_ENV]:
res = utils.path_tool.getKeyValue("job.conf."+par, None) res = utils.path_tool.getKeyValue("job.conf."+par, None)
self.assertIn(HOME_PATH, res) if verbose: print("assertIn "+par+": "+res+" -- "+DATA_PATH)
self.assertIn(DATA_PATH, res)
cnttest += 1 cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -140,9 +142,7 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob() job = test.testtools.getJob()
pt = utils.path_tool.PathConf() pt = utils.path_tool.PathConf()
r = utils.path_tool.extractPath("tsbase" , os.path.join(DATA_PATH, "lauf", "testlauf", "startjob_2021-08-21_10-02-01")) r = utils.path_tool.extractPath("tsbase" , os.path.join(DATA_PATH, "lauf", "testlauf", "startjob_2021-08-21_10-02-01"))
print("r " + str(r)) if verbose: print("r " + str(r))
#print(vars(job.par))
#self.assertEqual(job.par.release, "V0.1")
self.assertEqual(job.par.usecase, "startjob") self.assertEqual(job.par.usecase, "startjob")
self.assertEqual(job.par.tstime, "2021-08-21_10-02-01") self.assertEqual(job.par.tstime, "2021-08-21_10-02-01")
cnttest += 2 cnttest += 2
@ -150,7 +150,7 @@ class MyTestCase(unittest.TestCase):
def test_zzz(self): def test_zzz(self):
print(MyTestCase.mymsg) if verbose: print(MyTestCase.mymsg)
if __name__ == '__main__': if __name__ == '__main__':

3
test/test_config.py → test/test_04config.py

@ -9,6 +9,7 @@ import utils.path_const as P
import basic.constants as B import basic.constants as B
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PROG_PATH = test.constants.PROG_PATH
TEST_FUNCTIONS = ["test_getConfig", "test_mergeAttributes"] TEST_FUNCTIONS = ["test_getConfig", "test_mergeAttributes"]
VERIFY = False VERIFY = False
@ -24,7 +25,7 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob() job = test.testtools.getJob()
x = "path" x = "path"
r = utils.config_tool.getConfigPath(P.KEY_TOOL, x) r = utils.config_tool.getConfigPath(P.KEY_TOOL, x)
self.assertIn(os.path.join(HOME_PATH, P.VAL_UTIL, P.VAL_CONFIG), r) self.assertIn(os.path.join(PROG_PATH, P.VAL_UTIL, P.VAL_CONFIG), r)
cnttest += 1 cnttest += 1
x = "conn" x = "conn"
r = utils.config_tool.getConfigPath(P.KEY_TOOL, x) r = utils.config_tool.getConfigPath(P.KEY_TOOL, x)

27
test/test_05conn.py

@ -0,0 +1,27 @@
import unittest
import basic.program
import utils.conn_tool
TEST_FUNCTIONS = ["test_01conn"]
#TEST_FUNCTIONS = ["test_01conn"]
verbose = True
class MyTestCase(unittest.TestCase):
def runTest(self):
self.test_conn()
def test_01conn(self):
if verbose: print("# # # # testComponents # # # # #")
job = basic.program.Job("unit")
args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug", "tool" : "job_tool"}
job.par.setParameterArgs(args)
self.assertEqual(True, True)
conn = utils.conn_tool.getConnection("testcm", 1)
if verbose: print("test-conn " + str(conn))
conns = utils.conn_tool.getConnections("testcrmdb")
if verbose: print("test-conn " + str(conns))
conns = utils.conn_tool.getConnections("testprd")
if verbose: print("test-conn " + str(conns))
if __name__ == '__main__':
unittest.main()

2
test/test_file.py → test/test_06file.py

@ -22,7 +22,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file_.*.py", None) r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file_t.*.py", None)
self.assertEqual(len(r), 1) self.assertEqual(len(r), 1)
cnttest += 3 cnttest += 3
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file__.*.py", None) r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file__.*.py", None)

12
test/test_catalog.py → test/test_07catalog.py

@ -13,14 +13,14 @@ HOME_PATH = test.constants.HOME_PATH
OS_SYSTEM = test.constants.OS_SYSTEM OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests # here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_key", "test_rejoinPath", "test_rejoinPath", "test_composePath", "test_composePattern", TEST_FUNCTIONS = ["test_01class", "test_02key"]
"test_extractPath", "test_extractPattern"] #TEST_FUNCTIONS = [ "test_02key"]
#TEST_FUNCTIONS = [ "test_extractPath"] verbose = True
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"
def test_class(self): def test_01class(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
@ -32,7 +32,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_key(self): def test_02key(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
@ -43,7 +43,7 @@ class MyTestCase(unittest.TestCase):
def test_zzz(self): def test_zzz(self):
print(MyTestCase.mymsg) if verbose: print(MyTestCase.mymsg)
if __name__ == '__main__': if __name__ == '__main__':

0
test/test_component.py → test/test_11component.py

16
test/test_toolhandling.py → test/test_12toolhandling.py

@ -1,5 +1,5 @@
import unittest import unittest
import inspect
import basic.program import basic.program
import basic.toolHandling import basic.toolHandling
import test.constants import test.constants
@ -8,12 +8,24 @@ import basic.constants as B
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
conf = {} conf = {}
# the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function
TEST_FUNCTIONS = ["test_01toolhandling"]
#TEST_FUNCTIONS = ["test_01toolhandling"]
# with this variable you can switch prints on and off
verbose = False
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def runTest(self): def runTest(self):
self.test_toolhandling() self.test_toolhandling()
def test_toolhandling(self): def test_01toolhandling(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = basic.program.Job("unit") job = basic.program.Job("unit")
args = {B.PAR_APP: "TEST", B.PAR_ENV: "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool", args = {B.PAR_APP: "TEST", B.PAR_ENV: "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"modus": "unit"} "modus": "unit"}

21
test/test_tdata.py → test/test_21tdata.py

@ -16,16 +16,19 @@ HOME_PATH = test.constants.HOME_PATH
DATA_PATH = test.constants.DATA_PATH DATA_PATH = test.constants.DATA_PATH
OS_SYSTEM = test.constants.OS_SYSTEM OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests # the list of TEST_FUNCTIONS defines which function will be really tested.
TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key", # if you minimize the list you can check the specific test-function
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv"] TEST_FUNCTIONS = ["test_01tdata", "test_02getCsvSpec_data", "test_03getCsvSpec_tree", "test_04getCsvSpec_key",
"test_05getCsvSpec_conf", "test_06parseCsv"]
# TEST_FUNCTIONS = ["test_getCsvSpec_data"] # TEST_FUNCTIONS = ["test_getCsvSpec_data"]
# with this variable you can switch prints on and off
verbose = False
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"
def test_tdata(self): def test_01tdata(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
@ -44,7 +47,7 @@ class MyTestCase(unittest.TestCase):
#self.assertEqual(("steps" in tdata), True) #self.assertEqual(("steps" in tdata), True)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_data(self): def test_02getCsvSpec_data(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
@ -172,7 +175,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_tree(self): def test_03getCsvSpec_tree(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
@ -187,7 +190,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_key(self): def test_04getCsvSpec_key(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
@ -251,7 +254,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_conf(self): def test_05getCsvSpec_conf(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
@ -282,7 +285,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parseCsv(self): def test_06parseCsv(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0

106
test/test_compare.py → test/test_22compare.py

@ -1,6 +1,6 @@
import json import json
import unittest import unittest
import inspect
import basic import basic
from basic.program import Job from basic.program import Job
import basic.constants as B import basic.constants as B
@ -8,6 +8,15 @@ import utils.data_const as D
import utils.match_tool import utils.match_tool
import utils.match_const as M import utils.match_const as M
import basic.component import basic.component
import test.testtools
# the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function
TEST_FUNCTIONS = ["test_01matchstart", "test_02hitmanage", "test_03similarity", "test_04bestfit",
"test_11compareRow", "test_12compareRows", "test_21match"]
# TEST_FUNCTIONS = ["test_getCsvSpec_data"]
# with this variable you can switch prints on and off
verbose = False
tdata = { tdata = {
M.MATCH_SIDE_POSTEXPECT: { M.MATCH_SIDE_POSTEXPECT: {
@ -90,8 +99,13 @@ class MyTestCase(unittest.TestCase):
#self.test_compareRows() #self.test_compareRows()
#self.test_match() #self.test_match()
def test_matchstart(self): def test_01matchstart(self):
job = Job("unit") global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
comp = basic.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
@ -101,7 +115,12 @@ class MyTestCase(unittest.TestCase):
matching.setData(tdata, M.MATCH_SUCCESS) matching.setData(tdata, M.MATCH_SUCCESS)
print(matching.htmltext) print(matching.htmltext)
def test_hitmanage(self): def test_02hitmanage(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
comp = basic.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
@ -117,15 +136,25 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(matching.isHitB("b0005"), True, "doesnt exist") self.assertEqual(matching.isHitB("b0005"), True, "doesnt exist")
self.assertEqual(("b0005" in matching.linksB), True, "doesnt exist") self.assertEqual(("b0005" in matching.linksB), True, "doesnt exist")
def test_similarity(self): def test_03similarity(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
matching = self.getMatching() matching = self.getMatching()
utils.match_tool.setMatchkeys(matching, ":database:scheme:table:_data") utils.match_tool.setMatchkeys(matching, ":database:scheme:table:_data")
utils.match_tool.getSimilarity(matching, utils.match_tool.getSimilarity(matching,
tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0], tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0],
tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0], 1) tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0], 1)
def test_bestfit(self): def test_04bestfit(self):
job = Job("unit") global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
comp = basic.component.Component() comp = basic.component.Component()
comp.name = "component" comp.name = "component"
@ -144,8 +173,13 @@ class MyTestCase(unittest.TestCase):
print(json.dumps(matching.linksB)) print(json.dumps(matching.linksB))
print(json.dumps(matching.nomatch)) print(json.dumps(matching.nomatch))
def test_compareRow(self): def test_11compareRow(self):
job = Job("unit") global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
comp = basic.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
@ -165,8 +199,13 @@ class MyTestCase(unittest.TestCase):
tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][i]) tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][i])
print(text) print(text)
def test_compareRows(self): def test_12compareRows(self):
job = Job("unit") global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
comp = basic.component.Component() comp = basic.component.Component()
comp.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"} comp.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"}
comp.name = "component" comp.name = "component"
@ -182,28 +221,33 @@ class MyTestCase(unittest.TestCase):
text = utils.match_tool.compareRows(matching, ":database:scheme:table:_data") text = utils.match_tool.compareRows(matching, ":database:scheme:table:_data")
print(text) print(text)
def test_match(self): def test_21match(self):
job = Job("unit") global mymsg
setattr(job.par, B.PAR_TESTCASE, "TC0001") actfunction = str(inspect.currentframe().f_code.co_name)
setattr(job.par, "tctime", "2022-03-25_19-25-31") cnttest = 0
comp = basic.component.Component() if actfunction not in TEST_FUNCTIONS:
comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"} return
comp.name = "component" job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager() setattr(job.par, B.PAR_TESTCASE, "TC0001")
cm.comps["component"] = comp setattr(job.par, "tctime", "2022-03-25_19-25-32")
# tdata["postReq"] = tdata["preAct"] comp = basic.component.Component()
comp.conf = conf comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"}
matching = utils.match_tool.Matching(comp) comp.name = "component"
matching.htmltext = "" cm = basic.componentHandling.ComponentManager()
matching.setData(tdata, M.MATCH_POSTCOND) cm.comps["component"] = comp
text = utils.match_tool.matchTree(matching) # tdata["postReq"] = tdata["preAct"]
print("\n-------------\n") comp.conf = conf
print(text) matching = utils.match_tool.Matching(comp)
print("\n-------------\n") matching.htmltext = ""
print(matching.difftext) matching.setData(tdata, M.MATCH_POSTCOND)
text = utils.match_tool.matchTree(matching)
print("\n-------------\n")
print(text)
print("\n-------------\n")
print(matching.difftext)
def getMatching(self): def getMatching(self):
job = Job("unit") job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, B.PAR_TESTCASE, "TC0001")
setattr(job.par, "tctime", "2022-03-25_19-25-31") setattr(job.par, "tctime", "2022-03-25_19-25-31")
comp = basic.component.Component() comp = basic.component.Component()

0
test/test_report.py → test/test_22report.py

7
test/test_db.py → test/test_31db.py

@ -14,7 +14,8 @@ HOME_PATH = test.constants.HOME_PATH
conf = {} conf = {}
# here you can select single testfunction for developping the tests # here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_parseSql", "test_toolhandling", "test_formatDbRows"] # "test_toolhandling", "test_parseSql" -> test of components
TEST_FUNCTIONS = ["test_formatDbRows"]
#TEST_FUNCTIONS = ["test_formatDbRows"] #TEST_FUNCTIONS = ["test_formatDbRows"]
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
@ -28,7 +29,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool", args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"modus": "unit"} "modus": "unit"}
job.par.setParameterArgs(args) job.par.setParameterArgs(args)
# "SELECT * FROM lofts" # "SELECT * FROM lofts"
@ -59,7 +60,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = basic.program.Job("unit") job = basic.program.Job("unit")
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool", args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"modus": "unit"} "modus": "unit"}
job.par.setParameterArgs(args) job.par.setParameterArgs(args)
#t = basic.toolHandling.ToolManager() #t = basic.toolHandling.ToolManager()

78
test/test_job.py → test/test_71job.py

@ -1,19 +1,24 @@
import unittest import unittest
import os import os
import inspect import inspect
import shutil
import utils.path_tool
from basic.program import Job from basic.program import Job
from basic.componentHandling import ComponentManager from basic.componentHandling import ComponentManager
import basic.step
import init_testcase import init_testcase
import test_executer import test_executer
import test.constants import test.constants
import basic.constants as B import basic.constants as B
import test.constants as T import test.constants as T
import basic.componentHandling
import utils.file_tool
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key", TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key",
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv"] "test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv", "test_smokeTestcase"]
TEST_FUNCTIONS = ["test_run"] TEST_FUNCTIONS = ["test_smokeTestcase"]
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
@ -76,5 +81,74 @@ class MyTestCase(unittest.TestCase):
#test_executer.start(job) #test_executer.start(job)
job.stopJob(1) 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 = ["copy_precondition", "execute_testcase"]
testcase = "TC0001"
timexec = "2022-07-18_21-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(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("init")
print("cm " + str(cm))
cm.initComponents()
comps = cm.getComponents(program)
for c in comps:
comp = cm.getComponent(c)
tdatapath = utils.path_tool.composePattern("{"+tdsource+"}", comp)
envapppath = utils.path_tool.composePattern("{envappdir}", comp)
if os.path.exists(tdatapath):
files = utils.file_tool.getFiles(job.m, 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(os.path.join(envapppath, f), job.m)
shutil.copy(os.path.join(tdatapath, f), os.path.join(envapppath, f))
print(tdatapath)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

23
test/test_conn.py

@ -1,23 +0,0 @@
import unittest
import basic.program
import utils.conn_tool
class MyTestCase(unittest.TestCase):
def runTest(self):
self.test_conn()
def test_conn(self):
print("# # # # tetsComponents # # # # #")
job = basic.program.Job("unit")
args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug", "tool" : "job_tool"}
job.par.setParameterArgs(args)
self.assertEqual(True, True)
conn = utils.conn_tool.getConnection("testb", 1)
print("test-conn " + str(conn))
conns = utils.conn_tool.getConnections("testb")
print("test-conn " + str(conns))
conns = utils.conn_tool.getConnections("testa")
print("test-conn " + str(conns))
if __name__ == '__main__':
unittest.main()

2
test/test_xml.py

@ -6,7 +6,7 @@ import utils.xml1_tool
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def xtest_xmlTool(self): def xtest_xmlTool(self):
#job = basic.program.Job("unit") #job = basic.program.Job("unit")
args = {"application": "TEST", "application": "ENV01", "modus": "unit", "loglevel": "debug", args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug",
"tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit", "tool": "job_tool", "tdtyp": "csv", "tdsrc": "implement", "tdname": "firstunit",
"modus": "unit"} "modus": "unit"}
beispiel_json = {'root': {'@attr': 'xyz', '$': 'inhalt', "b": "bold"}} beispiel_json = {'root': {'@attr': 'xyz', '$': 'inhalt', "b": "bold"}}

2
test/testtools.py

@ -47,7 +47,7 @@ conf = {
def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""): def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
job = basic.program.Job.popInstance() job = basic.program.Job.popInstance()
if not job is None: if not job is None:
job.stopJob() job.stopJob(1)
if len(pgran) < 1: if len(pgran) < 1:
gran = DEFAULT_GRAN gran = DEFAULT_GRAN
else: else:

49
unit_run.py

@ -1,7 +1,9 @@
# #
#
# ---------------------------------------------------------- # ----------------------------------------------------------
""" """
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. 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. The test-specification is written in a yaml-config in the data-directory.
workflow: workflow:
1. generate test-cases with all inputs into a csv-file of the spec-yaml 1. generate test-cases with all inputs into a csv-file of the spec-yaml
@ -10,15 +12,19 @@ workflow:
OR instead 2 and 3 on test-first-strategy: OR instead 2 and 3 on test-first-strategy:
3. create manually the target-result with your inputs and the target system-outputs 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 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 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. # Press the green button in the gutter to run the script.
import importlib import importlib
import unittest import unittest
import test.constants import test.constants
import os, glob import os, glob
import io
import sys
import test.constants as T
HOME_PATH = test.constants.HOME_PATH
VERIFY = False VERIFY = False
class MyTestLoader(unittest.TestLoader): class MyTestLoader(unittest.TestLoader):
@ -26,29 +32,30 @@ class MyTestLoader(unittest.TestLoader):
pass pass
def create_test_suite(): def create_test_suite():
testFileStrings = glob.glob(os.path.join(HOME_PATH, "test", 'test_*.py'))
print(testFileStrings)
suite = unittest.TestSuite() suite = unittest.TestSuite()
for t in testFileStrings: for testdir in [T.PROG_PATH, T.COMP_PATH]:
v = "test."+t[len(HOME_PATH)+6:-3] print("testdir "+testdir)
#v = v.replace("\/", '.') testFileStrings = sorted(glob.glob(os.path.join(testdir, "test", 'test_*.py')))
#v = v.replace("\\", '.') print("testdir "+str(testFileStrings))
cmodul = importlib.import_module(v) for t in testFileStrings:
class_ = getattr(cmodul, "MyTestCase") print("t "+t)
suite.addTest(class_()) if not t[len(testdir)+11:len(testdir)+13].isnumeric():
#module_strings = [str for str in test_file_strings] continue
#mod = __import__(os.path.join(HOME_PATH, "test", 'test_css.py'), globals(), locals(), ['suite']) if testdir == T.COMP_PATH:
#suitefn = getattr(mod, 'MyTestCase') v = "components.test." + t[len(testdir) + 6:-3]
#suite.addTest(suitefn()) else:
# suites = ["test.test_css.MyTestCase()"] v = "test."+t[len(testdir)+6:-3]
# testSuite = unittest.TestSuite(suites) cmodul = importlib.import_module(v)
class_ = getattr(cmodul, "MyTestCase")
c = class_()
for f in cmodul.TEST_FUNCTIONS:
setattr(c, "verbose", False)
suite.addTest(class_(f))
return suite return suite
if __name__ == '__main__': if __name__ == '__main__':
# loader = MyTestLoader()
print ("start") print ("start")
loader = unittest.TestLoader() loader = unittest.TestLoader()
suite = create_test_suite() suite = create_test_suite()
#loader.discover(os.path.join(HOME_PATH, "test"), 'test_.*py') runner = unittest.TextTestRunner(sys.stdout, True, 3, True, True)
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite) runner.run(suite)

Loading…
Cancel
Save