mirror of
https://github.com/django/django.git
synced 2024-12-26 02:56:25 +00:00
Fixed #18608 -- Reduced monkey-patching in tests.
Thanks Claude Paroz for the patch.
This commit is contained in:
parent
c54905b359
commit
123362dd37
@ -184,7 +184,7 @@ def naturaltime(value):
|
|||||||
if delta.days != 0:
|
if delta.days != 0:
|
||||||
return pgettext(
|
return pgettext(
|
||||||
'naturaltime', '%(delta)s ago'
|
'naturaltime', '%(delta)s ago'
|
||||||
) % {'delta': defaultfilters.timesince(value)}
|
) % {'delta': defaultfilters.timesince(value, now)}
|
||||||
elif delta.seconds == 0:
|
elif delta.seconds == 0:
|
||||||
return _('now')
|
return _('now')
|
||||||
elif delta.seconds < 60:
|
elif delta.seconds < 60:
|
||||||
@ -206,7 +206,7 @@ def naturaltime(value):
|
|||||||
if delta.days != 0:
|
if delta.days != 0:
|
||||||
return pgettext(
|
return pgettext(
|
||||||
'naturaltime', '%(delta)s from now'
|
'naturaltime', '%(delta)s from now'
|
||||||
) % {'delta': defaultfilters.timeuntil(value)}
|
) % {'delta': defaultfilters.timeuntil(value, now)}
|
||||||
elif delta.seconds == 0:
|
elif delta.seconds == 0:
|
||||||
return _('now')
|
return _('now')
|
||||||
elif delta.seconds < 60:
|
elif delta.seconds < 60:
|
||||||
|
@ -130,7 +130,7 @@ class HumanizeTests(TestCase):
|
|||||||
def utcoffset(self, dt):
|
def utcoffset(self, dt):
|
||||||
return None
|
return None
|
||||||
# we're going to mock datetime.datetime, so use a fixed datetime
|
# 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 = [
|
test_list = [
|
||||||
now,
|
now,
|
||||||
now - datetime.timedelta(seconds=1),
|
now - datetime.timedelta(seconds=1),
|
||||||
@ -185,17 +185,11 @@ class HumanizeTests(TestCase):
|
|||||||
# equals now.replace(tzinfo=utc)
|
# equals now.replace(tzinfo=utc)
|
||||||
return now.replace(tzinfo=tz) + tz.utcoffset(now)
|
return now.replace(tzinfo=tz) + tz.utcoffset(now)
|
||||||
|
|
||||||
# naturaltime also calls timesince/timeuntil
|
|
||||||
from django.contrib.humanize.templatetags import humanize
|
from django.contrib.humanize.templatetags import humanize
|
||||||
from django.utils import timesince
|
|
||||||
orig_humanize_datetime = humanize.datetime
|
orig_humanize_datetime = humanize.datetime
|
||||||
orig_timesince_datetime = timesince.datetime
|
|
||||||
humanize.datetime = MockDateTime
|
humanize.datetime = MockDateTime
|
||||||
timesince.datetime = new.module(b"mock_datetime")
|
|
||||||
timesince.datetime.datetime = MockDateTime
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.humanize_tester(test_list, result_list, 'naturaltime')
|
self.humanize_tester(test_list, result_list, 'naturaltime')
|
||||||
finally:
|
finally:
|
||||||
humanize.datetime = orig_humanize_datetime
|
humanize.datetime = orig_humanize_datetime
|
||||||
timesince.datetime = orig_timesince_datetime
|
|
||||||
|
Loading…
Reference in New Issue
Block a user