Fix issue in validatorfuncs.timedelta() in which days and years (in days) aren't added to create datetime.timedelta(days=days, ...)

This commit is contained in:
Henddher Pedroza 2019-10-24 21:10:46 -04:00
parent fffa1937e5
commit 56ab5d32a5

View file

@ -44,10 +44,13 @@ class TestValidatorFuncs(TestCase):
self.assertTrue(
isinstance(validatorfuncs.duration(d), datetime.timedelta))
# THE FOLLOWING FAILS, year calculation seems to be incorrect
# self.assertEqual(
# datetime.timedelta(1+5*365, 2, 0, 0, 3, 4, 5),
# validatorfuncs.duration('1d 2s 3m 4h 5w 5y'))
self.assertEqual(
datetime.timedelta(1+6*365, 2, 0, 0, 3, 4, 5),
validatorfuncs.duration('1d 2s 3m 4h 5w 6y'))
# values may be duplicated
self.assertEqual(
datetime.timedelta((1+7)+(6+12)*365, 2+8, 0, 0, 3+9, 4+10, 5+11),
validatorfuncs.duration('1d 2s 3m 4h 5w 6y 7d 8s 9m 10h 11w 12y'))
def test_duration_raises_ValueError(self):
for d in ['', '1', '5days', '1Week']: