import json import inspect import unittest import datetime import utils.date_tool TEST_FUNCTIONS = ["test_dateformat", "test_parseFormula", "test_parseDate"] #TEST_FUNCTIONS = ["test_parseFormula"] verbose = True # class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase): 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, 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() if verbose: print(stime) tdate = (2022, 2, 10) sdate = datetime.datetime(tdate[0], tdate[1],tdate[2], 3, 32, 23) #sdate = datetime.datetime(stime) if verbose: print(sdate) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) 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)}") 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)}") 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)}") 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)}") if verbose: print(str(res)) self.assertEqual(res[0], 2013) self.assertEqual(res[5], 43) res = utils.date_tool.parseFormula("{(21.12.2012 -60M)}") 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, 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") if verbose: print(str(res)) self.assertEqual(res[0], 2012) self.assertEqual(res[3], 0) res = utils.date_tool.parseDate("{(21.12.2012 +1Y)}") if verbose: print(str(res)) self.assertEqual(res[0], 2013) self.assertEqual(res[3], 0) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) if __name__ == '__main__': unittest.main()