def basetest_Formater_format(self, formaterinstance, teststr, _resultstr1): from comoonics.search.datetime.TimeExpression import TimeExpression te=TimeExpression(teststr) _resultstr2=formaterinstance.format(te) _error="Testing time dateformater.format(%s): %s == %s " %(teststr, _resultstr2, _resultstr1) print _error self.assertEquals(_resultstr1, _resultstr2, _error)
def test_toMonthNumber(self): result="11" from comoonics.search.datetime.TimeExpression import TimeExpression monthname="Nov" monthnum=TimeExpression.toMonthnumber(monthname, False) print "Month %s: %s" %(monthname, monthnum) self.assertEquals(monthnum, result, "Month %s is not %s as expected. %s" %(monthname, monthnum, result))
def test_toMonthname(self): result="Sep\w*" from comoonics.search.datetime.TimeExpression import TimeExpression monthnum=9 monthname=TimeExpression.toMonthname(monthnum, False) print "Mtimeonth %u: %s" %(monthnum, monthname) self.assertEquals(monthname, result, "Monthnum %u is not %s as expected. %s" %(monthnum, monthname, result))
def test_toMonthnameRegExp(self): from comoonics.search.datetime.TimeExpression import TimeExpression results={ "1-10": "(?P<month>Jan\w*|Feb\w*|Mar\w*|Apr\w*|Mai|Jun\w*|Jul\w*|Aug\w*|Sep\w*|Oct\w*)", "*": "(?P<month>Jan\w*|Feb\w*|Mar\w*|Apr\w*|Mai|Jun\w*|Jul\w*|Aug\w*|Sep\w*|Oct\w*|Nov\w*|Dec\w*)" } for input, result1 in results.items(): result2=TimeExpression.toMonthnameRegExp(input) error= "toMonthnameRegExp(%s) => %s == %s" %(input, result2, result1) print error
def test_toMonthnumberRegExp(self): from comoonics.search.datetime.TimeExpression import TimeExpression results={ "Jan-Oct": "(?P<month>[1-10])", "*": "(?P<month>[1-12])" } for input, result1 in results.items(): result2=TimeExpression.toMonthnumberRegExp(input) error= "toMonthnumberRegExp(%s) => %s == %s" %(input, result2, result1) print error self.assertTrue(result2==result1, error)
def test_SyslogDateFormat_format(self): from comoonics.search.datetime.TimeExpression import SyslogDateFormat, TimeExpression now=self.now() results=["(?P<month>Jan\w*|Feb\w*|Mar\w*|Apr\w*|Mai|Jun\w*|Jul\w*|Aug\w*|Sep\w*|Oct\w*)\s+(?P<day>\d{1,2}) (?P<hour>16):(?P<minute>\d{1,2}):(?P<second>\d{1,2})", "(?P<month>Sep\w*)\s+(?P<day>\d{1,2}) (?P<hour>04):(?P<minute>\d{1,2}):(?P<second>\d{1,2})", "(?P<month>%s)\s+(?P<day>%s) (?P<hour>%s):(?P<minute>%s):(?P<second>\d{1,2})" %(TimeExpression.toMonthname(now[1], False), now[2], now[3], now[4]), "(?P<month>Jun\w*)\s+(?P<day>25) (?P<hour>\d{1,2}):(?P<minute>\d{1,2}):(?P<second>\d{1,2})", "(?P<month>Jan\w*|Feb\w*|Mar\w*|Apr\w*|Mai|Jun\w*|Jul\w*|Aug\w*|Sep\w*|Oct\w*|Nov\w*|Dec\w*)\s+(?P<day>\d{1,2}) (?P<hour>\d{1,2}):(?P<minute>\d{1,2}):(?P<second>\d{1,2})"] for i in range(len(self.formater_teststrs)): self.basetest_Formater_format(SyslogDateFormat(), self.formater_teststrs[i], results[i])
def basetest_TimeExpression_toRegExp(self, teststr, _resultstr1): from comoonics.search.datetime.TimeExpression import TimeExpression _resultstr2=TimeExpression.toRegExp(teststr) _error="Testing TimeExpression.toRegExp(%s): %s == %s" %(teststr, _resultstr2, _resultstr1) print _error self.assertEquals(_resultstr1, _resultstr2, _error)