'Test detection of various common date/time formats f2b should understand'

def testVariousTimes(self):

    dateUnix = 1106513999.0
    for (anchored, bound, sdate, rdate) in ((False, True, 'Jan    23    21:59:59', None), (False, False, 'Sun    Jan    23    21:59:59    2005', None), (False, False, 'Sun    Jan    23    21:59:59', None), (False, False, 'Sun    Jan    23    2005    21:59:59', None), (False, True, '2005/01/23    21:59:59', None), (False, True, '2005.01.23    21:59:59', None), (False, True, '23/01/2005    21:59:59', None), (False, True, '23/01/05    21:59:59', None), (False, True, '23/Jan/2005:21:59:59', None), (False, True, '23/Jan/2005:21:59:59    +0100', None), (False, True, '01/23/2005:21:59:59', None), (False, True, '2005-01-23    21:59:59', None), (False, True, '2005-01-23    21:59:59,000', None), (False, True, '23-Jan-2005    21:59:59', None), (False, True, '23-Jan-2005    21:59:59.02', None), (False, True, '23-Jan-2005    21:59:59    +0100', None), (False, True, '23-01-2005    21:59:59', None), (True, True, '1106513999', None), (False, True, '01-23-2005    21:59:59.252', None), (False, False, '@4000000041f4104f00000000', None), (False, True, '2005-01-23T20:59:59.252Z', None), (False, True, '2005-01-23T15:59:59-05:00', None), (False, True, '2005-01-23    21:59:59', None), (False, True, '20050123T215959', None), (False, True, '20050123    215959', None), (True, True, '<01/23/05@21:59:59>', None), (False, True, '050123    21:59:59', None), (True, True, 'Jan-23-05    21:59:59', None), (False, True, 'Jan    23,    2005    9:59:59    PM', None), (True, True, '1106513999', None), (True, True, '1106513999.000', None), (True, True, '[1106513999.000]', '1106513999.000'), (False, True, 'audit(1106513999.000:987)', '1106513999.000'), (True, True, 'no    date    line', None)):
        if ((rdate is None) and (sdate != 'no    date    line')):
            rdate = sdate
        logSys.debug('==    test    %r', (anchored, bound, sdate, rdate))
        for (should_match, prefix) in (((rdate is not None), ''), ((not anchored), 'bogus-prefix    '), (False, 'word-boundary')):
            log = ((prefix + sdate) + '[sshd]    error:    PAM:    Authentication    failure')
            if ((not bound) and (prefix == 'word-boundary')):
                continue
            logSys.debug('        --    test    %-5s    for    %r', should_match, log)
            logtime = self.datedetector.getTime(log)
            if should_match:
                self.assertNotEqual(logtime, None, ('getTime    retrieved    nothing:    failure    for    %s    by    prefix    %r,    anchored:    %r,    log:    %s' % (sdate, prefix, anchored, log)))
                (logUnix, logMatch) = logtime
                self.assertEqual(logUnix, dateUnix, ('getTime    comparison    failure    for    %s:    by    prefix    %r    "%s"    is    not    "%s"' % (sdate, prefix, logUnix, dateUnix)))
                self.assertEqual(logMatch.group(1), rdate)
            else:
                self.assertEqual(logtime, None, ('getTime    should    have    not    matched    for    %r    by    prefix    %r    Got:    %s' % (sdate, prefix, logtime)))
            (timeMatch, template) = matchTime = self.datedetector.matchTime(log)
            logtime = self.datedetector.getTime(log, matchTime)
            logSys.debug('        --    found    -    %r', (template.name if timeMatch else False))
            if should_match:
                self.assertNotEqual(logtime, None, ('getTime    retrieved    nothing:    failure    for    %s    by    prefix    %r,    anchored:    %r,    log:    %s' % (sdate, prefix, anchored, log)))
                (logUnix, logMatch) = logtime
                self.assertEqual(logUnix, dateUnix, ('getTime    comparison    failure    for    %s    by    prefix    %r:    "%s"    is    not    "%s"' % (sdate, prefix, logUnix, dateUnix)))
                self.assertEqual(logMatch.group(1), rdate)
            else:
                self.assertEqual(logtime, None, ('getTime    should    have    not    matched    for    %r    by    prefix    %r    Got:    %s' % (sdate, prefix, logtime)))
            logSys.debug('        --    OK')
