Ticket #21161: fix-21161-no-tzset-on-windows.patch

File fix-21161-no-tzset-on-windows.patch, 5.7 KB (added by Raphaël Barrois, 11 years ago)
  • tests/template_tests/filters.py

    diff --git a/tests/template_tests/filters.py b/tests/template_tests/filters.py
    index 317b8bc..6869685 100644
    a b consistent.  
    99from __future__ import unicode_literals
    1010
    1111from datetime import date, datetime, time, timedelta
     12import time as time_module
    1213
    1314from django.test.utils import str_prefix
    1415from django.utils.encoding import python_2_unicode_compatible
    class SafeClass:  
    2627    def __str__(self):
    2728        return mark_safe('you > me')
    2829
     30TZ_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
    2938# RESULT SYNTAX --
    3039# 'template_name': ('template contents', 'context dict',
    3140#                   'expected string output' or Exception class)
    def get_filter_tests():  
    5665        'filter-timesince10': ('{{ later|timesince:now }}', { 'now': now, 'later': now + timedelta(days=7) }, '0\xa0minutes'),
    5766
    5867        # 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).
    5969        '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 ('', {}, ''),
    6272        'filter-timesince14' : ('{{ a|timesince:b }}', {'a': now_tz, 'b': now_tz_i}, '0\xa0minutes'),
    6373        'filter-timesince15' : ('{{ a|timesince:b }}', {'a': now, 'b': now_tz_i}, ''),
    6474        'filter-timesince16' : ('{{ a|timesince:b }}', {'a': now_tz_i, 'b': now}, ''),
    def get_filter_tests():  
    8393        'filter-timeuntil09': ('{{ later|timeuntil:now }}', { 'now': now, 'later': now + timedelta(days=7) }, '1\xa0week'),
    8494
    8595        # 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'),
    88100
    89101        # 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'),
    92104
    93105        'filter-addslash01': ("{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}", {"a": "<a>'", "b": mark_safe("<a>'")}, r"<a>\' <a>\'"),
    94106        'filter-addslash02': ("{{ a|addslashes }} {{ b|addslashes }}", {"a": "<a>'", "b": mark_safe("<a>'")}, r"&lt;a&gt;\&#39; <a>\'"),
  • tests/utils_tests/test_timesince.py

    diff --git a/tests/utils_tests/test_timesince.py b/tests/utils_tests/test_timesince.py
    index b454131..4ffbd86 100644
    a b  
    11from __future__ import unicode_literals
    22
    33import datetime
     4import time
    45import unittest
    56
    67from django.utils.timesince import timesince, timeuntil
    78from django.utils import timezone
    89
    910
     11TZ_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
     18requires_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
    1022class TimesinceTests(unittest.TestCase):
    1123
    1224    def setUp(self):
    class TimesinceTests(unittest.TestCase):  
    93105        self.assertEqual(timesince(self.t,
    94106            self.t-4*self.oneday-5*self.oneminute), '0\xa0minutes')
    95107
     108    @requires_tz_support
    96109    def test_different_timezones(self):
    97110        """ When using two different timezones. """
    98111        now = datetime.datetime.now()
    class TimesinceTests(unittest.TestCase):  
    101114
    102115        self.assertEqual(timesince(now), '0\xa0minutes')
    103116        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')
    104122        self.assertEqual(timeuntil(now_tz, now_tz_i), '0\xa0minutes')
    105123
    106124    def test_date_objects(self):
Back to Top