1
0
mirror of https://github.com/django/django.git synced 2024-12-25 10:35:48 +00:00

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

Thanks Claude Paroz for the patch.
This commit is contained in:
Aymeric Augustin 2012-07-19 20:02:20 +02:00
parent c54905b359
commit 123362dd37
2 changed files with 3 additions and 9 deletions

View File

@ -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 File

@ -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