'Test date parsing'

def testDateParsing(self):

    assertEqual = self.assertEqual
    assertRaises = self.assertRaises
    now = current.request.utcnow
    test_dates = (('%Y-%m-%d', '2009-04-16', (2009, 4, 16, 0, 0, 0)), ('%d.%m.%Y', '1.8.1936', (1936, 8, 1, 0, 0, 0)), ('%d/%m/%y', None, 'TypeError'), ('%d/%m/%y', '16.04.1678', 'ValueError'), ('%d/%m/%Y', '31/04/1678', (1678, 5, 1, 0, 0, 0)), ('%d/%m/%Y', '16/04/1678', (1678, 4, 16, 0, 0, 0)), ('%d/%m/%Y', '03/4/1785', (1785, 4, 3, 0, 0, 0)), ('%d/%m/%y', '16/04/78', (2078, 4, 16, 0, 0, 0)), ('%d/%m', '16/04', (now.year, 4, 16, 0, 0, 0)), ('%d.%B', '16.January', (now.year, 1, 16, 0, 0, 0)), ('%d-%b-%Y', '27-Mar-2005', (2005, 3, 27, 0, 0, 0)))
    c = S3Calendar('Gregorian')
    for (dtfmt, string, timetuple) in test_dates:
        parser = S3DateTimeParser(c, dtfmt)
        if (timetuple == 'ValueError'):
            with assertRaises(ValueError):
                result = parser.parse(string)
        elif (timetuple == 'TypeError'):
            with assertRaises(TypeError):
                result = parser.parse(string)
        else:
            result = parser.parse(string)
            assertEqual(result, timetuple)
