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. 74
      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. 43
      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"
COMP_PATH = "/home/ulrich/6_Projekte/Programme/data/components"
"""
constants
"""
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"

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

@ -3,72 +3,90 @@ import inspect
import unittest
import datetime
import utils.date_tool
import test.abstractTestcase
#TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"]
TEST_FUNCTIONS = ["test_parseFormula"]
TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"]
#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 = "--------------------------------------------------------------"
"""
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)
cnttest = 0
if verbose: print("test_dateformat -------")
if actfunction not in TEST_FUNCTIONS:
return
stime = datetime.datetime.now()
print(stime)
if verbose: print(stime)
tdate = (2022, 2, 10)
sdate = datetime.datetime(tdate[0], tdate[1],tdate[2], 3, 32, 23)
sdate = datetime.datetime(stime)
print(sdate)
#sdate = datetime.datetime(stime)
if verbose: print(sdate)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parseFormula(self):
def test_parseFormula(self, result=None):
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
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[3], 0)
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[1], 11)
self.assertEqual(res[3], 0)
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[1], 1)
self.assertEqual(res[2], 10)
self.assertEqual(res[3], 0)
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[5], 43)
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[1], 12)
self.assertEqual(res[3], 0)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parseDate(self):
def test_parseDate(self, result=None):
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
res = utils.date_tool.parseDate("21.12.2012")
print(str(res))
if verbose: print(str(res))
self.assertEqual(res[0], 2012)
self.assertEqual(res[3], 0)
res = utils.date_tool.parseDate("{(21.12.2012 +1Y)}")
print(str(res))
self.assertEqual(res[0], 2012)
if verbose: print(str(res))
self.assertEqual(res[0], 2013)
self.assertEqual(res[3], 0)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

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

@ -1,20 +1,30 @@
"""
unit-test
"""
import unittest
import utils.css_tool
import basic.program
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):
def runTest(self):
self.test_css()
def test_css(self):
def test_01css(self):
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",
"modus": "unit"}
job.par.setParameterArgs(args)
print("eeeeeeeee")
print(json.dumps(job.conf.confs))
if verbose: print("eeeeeeeee")
if verbose: print(json.dumps(job.conf.confs))
# ------- inline ---------------
job.conf.setConfig("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(("class" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles")
print(text)
if verbose: print(text)
self.assertEqual(len(text), 262)
self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("resultFile")
print(text)
if verbose: print(text)
self.assertEqual(len(text), 283)
self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles,resultFile")
print(text)
if verbose: print(text)
self.assertEqual(len(text), 465)
self.assertEqual(("<style>" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles")
self.assertEqual(len(text), 0)
print(text)
print(str(len(text)))
if verbose: print(text)
if verbose: print(str(len(text)))
# ------- external ---------------
job.conf.setConfig("tools.csstyp", "external")
text = utils.css_tool.getInlineStyle("diffFiles", "diffA")
self.assertEqual(len(text), 13)
self.assertEqual(("class" in text), True)
text = utils.css_tool.getInternalStyle("diffFiles")
print(text)
if verbose: print(text)
self.assertEqual(len(text), 55)
self.assertEqual(("<link " in text and "stylesheet" in text), True)
text = utils.css_tool.getExternalStyle("diffFiles")
self.assertEqual(len(text), 216)
print(text)
print(str(len(text)))
if verbose: print(text)
if verbose: print(str(len(text)))
text = utils.css_tool.getExternalStyle("diffFiles,resultFile")
self.assertEqual(len(text), 449)
print(text)
print(str(len(text)))
if verbose: print(text)
if verbose: print(str(len(text)))
if __name__ == '__main__':
verbose = True
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_extractPath", "test_extractPattern"]
#TEST_FUNCTIONS = [ "test_extractPath"]
verbose = True
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
@ -44,9 +45,10 @@ class MyTestCase(unittest.TestCase):
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]:
for par in [B.ATTR_PATH_ARCHIV, B.ATTR_PATH_ENV]:
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
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -140,9 +142,7 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob()
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"))
print("r " + str(r))
#print(vars(job.par))
#self.assertEqual(job.par.release, "V0.1")
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
@ -150,7 +150,7 @@ class MyTestCase(unittest.TestCase):
def test_zzz(self):
print(MyTestCase.mymsg)
if verbose: print(MyTestCase.mymsg)
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
HOME_PATH = test.constants.HOME_PATH
PROG_PATH = test.constants.PROG_PATH
TEST_FUNCTIONS = ["test_getConfig", "test_mergeAttributes"]
VERIFY = False
@ -24,7 +25,7 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob()
x = "path"
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
x = "conn"
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:
return
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)
cnttest += 3
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
# 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"]
TEST_FUNCTIONS = ["test_01class", "test_02key"]
#TEST_FUNCTIONS = [ "test_02key"]
verbose = True
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_class(self):
def test_01class(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -32,7 +32,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_key(self):
def test_02key(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -43,7 +43,7 @@ class MyTestCase(unittest.TestCase):
def test_zzz(self):
print(MyTestCase.mymsg)
if verbose: print(MyTestCase.mymsg)
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 inspect
import basic.program
import basic.toolHandling
import test.constants
@ -8,12 +8,24 @@ import basic.constants as B
HOME_PATH = test.constants.HOME_PATH
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):
def runTest(self):
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")
args = {B.PAR_APP: "TEST", B.PAR_ENV: "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"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
OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key",
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv"]
# 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_01tdata", "test_02getCsvSpec_data", "test_03getCsvSpec_tree", "test_04getCsvSpec_key",
"test_05getCsvSpec_conf", "test_06parseCsv"]
# TEST_FUNCTIONS = ["test_getCsvSpec_data"]
# with this variable you can switch prints on and off
verbose = False
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_tdata(self):
def test_01tdata(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -44,7 +47,7 @@ class MyTestCase(unittest.TestCase):
#self.assertEqual(("steps" in tdata), True)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_data(self):
def test_02getCsvSpec_data(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -172,7 +175,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_tree(self):
def test_03getCsvSpec_tree(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -187,7 +190,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_key(self):
def test_04getCsvSpec_key(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -251,7 +254,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getCsvSpec_conf(self):
def test_05getCsvSpec_conf(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
@ -282,7 +285,7 @@ class MyTestCase(unittest.TestCase):
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parseCsv(self):
def test_06parseCsv(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0

74
test/test_compare.py → test/test_22compare.py

@ -1,6 +1,6 @@
import json
import unittest
import inspect
import basic
from basic.program import Job
import basic.constants as B
@ -8,6 +8,15 @@ import utils.data_const as D
import utils.match_tool
import utils.match_const as M
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 = {
M.MATCH_SIDE_POSTEXPECT: {
@ -90,8 +99,13 @@ class MyTestCase(unittest.TestCase):
#self.test_compareRows()
#self.test_match()
def test_matchstart(self):
job = Job("unit")
def test_01matchstart(self):
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")
comp = basic.component.Component()
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)
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.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component"
@ -117,15 +136,25 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(matching.isHitB("b0005"), 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()
utils.match_tool.setMatchkeys(matching, ":database:scheme:table:_data")
utils.match_tool.getSimilarity(matching,
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)
def test_bestfit(self):
job = Job("unit")
def test_04bestfit(self):
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")
comp = basic.component.Component()
comp.name = "component"
@ -144,8 +173,13 @@ class MyTestCase(unittest.TestCase):
print(json.dumps(matching.linksB))
print(json.dumps(matching.nomatch))
def test_compareRow(self):
job = Job("unit")
def test_11compareRow(self):
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")
comp = basic.component.Component()
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])
print(text)
def test_compareRows(self):
job = Job("unit")
def test_12compareRows(self):
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.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"}
comp.name = "component"
@ -182,10 +221,15 @@ class MyTestCase(unittest.TestCase):
text = utils.match_tool.compareRows(matching, ":database:scheme:table:_data")
print(text)
def test_match(self):
job = Job("unit")
def test_21match(self):
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, "tctime", "2022-03-25_19-25-31")
setattr(job.par, "tctime", "2022-03-25_19-25-32")
comp = basic.component.Component()
comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"}
comp.name = "component"
@ -203,7 +247,7 @@ class MyTestCase(unittest.TestCase):
print(matching.difftext)
def getMatching(self):
job = Job("unit")
job = test.testtools.getJob()
setattr(job.par, B.PAR_TESTCASE, "TC0001")
setattr(job.par, "tctime", "2022-03-25_19-25-31")
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 = {}
# 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"]
class MyTestCase(unittest.TestCase):
@ -28,7 +29,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
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"}
job.par.setParameterArgs(args)
# "SELECT * FROM lofts"
@ -59,7 +60,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
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"}
job.par.setParameterArgs(args)
#t = basic.toolHandling.ToolManager()

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

@ -1,19 +1,24 @@
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_FUNCTIONS = ["test_run"]
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv", "test_smokeTestcase"]
TEST_FUNCTIONS = ["test_smokeTestcase"]
class MyTestCase(unittest.TestCase):
@ -76,5 +81,74 @@ class MyTestCase(unittest.TestCase):
#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 = ["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__':
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):
def xtest_xmlTool(self):
#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",
"modus": "unit"}
beispiel_json = {'root': {'@attr': 'xyz', '$': 'inhalt', "b": "bold"}}

2
test/testtools.py

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

43
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.
workflow:
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:
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
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.
import importlib
import unittest
import test.constants
import os, glob
import io
import sys
import test.constants as T
HOME_PATH = test.constants.HOME_PATH
VERIFY = False
class MyTestLoader(unittest.TestLoader):
@ -26,29 +32,30 @@ class MyTestLoader(unittest.TestLoader):
pass
def create_test_suite():
testFileStrings = glob.glob(os.path.join(HOME_PATH, "test", 'test_*.py'))
print(testFileStrings)
suite = unittest.TestSuite()
for testdir in [T.PROG_PATH, T.COMP_PATH]:
print("testdir "+testdir)
testFileStrings = sorted(glob.glob(os.path.join(testdir, "test", 'test_*.py')))
print("testdir "+str(testFileStrings))
for t in testFileStrings:
v = "test."+t[len(HOME_PATH)+6:-3]
#v = v.replace("\/", '.')
#v = v.replace("\\", '.')
print("t "+t)
if not t[len(testdir)+11:len(testdir)+13].isnumeric():
continue
if testdir == T.COMP_PATH:
v = "components.test." + t[len(testdir) + 6:-3]
else:
v = "test."+t[len(testdir)+6:-3]
cmodul = importlib.import_module(v)
class_ = getattr(cmodul, "MyTestCase")
suite.addTest(class_())
#module_strings = [str for str in test_file_strings]
#mod = __import__(os.path.join(HOME_PATH, "test", 'test_css.py'), globals(), locals(), ['suite'])
#suitefn = getattr(mod, 'MyTestCase')
#suite.addTest(suitefn())
# suites = ["test.test_css.MyTestCase()"]
# testSuite = unittest.TestSuite(suites)
c = class_()
for f in cmodul.TEST_FUNCTIONS:
setattr(c, "verbose", False)
suite.addTest(class_(f))
return suite
if __name__ == '__main__':
# loader = MyTestLoader()
print ("start")
loader = unittest.TestLoader()
suite = create_test_suite()
#loader.discover(os.path.join(HOME_PATH, "test"), 'test_.*py')
runner = unittest.TextTestRunner(verbosity=2)
runner = unittest.TextTestRunner(sys.stdout, True, 3, True, True)
runner.run(suite)

Loading…
Cancel
Save