def test_parse_ordinal_date(self): date = _parse_ordinal_date('1981-095') self.assertEqual(date.year, 1981) self.assertEqual(date.month, 4) self.assertEqual(date.day, 5) date = _parse_ordinal_date('1981095') self.assertEqual(date.year, 1981) self.assertEqual(date.month, 4) self.assertEqual(date.day, 5)
def test_parse_ordinal_date(self): date = _parse_ordinal_date('1981-095') self.assertEqual(date, datetime.date(1981, 4, 5)) date = _parse_ordinal_date('1981095') self.assertEqual(date, datetime.date(1981, 4, 5)) date = _parse_ordinal_date('1981365') self.assertEqual(date, datetime.date(1981, 12, 31)) date = _parse_ordinal_date('1980366') self.assertEqual(date, datetime.date(1980, 12, 31))
def test_parse_ordinal_date(self): testtuples = (('1981-095', {'YYYY': '1981', 'DDD': '095'}), ('1981095', {'YYYY': '1981', 'DDD': '095'}), ('1981365', {'YYYY': '1981', 'DDD': '365'}), ('1980366', {'YYYY': '1980', 'DDD': '366'})) for testtuple in testtuples: mockBuilder = mock.Mock() mockBuilder.build_date.return_value = testtuple[1] result = _parse_ordinal_date(testtuple[0], mockBuilder) self.assertEqual(result, testtuple[1]) mockBuilder.build_date.assert_called_once_with(**testtuple[1])
def test_parse_ordinal_date(self): testtuples = ( ("1981-095", {"YYYY": "1981", "DDD": "095"}), ("1981095", {"YYYY": "1981", "DDD": "095"}), ("1981365", {"YYYY": "1981", "DDD": "365"}), ("1980366", {"YYYY": "1980", "DDD": "366"}), ) for testtuple in testtuples: mockBuilder = mock.Mock() mockBuilder.build_date.return_value = testtuple[1] result = _parse_ordinal_date(testtuple[0], mockBuilder) self.assertEqual(result, testtuple[1]) mockBuilder.build_date.assert_called_once_with(**testtuple[1])
def test_parse_ordinal_date_overflow(self): #Day must me 365, or 366, not larger with self.assertRaises(DayOutOfBoundsError): _parse_ordinal_date('1981367')
def test_parse_ordinal_date_nonleap(self): #Day 366 is only valid on a leap year with self.assertRaises(DayOutOfBoundsError): _parse_ordinal_date('1981366')
def test_parse_ordinal_date_zero(self): #0 isn't a valid day of year with self.assertRaises(DayOutOfBoundsError): _parse_ordinal_date('1981000')