Skip to content

Commit

Permalink
Fixed #18608 -- Reduced monkey-patching in tests.
Browse files Browse the repository at this point in the history
Thanks Claude Paroz for the patch.
  • Loading branch information
aaugustin committed Jul 19, 2012
1 parent c54905b commit 123362d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
4 changes: 2 additions & 2 deletions django/contrib/humanize/templatetags/humanize.py
Expand Up @@ -184,7 +184,7 @@ def naturaltime(value):
if delta.days != 0:
return pgettext(
'naturaltime', '%(delta)s ago'
) % {'delta': defaultfilters.timesince(value)}
) % {'delta': defaultfilters.timesince(value, now)}
elif delta.seconds == 0:
return _('now')
elif delta.seconds < 60:
Expand All @@ -206,7 +206,7 @@ def naturaltime(value):
if delta.days != 0:
return pgettext(
'naturaltime', '%(delta)s from now'
) % {'delta': defaultfilters.timeuntil(value)}
) % {'delta': defaultfilters.timeuntil(value, now)}
elif delta.seconds == 0:
return _('now')
elif delta.seconds < 60:
Expand Down
8 changes: 1 addition & 7 deletions django/contrib/humanize/tests.py
Expand Up @@ -130,7 +130,7 @@ class naive(datetime.tzinfo):
def utcoffset(self, dt):
return None
# we're going to mock datetime.datetime, so use a fixed datetime
now = datetime.datetime(2011, 8, 15)
now = datetime.datetime(2011, 8, 15, 1, 23)
test_list = [
now,
now - datetime.timedelta(seconds=1),
Expand Down Expand Up @@ -185,17 +185,11 @@ def now(self, tz=None):
# equals now.replace(tzinfo=utc)
return now.replace(tzinfo=tz) + tz.utcoffset(now)

# naturaltime also calls timesince/timeuntil
from django.contrib.humanize.templatetags import humanize
from django.utils import timesince
orig_humanize_datetime = humanize.datetime
orig_timesince_datetime = timesince.datetime
humanize.datetime = MockDateTime
timesince.datetime = new.module(b"mock_datetime")
timesince.datetime.datetime = MockDateTime

try:
self.humanize_tester(test_list, result_list, 'naturaltime')
finally:
humanize.datetime = orig_humanize_datetime
timesince.datetime = orig_timesince_datetime

0 comments on commit 123362d

Please sign in to comment.