Merge pull request #479 from grooverdan/tst-CustomDateFormatsTest

TST: missed including testcases CustomDateFormatsTest
pull/492/head
Daniel Black 11 years ago
commit 051c2a5f50

@ -41,7 +41,7 @@ __all__ = ["parse_date", "ParseError"]
# Adapted from http://delete.me.uk/2005/03/iso8601.html
ISO8601_REGEX_RAW = "(?P<year>[0-9]{4})-(?P<month>[0-9]{1,2})-(?P<day>[0-9]{1,2})" \
"T(?P<hour>[0-9]{2}):(?P<minute>[0-9]{2})(:(?P<second>[0-9]{2})(\.(?P<fraction>[0-9]+))?)?" \
"(?P<timezone>Z|(([-+])([0-9]{2}):([0-9]{2})))?"
"(?P<timezone>Z|[-+][0-9]{2}(:?[0-9]{2})?)?"
ISO8601_REGEX = re.compile(ISO8601_REGEX_RAW)
TIMEZONE_REGEX = re.compile("(?P<prefix>[+-])(?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2})?")

@ -172,6 +172,7 @@ class TestsUtilsTest(unittest.TestCase):
from fail2ban.server import iso8601
import datetime
import time
class CustomDateFormatsTest(unittest.TestCase):
@ -190,8 +191,25 @@ class CustomDateFormatsTest(unittest.TestCase):
iso8601.parse_date, "2007-01-01T120:00:00Z")
self.assertRaises(iso8601.ParseError,
iso8601.parse_date, "2007-13-01T12:00:00Z")
date = iso8601.parse_date("2007-01-25T12:00:00+0400")
self.assertEqual(
date,
datetime.datetime(2007, 1, 25, 8, 0, tzinfo=iso8601.Utc()))
date = iso8601.parse_date("2007-01-25T12:00:00+04:00")
self.assertEqual(
date,
datetime.datetime(2007, 1, 25, 8, 0, tzinfo=iso8601.Utc()))
date = iso8601.parse_date("2007-01-25T12:00:00-0400")
self.assertEqual(
date,
datetime.datetime(2007, 1, 25, 16, 0, tzinfo=iso8601.Utc()))
date = iso8601.parse_date("2007-01-25T12:00:00-04")
self.assertEqual(
date,
datetime.datetime(2007, 1, 25, 16, 0, tzinfo=iso8601.Utc()))
def testTimeZone(self):
# Just verify consistent operation and improve coverage ;)
self.assertEqual(iso8601.parse_timezone(None), iso8601.UTC)
self.assertEqual(iso8601.parse_timezone('Z'), iso8601.UTC)
self.assertEqual((iso8601.parse_timezone(None).tzname(False), iso8601.parse_timezone(None).tzname(True)), time.tzname)
self.assertEqual(iso8601.parse_timezone('Z').tzname(True), "UTC")
self.assertEqual(iso8601.parse_timezone('Z').dst(True), datetime.timedelta(0))

@ -184,6 +184,7 @@ def gatherTests(regexps=None, no_network=False):
tests.addTest(unittest.makeSuite(misctestcase.HelpersTest))
tests.addTest(unittest.makeSuite(misctestcase.SetupTest))
tests.addTest(unittest.makeSuite(misctestcase.TestsUtilsTest))
tests.addTest(unittest.makeSuite(misctestcase.CustomDateFormatsTest))
# Filter
if not no_network:

Loading…
Cancel
Save