Browse Source

tests after refactor(move basic.comp)

master
Ulrich Carmesin 2 years ago
parent
commit
4185850774
  1. 9
      basic/component.py
  2. 10
      basic/program.py
  3. 1
      test/constants.py
  4. 17
      test/test_file.py
  5. 3
      test/test_path.py
  6. 112
      test/test_report.py
  7. 9
      test/test_toolhandling.py
  8. 34
      test/testtools.py
  9. 26
      utils/date_tool.py

9
basic/component.py

@ -8,15 +8,10 @@
# ---------------------------------------------------------------------
from datetime import datetime
import components.sysmonitor
import components.testexec
import components.report
import components.maintain
import components.catalog
import basic.testexec
import basic.message
import basic.program
import inspect
import threading
class CompData:
@ -29,7 +24,7 @@ class CompData:
#class Component(components.sysmonitor.SystemMonitor, components.testexec.Testexecuter, components.report.Report,
# components.maintain.Maintainer, components.catalog, threading.Thread):
class Component(components.testexec.Testexecuter):
class Component(basic.testexec.Testexecuter):
"""
A component represents an application of the system-under-test or a data-artifact which is created from the system-under-test.
As the representation it has to knowlegde of the url, which other components depends on this component.

10
basic/program.py

@ -134,9 +134,16 @@ class Job:
@staticmethod
def popInstance(pjob=None):
""" pop and stop a subjob """
if pjob is not None and Job.__instance is not None and Job.__instance != pjob:
raise Exception(B.EXP_CANT_POP)
# for guarantee that both the stack and the original variable is empty if one is empty
if len(Job.instances) < 1:
Job.__instance = None
return None
if Job.__instance is None:
while len(Job.instances) > 0:
Job.instances.pop()
return None
if len(Job.instances) == 1:
job = Job.__instance
@ -160,6 +167,7 @@ class Job:
@staticmethod
def pushInstance(pjob):
""" push a new created subjob """
if len(Job.instances) > 0:
job = Job.instances.pop()
if pjob is not None and job is not None and job != pjob:
@ -404,11 +412,11 @@ class Parameter:
if dirpath is not None:
utils.path_tool.extractPath(dirpath[0], dirpath[1])
def setParameterLoaded(self):
job = Job.getInstance()
print("setParLoaded " )
readedPar = job.loadParameter()
if readedPar is not None:
for k in readedPar["par"].keys():
if not hasattr(self, k):

1
test/constants.py

@ -1,2 +1,3 @@
HOME_PATH = "/home/ulrich/6_Projekte/Programme/datest"
DATA_PATH = "/home/ulrich/6_Projekte/Programme/data"
OS_SYSTEM = "linux"

17
test/test_file.py

@ -8,6 +8,7 @@ import test.constants
import test.testtools
HOME_PATH = test.constants.HOME_PATH
DATA_PATH = test.constants.DATA_PATH
TEST_FUNCTIONS = ["test_getFiles", "test_pathTool", "test_encoding"]
@ -21,10 +22,10 @@ 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)
self.assertEqual((len(r) == 1), True)
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", "^file_.*.py", None)
self.assertEqual(len(r), 1)
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)
self.assertEqual((len(r) == 0), True)
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", ".*_tool.py", None)
self.assertEqual((len(r) > 2), True)
@ -54,15 +55,19 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob()
print("------- test_encoding")
encodings = ['utf-8', 'windows-1250', 'iso-8859-1']
res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_iso8859.txt"))
res = utils.file_tool.getFileEncoding(job.m, os.path.join(DATA_PATH, "tdata", "encoded_iso8859.txt"))
self.assertEqual(res, "iso-8859-1")
res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_win1250.txt"))
res = utils.file_tool.getFileEncoding(job.m, os.path.join(DATA_PATH, "tdata", "encoded_win1250.txt"))
self.assertEqual(res, "iso-8859-1")
res = utils.file_tool.getFileEncoding(job.m, os.path.join(HOME_PATH,"test","conf","tdata","encoded_utf8.txt"))
res = utils.file_tool.getFileEncoding(job.m, os.path.join(DATA_PATH, "tdata", "encoded_utf8.txt"))
self.assertEqual(res, "utf-8")
cnttest += 3
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__':
unittest.main()

3
test/test_path.py

@ -9,6 +9,7 @@ import test.testtools
import utils.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
@ -138,7 +139,7 @@ class MyTestCase(unittest.TestCase):
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"))
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")

112
test/test_report.py

@ -1,12 +1,9 @@
import unittest
import os
import basic.program
import inspect
import test.testtools
import basic.program
import components.component
import basic.component
from basic.componentHandling import ComponentManager
import init_testcase
import test_executer
import test.constants
import utils.report_tool
import utils.match_tool
@ -14,8 +11,13 @@ import utils.match_const as M
import basic.constants as B
HOME_PATH = test.constants.HOME_PATH
DATA_PATH = test.constants.DATA_PATH
TEST_FUNCTIONS = ["test_20cssClass", "test_21title", "test_22overview", "test_23filename",
"test_24headlines", "test_30reportS"]
TEST_FUNCTIONS = ["test_21title"]
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def getReport(self):
job = basic.program.Job.getInstance()
@ -38,20 +40,28 @@ class MyTestCase(unittest.TestCase):
i = 0
return report
def test_cssClass(self):
job = basic.program.Job("unit")
args = { "application": "TEST", "environment": "ENV01", "modus": "unit", "tstime": "2022-03-19_12-09-09",
"tsdir": '/home/ulrich/6_Projekte/Programme/datest/test/conf/lauf/testlauf/TST001_2022-03-19_12-09-09',
"step": 2 }
# "usecase": "TST001", "tstime": "2022-03-17_17-28"}
job.par.setParameterArgs(args)
job.setProgram("test_executer")
def test_20cssClass(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
#job = basic.program.Job("unit")
#args = { "application": "TEST", "environment": "ENV01", "modus": "unit", "tstime": "2022-03-19_12-09-09",
# "tsdir": '/home/ulrich/6_Projekte/Programme/datest/test/conf/lauf/testlauf/TST001_2022-03-19_12-09-09',
# "step": 2 }
## "usecase": "TST001", "tstime": "2022-03-17_17-28"}
#job.par.setParameterArgs(args)
#job.setProgram("test_executer")
job = test.testtools.getJob()
report = self.getReport()
i = 0
for m in M.MATCH_TYPES:
cssClass = report.getCssClass("TC0001", "comp01", "arte01", m)
print(m + " test0111 " + cssClass)
self.assertEqual(cssClass, "result"+str(i))
cnttest += 1
i += 1
if i > 4:
i = 0
@ -67,11 +77,18 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(cssClass, "result1")
cssClass = report.getCssClass("TC0002")
self.assertEqual(cssClass, "result4")
cnttest += 4
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_title(self):
job = basic.program.Job.getInstance()
def test_21title(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
print(" ---------- test_title")
setattr(job.par, "testsuite", "TST001")
setattr(job.par, B.PAR_TESTSUITE, "TST001")
report = self.getReport()
html = report.getTitle("TC0001", "comp01", "arte01", M.MATCH_POSTCOND)
print(html)
@ -79,44 +96,64 @@ class MyTestCase(unittest.TestCase):
self.assertEqual((utils.report_tool.REP_TITLE in html), True)
self.assertEqual((utils.report_tool.REP_TC in html), True)
self.assertEqual(("TC0001" in html), True)
cnttest += 3
html = report.getTitle()
self.assertEqual((utils.report_tool.REP_TITLE in html), True)
self.assertEqual((utils.report_tool.REP_TS in html), True)
self.assertEqual(("TST001" in html), True)
cnttest += 3
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_overview(self):
job = basic.program.Job.getInstance()
def test_22overview(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
print(" ---------- test_overview")
report = self.getReport()
html = report.getOverview("TC0001")
print(html)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_filename(self):
job = basic.program.Job.getInstance()
def test_23filename(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
#job = basic.program.Job.getInstance()
job = test.testtools.getJob()
setattr(job.par, "testcase", "TC0001")
setattr(job.par, "tctime", "2022-03-23_21-23-32")
print(" ---------- test_filename")
cm = basic.componentHandling.ComponentManager()
for c in ["comp02"]:
comp = components.component.Component()
comp = basic.component.Component()
comp.conf = {}
comp.name = c
basic.componentHandling.comps[c] = comp
cm.comps[c] = comp
report = self.getReport()
html = report.getFilepath("TC0001", "comp02", "arte01", M.MATCH_POSTCOND)
print(html)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_headlines(self):
job = basic.program.Job.getInstance()
def test_24headlines(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, "testcase", "TC0001")
setattr(job.par, "tctime", "2022-03-23_21-23-32")
cm = basic.componentHandling.ComponentManager()
for c in ["comp02"]:
comp = components.component.Component()
comp = basic.component.Component()
comp.conf = {}
comp.name = c
basic.componentHandling.comps[c] = comp
cm.comps[c] = comp
print(" ---------- test_headlines")
report = self.getReport()
html = report.getTestcaseHead("TC0001")
@ -125,9 +162,15 @@ class MyTestCase(unittest.TestCase):
print(html)
html = report.getArtefactBlock("TC0001", "comp02", "arte01")
print(html)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def xtest_reportS(self):
job = basic.program.Job.getInstance()
def test_30reportS(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, "testcase", "TC0001")
setattr(job.par, "testcases", ["TC0001", "TC0002"])
setattr(job.par, "tctime", "2022-03-23_21-23-32")
@ -136,11 +179,11 @@ class MyTestCase(unittest.TestCase):
cm = basic.componentHandling.ComponentManager()
for compname in ["comp01", "comp02"]:
conf = {}
comp = components.component.Component()
comp = basic.component.Component()
comp.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"}
comp.name = compname
comp.conf = conf
basic.componentHandling.comps[compname] = comp
cm.comps[compname] = comp
html_1 = report.reportTestcase("TC0001")
print(html_1)
print("<<---------------------------------- TC0001")
@ -154,8 +197,13 @@ class MyTestCase(unittest.TestCase):
setattr(job.par, B.PAR_TESTCASES, ["TC0001", "TC0002"])
#html = report.reportTestsuite()
#print(html)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
print("<<---------------------------------- TST001")
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__':
unittest.main()

9
test/test_toolhandling.py

@ -1,10 +1,9 @@
import unittest, os
import unittest
import basic.program
import utils.path_tool
import basic.toolHandling
import test.constants
import components.component
import basic.component
import basic.constants as B
HOME_PATH = test.constants.HOME_PATH
@ -20,14 +19,14 @@ class MyTestCase(unittest.TestCase):
"modus": "unit"}
job.par.setParameterArgs(args)
#t = basic.toolHandling.ToolManager()
comp = components.component.Component()
comp = basic.component.Component()
comp.name = "testb"
comp.conf = {}
comp.conf[B.SUBJECT_CONN] = {}
comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_CLI] = {}
#self.assertRaises(LookupError, basic.toolHandling.getDbTool, comp)
comp = components.component.Component()
comp = basic.component.Component()
comp.name = "testb"
comp.conf = {}
comp.conf[B.SUBJECT_ARTS] = {}

34
test/testtools.py

@ -1,6 +1,7 @@
import basic.program
import basic.constants as B
import components.component
import basic.component
import utils.data_const as D
DEFAULT_GRAN = "tc"
DEFAULT_APP = "TEST"
@ -15,6 +16,32 @@ tstamp = ""
mode = ""
path = ""
# xample-DDL
conf = {
B.SUBJECT_ARTS: {
B.TOPIC_NODE_DB: {
B.ATTR_TYPE: "csv",
"person": {
"tabname": "tbl_person"
}
},
B.TOPIC_NODE_CLI: {
B.ATTR_TYPE: "cmd"
}
},
B.DATA_NODE_DDL: {
"person": {
"id": { D.DDL_FNAME: "id", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "ignore", D.DDL_KEY: "T:3" },
"name": { D.DDL_FNAME: "name", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:1" },
"birth": { D.DDL_FNAME: "id", D.DDL_TYPE: "date", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" },
"year": { D.DDL_FNAME: "year", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:2" },
"position": { D.DDL_FNAME: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" },
"hobby": { D.DDL_FNAME: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" },
"_header": ["id", "name", "birth", "year", "position", "hobby"]
}
}
}
def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
job = basic.program.Job.popInstance()
if not job is None:
@ -53,7 +80,8 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
def getComp():
comp = components.component.Component()
comp = basic.component.Component()
comp.conf = {}
comp.name = "testcomp"
comp.name = "person"
pass

26
utils/date_tool.py

@ -11,6 +11,7 @@ import utils.data_const as D
F_DIR = "%Y-%m-%d_%H-%M-%S"
F_DE = "%d.%m.%Y"
F_N8 = "%Y%m%d"
def getActdate(format):
return getFormatdate(datetime.datetime.now(), format)
@ -21,7 +22,22 @@ def getFormatdate(date, format):
return date.strftime(format)
def getFormatDatetupel(dtupel, format):
""" it return the date as string in the format """
if format == F_N8:
return f'{dtupel[0]:04}'+f'{dtupel[1]:02}'+f'{dtupel[2]:02}'
return getFormatdate(datetime.datetime(dtupel[0], dtupel[1], dtupel[2],
dtupel[3], dtupel[4], dtupel[5]) ,format)
def parseFormula(instring):
"""
the function parses the string as a formula. In the formula the input-date - actdate or explicite date -
will be added resp. subtracted with years, months or dates which are specified in the formula.
The structure of the formula: DATE +/- mY +/-nM +/-qD
:param instring:
:return:
"""
instring = instring.upper()
if instring[2:6] == "DATE":
refdate = datetime.datetime.today()
@ -70,6 +86,11 @@ def parseFormula(instring):
def parseDate(instring):
"""
the function parses the string as a date or timestamp which is formed in one of the typical formates
:param the string to be parse:
:return timestamp as tupel (y, m, d, H, M ,S):
"""
year = 0
mon = 0
day = 0
@ -97,6 +118,11 @@ def parseDate(instring):
mon = int(res.group(2))
day = int(res.group(1))
return (year, mon, day, hour, min, sec)
if re.match(r"\d{8}", instring):
year = instring[0:4]
mon = instring[4:6]
day = instring[6:8]
return (year, mon, day, hour, min, sec)
if re.match(r"\d{2}[-:]\d{2}[-:/]\d{2}", instring):
res = re.match(r"(\d{2})[-:/](\d{2})[-:/](\d{2})", instring)
hour = int(res.group(1))

Loading…
Cancel
Save