Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18608 -- Reduced monkey-patching in tests.

Thanks Claude Paroz for the patch.
  • Loading branch information...
commit 123362dd37a076987f265179fe16dcd2b6a16d12 1 parent c54905b
@aaugustin aaugustin authored
View
4 django/contrib/humanize/templatetags/humanize.py
@@ -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:
@@ -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:
View
8 django/contrib/humanize/tests.py
@@ -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),
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.