diff --git a/tests/template_tests/filters.py b/tests/template_tests/filters.py
index 317b8bc..6869685 100644
a
|
b
|
consistent.
|
9 | 9 | from __future__ import unicode_literals |
10 | 10 | |
11 | 11 | from datetime import date, datetime, time, timedelta |
| 12 | import time as time_module |
12 | 13 | |
13 | 14 | from django.test.utils import str_prefix |
14 | 15 | from django.utils.encoding import python_2_unicode_compatible |
… |
… |
class SafeClass:
|
26 | 27 | def __str__(self): |
27 | 28 | return mark_safe('you > me') |
28 | 29 | |
| 30 | TZ_SUPPORT = hasattr(time_module, 'tzset') |
| 31 | |
| 32 | # On OSes that don't provide tzset (Windows), we can't set the timezone |
| 33 | # in which the program runs. As a consequence, we must skip tests that |
| 34 | # don't enforce a specific timezone (with timezone.override or equivalent), |
| 35 | # or attempt to interpret naive datetimes in the default timezone. |
| 36 | |
| 37 | |
29 | 38 | # RESULT SYNTAX -- |
30 | 39 | # 'template_name': ('template contents', 'context dict', |
31 | 40 | # 'expected string output' or Exception class) |
… |
… |
def get_filter_tests():
|
56 | 65 | 'filter-timesince10': ('{{ later|timesince:now }}', { 'now': now, 'later': now + timedelta(days=7) }, '0\xa0minutes'), |
57 | 66 | |
58 | 67 | # Ensures that differing timezones are calculated correctly |
| 68 | # Tests trying to compare a timezone-aware 'now' to now aren't supported on no-tz-support systems (e.g Windows). |
59 | 69 | 'filter-timesince11' : ('{{ a|timesince }}', {'a': now}, '0\xa0minutes'), |
60 | | 'filter-timesince12' : ('{{ a|timesince }}', {'a': now_tz}, '0\xa0minutes'), |
61 | | 'filter-timesince13' : ('{{ a|timesince }}', {'a': now_tz_i}, '0\xa0minutes'), |
| 70 | 'filter-timesince12' : ('{{ a|timesince }}', {'a': now_tz}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''), |
| 71 | 'filter-timesince13' : ('{{ a|timesince }}', {'a': now_tz_i}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''), |
62 | 72 | 'filter-timesince14' : ('{{ a|timesince:b }}', {'a': now_tz, 'b': now_tz_i}, '0\xa0minutes'), |
63 | 73 | 'filter-timesince15' : ('{{ a|timesince:b }}', {'a': now, 'b': now_tz_i}, ''), |
64 | 74 | 'filter-timesince16' : ('{{ a|timesince:b }}', {'a': now_tz_i, 'b': now}, ''), |
… |
… |
def get_filter_tests():
|
83 | 93 | 'filter-timeuntil09': ('{{ later|timeuntil:now }}', { 'now': now, 'later': now + timedelta(days=7) }, '1\xa0week'), |
84 | 94 | |
85 | 95 | # Ensures that differing timezones are calculated correctly |
86 | | 'filter-timeuntil10' : ('{{ a|timeuntil }}', {'a': now_tz_i}, '0\xa0minutes'), |
87 | | 'filter-timeuntil11' : ('{{ a|timeuntil:b }}', {'a': now_tz_i, 'b': now_tz}, '0\xa0minutes'), |
| 96 | # Tests trying to compare a timezone-aware 'now' to now aren't supported on no-tz-support systems (e.g Windows). |
| 97 | 'filter-timeuntil10' : ('{{ a|timeuntil }}', {'a': now_tz}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''), |
| 98 | 'filter-timeuntil11' : ('{{ a|timeuntil }}', {'a': now_tz_i}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''), |
| 99 | 'filter-timeuntil12' : ('{{ a|timeuntil:b }}', {'a': now_tz_i, 'b': now_tz}, '0\xa0minutes'), |
88 | 100 | |
89 | 101 | # Regression for #9065 (two date objects). |
90 | | 'filter-timeuntil12' : ('{{ a|timeuntil:b }}', {'a': today, 'b': today}, '0\xa0minutes'), |
91 | | 'filter-timeuntil13' : ('{{ a|timeuntil:b }}', {'a': today, 'b': today - timedelta(hours=24)}, '1\xa0day'), |
| 102 | 'filter-timeuntil13' : ('{{ a|timeuntil:b }}', {'a': today, 'b': today}, '0\xa0minutes'), |
| 103 | 'filter-timeuntil14' : ('{{ a|timeuntil:b }}', {'a': today, 'b': today - timedelta(hours=24)}, '1\xa0day'), |
92 | 104 | |
93 | 105 | 'filter-addslash01': ("{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}", {"a": "<a>'", "b": mark_safe("<a>'")}, r"<a>\' <a>\'"), |
94 | 106 | 'filter-addslash02': ("{{ a|addslashes }} {{ b|addslashes }}", {"a": "<a>'", "b": mark_safe("<a>'")}, r"<a>\' <a>\'"), |
diff --git a/tests/utils_tests/test_timesince.py b/tests/utils_tests/test_timesince.py
index b454131..4ffbd86 100644
a
|
b
|
|
1 | 1 | from __future__ import unicode_literals |
2 | 2 | |
3 | 3 | import datetime |
| 4 | import time |
4 | 5 | import unittest |
5 | 6 | |
6 | 7 | from django.utils.timesince import timesince, timeuntil |
7 | 8 | from django.utils import timezone |
8 | 9 | |
9 | 10 | |
| 11 | TZ_SUPPORT = hasattr(time, 'tzset') |
| 12 | |
| 13 | # On OSes that don't provide tzset (Windows), we can't set the timezone |
| 14 | # in which the program runs. As a consequence, we must skip tests that |
| 15 | # don't enforce a specific timezone (with timezone.override or equivalent), |
| 16 | # or attempt to interpret naive datetimes in the default timezone. |
| 17 | |
| 18 | requires_tz_support = unittest.skipUnless(TZ_SUPPORT, |
| 19 | "This test relies on the ability to run a program in an arbitrary " |
| 20 | "time zone, but your operating system isn't able to do that.") |
| 21 | |
10 | 22 | class TimesinceTests(unittest.TestCase): |
11 | 23 | |
12 | 24 | def setUp(self): |
… |
… |
class TimesinceTests(unittest.TestCase):
|
93 | 105 | self.assertEqual(timesince(self.t, |
94 | 106 | self.t-4*self.oneday-5*self.oneminute), '0\xa0minutes') |
95 | 107 | |
| 108 | @requires_tz_support |
96 | 109 | def test_different_timezones(self): |
97 | 110 | """ When using two different timezones. """ |
98 | 111 | now = datetime.datetime.now() |
… |
… |
class TimesinceTests(unittest.TestCase):
|
101 | 114 | |
102 | 115 | self.assertEqual(timesince(now), '0\xa0minutes') |
103 | 116 | self.assertEqual(timesince(now_tz), '0\xa0minutes') |
| 117 | self.assertEqual(timesince(now_tz_i), '0\xa0minutes') |
| 118 | self.assertEqual(timesince(now_tz, now_tz_i), '0\xa0minutes') |
| 119 | self.assertEqual(timeuntil(now), '0\xa0minutes') |
| 120 | self.assertEqual(timeuntil(now_tz), '0\xa0minutes') |
| 121 | self.assertEqual(timeuntil(now_tz_i), '0\xa0minutes') |
104 | 122 | self.assertEqual(timeuntil(now_tz, now_tz_i), '0\xa0minutes') |
105 | 123 | |
106 | 124 | def test_date_objects(self): |