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. 95
      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 from datetime import datetime
import components.sysmonitor import basic.testexec
import components.testexec
import components.report
import components.maintain
import components.catalog
import basic.message import basic.message
import basic.program import basic.program
import inspect import inspect
import threading
class CompData: class CompData:
@ -29,7 +24,7 @@ class CompData:
#class Component(components.sysmonitor.SystemMonitor, components.testexec.Testexecuter, components.report.Report, #class Component(components.sysmonitor.SystemMonitor, components.testexec.Testexecuter, components.report.Report,
# components.maintain.Maintainer, components.catalog, threading.Thread): # 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. 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. 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 @staticmethod
def popInstance(pjob=None): def popInstance(pjob=None):
""" pop and stop a subjob """
if pjob is not None and Job.__instance is not None and Job.__instance != pjob: if pjob is not None and Job.__instance is not None and Job.__instance != pjob:
raise Exception(B.EXP_CANT_POP) 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: 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 return None
if len(Job.instances) == 1: if len(Job.instances) == 1:
job = Job.__instance job = Job.__instance
@ -160,6 +167,7 @@ class Job:
@staticmethod @staticmethod
def pushInstance(pjob): def pushInstance(pjob):
""" push a new created subjob """
if len(Job.instances) > 0: if len(Job.instances) > 0:
job = Job.instances.pop() job = Job.instances.pop()
if pjob is not None and job is not None and job != pjob: if pjob is not None and job is not None and job != pjob:
@ -404,11 +412,11 @@ class Parameter:
if dirpath is not None: if dirpath is not None:
utils.path_tool.extractPath(dirpath[0], dirpath[1]) utils.path_tool.extractPath(dirpath[0], dirpath[1])
def setParameterLoaded(self): def setParameterLoaded(self):
job = Job.getInstance() job = Job.getInstance()
print("setParLoaded " ) print("setParLoaded " )
readedPar = job.loadParameter() readedPar = job.loadParameter()
if readedPar is not None: if readedPar is not None:
for k in readedPar["par"].keys(): for k in readedPar["par"].keys():
if not hasattr(self, k): if not hasattr(self, k):

1
test/constants.py

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

95
test/test_file.py

@ -8,60 +8,65 @@ import test.constants
import test.testtools import test.testtools
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
DATA_PATH = test.constants.DATA_PATH
TEST_FUNCTIONS = ["test_getFiles", "test_pathTool", "test_encoding"] TEST_FUNCTIONS = ["test_getFiles", "test_pathTool", "test_encoding"]
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
mymsg = "" mymsg = ""
def test_getFiles(self): def test_getFiles(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
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_.*.py", None)
self.assertEqual((len(r) == 1), True) 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)
self.assertEqual((len(r) == 0), True) self.assertEqual((len(r) == 0), True)
r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", ".*_tool.py", None) r = t.getFiles(job.m, job.conf.getPath("program") + "/utils", ".*_tool.py", None)
self.assertEqual((len(r) > 2), True) self.assertEqual((len(r) > 2), True)
cnttest += 3 cnttest += 3
r = t.getFilesRec(job.m, job.conf.getPath("program"), ".*?file.*.py") r = t.getFilesRec(job.m, job.conf.getPath("program"), ".*?file.*.py")
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
def test_pathTool(self): def test_pathTool(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
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
#self.assertEqual(utils.path_tool.generatePath("program", "komp", "testA", "CONFIG.yml"), #self.assertEqual(utils.path_tool.generatePath("program", "komp", "testA", "CONFIG.yml"),
# os.path.join(HOME_PATH, "components","testA","COFIG.yml")) # os.path.join(HOME_PATH, "components","testA","COFIG.yml"))
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
def test_encoding(self): def test_encoding(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
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
print("------- test_encoding") print("------- test_encoding")
encodings = ['utf-8', 'windows-1250', 'iso-8859-1'] 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") 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") 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") self.assertEqual(res, "utf-8")
cnttest += 3 cnttest += 3
MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest) MyTestCase.mymsg += "\n----- " + actfunction + " : " + str(cnttest)
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__': if __name__ == '__main__':

3
test/test_path.py

@ -9,6 +9,7 @@ import test.testtools
import utils.path_const as P import utils.path_const as P
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_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 # here you can select single testfunction for developping the tests
@ -138,7 +139,7 @@ class MyTestCase(unittest.TestCase):
return return
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(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("r " + str(r))
#print(vars(job.par)) #print(vars(job.par))
#self.assertEqual(job.par.release, "V0.1") #self.assertEqual(job.par.release, "V0.1")

112
test/test_report.py

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

9
test/test_toolhandling.py

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

34
test/testtools.py

@ -1,6 +1,7 @@
import basic.program import basic.program
import basic.constants as B import basic.constants as B
import components.component import basic.component
import utils.data_const as D
DEFAULT_GRAN = "tc" DEFAULT_GRAN = "tc"
DEFAULT_APP = "TEST" DEFAULT_APP = "TEST"
@ -15,6 +16,32 @@ tstamp = ""
mode = "" mode = ""
path = "" 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=""): 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:
@ -53,7 +80,8 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
def getComp(): def getComp():
comp = components.component.Component() comp = basic.component.Component()
comp.conf = {} comp.conf = {}
comp.name = "testcomp" comp.name = "person"
pass 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_DIR = "%Y-%m-%d_%H-%M-%S"
F_DE = "%d.%m.%Y" F_DE = "%d.%m.%Y"
F_N8 = "%Y%m%d"
def getActdate(format): def getActdate(format):
return getFormatdate(datetime.datetime.now(), format) return getFormatdate(datetime.datetime.now(), format)
@ -21,7 +22,22 @@ def getFormatdate(date, format):
return date.strftime(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): 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() instring = instring.upper()
if instring[2:6] == "DATE": if instring[2:6] == "DATE":
refdate = datetime.datetime.today() refdate = datetime.datetime.today()
@ -70,6 +86,11 @@ def parseFormula(instring):
def parseDate(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 year = 0
mon = 0 mon = 0
day = 0 day = 0
@ -97,6 +118,11 @@ def parseDate(instring):
mon = int(res.group(2)) mon = int(res.group(2))
day = int(res.group(1)) day = int(res.group(1))
return (year, mon, day, hour, min, sec) 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): if re.match(r"\d{2}[-:]\d{2}[-:/]\d{2}", instring):
res = 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)) hour = int(res.group(1))

Loading…
Cancel
Save