Fix bug in implementation of `timeutils.daterange`

Currently, the `finished` function used in case of `stop` being None has a
different signature than the one used in case of `stop` being a date.
This commit remedies that and adds a test for the same.
This commit is contained in:
Ankit Goel 2018-10-11 12:54:38 +05:30 committed by Mahmoud Hashemi
parent d931428f0a
commit 139d5dcd32
2 changed files with 7 additions and 1 deletions

View File

@ -348,7 +348,7 @@ def daterange(start, stop, step=1, inclusive=False):
' (year, month, day), not: %r' % step) ' (year, month, day), not: %r' % step)
if stop is None: if stop is None:
finished = lambda t: False finished = lambda now, stop: False
elif start < stop: elif start < stop:
finished = operator.gt if inclusive else operator.ge finished = operator.gt if inclusive else operator.ge
else: else:

View File

@ -47,3 +47,9 @@ def test_daterange_years():
assert years_from_2025[0] == date(2025, 1, 1) assert years_from_2025[0] == date(2025, 1, 1)
assert years_from_2025[-1] == date(2017, 1, 1) assert years_from_2025[-1] == date(2017, 1, 1)
def test_daterange_infinite():
today = date.today()
infinite_dates = daterange(today, None)
for i in range(10):
assert next(infinite_dates) == today + timedelta(days=i)