From 123362dd37a076987f265179fe16dcd2b6a16d12 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 19 Jul 2012 20:02:20 +0200 Subject: [PATCH] Fixed #18608 -- Reduced monkey-patching in tests. Thanks Claude Paroz for the patch. --- django/contrib/humanize/templatetags/humanize.py | 4 ++-- django/contrib/humanize/tests.py | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py index 7a2e5147d8..1398b43676 100644 --- a/django/contrib/humanize/templatetags/humanize.py +++ b/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: diff --git a/django/contrib/humanize/tests.py b/django/contrib/humanize/tests.py index ecf4b83d6d..62df2be143 100644 --- a/django/contrib/humanize/tests.py +++ b/django/contrib/humanize/tests.py @@ -130,7 +130,7 @@ class HumanizeTests(TestCase): 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 @@ class HumanizeTests(TestCase): # 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