import json import inspect import unittest import datetime import tools.date_tool TEST_FUNCTIONS = ["test_01dateformat", "test_10parseFormula", "test_11parseDate"] #TEST_FUNCTIONS = ["test_11parseDate"] verbose = True # class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase): 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_01dateformat(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_10parseFormula(self, result=None): actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return res = tools.date_tool.parseFormula("{(21.12.2012 +1Y)}") if verbose: print(str(res)) self.assertEqual(res[0], 2013) self.assertEqual(res[3], 0) res = tools.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 = tools.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 = tools.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 = tools.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_11parseDate(self, result=None): actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return res = tools.date_tool.parseDate("21.12.2012") if verbose: print(str(res)) self.assertEqual(res[0], 2012) self.assertEqual(res[3], 0) res = tools.date_tool.parseDate("{(21.12.2012 +1Y)}") if verbose: print(str(res)) self.assertEqual(res[0], 2013) self.assertEqual(res[3], 0) res = tools.date_tool.parseDate("Wed May 18 23:32:55 2022 +0200") if verbose: print(str(res)) self.assertEqual(res[0], 2022) self.assertEqual(res[1], 5) res = tools.date_tool.parseDate("Mit Dez 18 23:32:55 2021 +0200") if verbose: print(str(res)) self.assertEqual(res[0], 2021) self.assertEqual(res[1], 12) res = tools.date_tool.parseDate("Sun Sep 4 15:12:21 2022 +0200") if verbose: print(str(res)) self.assertEqual(res[0], 2022) self.assertEqual(res[1], 9) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) if __name__ == '__main__': unittest.main()