Browse files

Decorated some tests that require tz support.

This allows the test suite to run without errors on Windows.
  • Loading branch information...
1 parent 9008164 commit be7f1099c61004bda8c491fc4e7aab9f8b2c8512 @kmtracey kmtracey committed Aug 11, 2012
Showing with 17 additions and 0 deletions.
  1. +1 −0 tests/modeltests/timezones/tests.py
  2. +16 −0 tests/regressiontests/generic_views/dates.py
View
1 tests/modeltests/timezones/tests.py
@@ -467,6 +467,7 @@ def test_raw_sql(self):
[event],
transform=lambda d: d)
+ @requires_tz_support
def test_filter_date_field_with_aware_datetime(self):
# Regression test for #17742
day = datetime.date(2011, 9, 1)
View
16 tests/regressiontests/generic_views/dates.py
@@ -1,14 +1,27 @@
from __future__ import absolute_import
+import time
import datetime
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import timezone
+from django.utils.unittest import skipUnless
from .models import Book, BookSigning
+TZ_SUPPORT = hasattr(time, 'tzset')
+
+# On OSes that don't provide tzset (Windows), we can't set the timezone
+# in which the program runs. As a consequence, we must skip tests that
+# don't enforce a specific timezone (with timezone.override or equivalent),
+# or attempt to interpret naive datetimes in the default timezone.
+
+requires_tz_support = skipUnless(TZ_SUPPORT,
+ "This test relies on the ability to run a program in an arbitrary "
+ "time zone, but your operating system isn't able to do that.")
+
class ArchiveIndexViewTests(TestCase):
fixtures = ['generic-views-test-data.json']
@@ -100,6 +113,7 @@ def test_datetime_archive_view(self):
res = self.client.get('/dates/booksignings/')
self.assertEqual(res.status_code, 200)
+ @requires_tz_support
@override_settings(USE_TZ=True, TIME_ZONE='Africa/Nairobi')
def test_aware_datetime_archive_view(self):
BookSigning.objects.create(event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=timezone.utc))
@@ -502,6 +516,7 @@ def test_datetime_day_view(self):
res = self.client.get('/dates/booksignings/2008/apr/2/')
self.assertEqual(res.status_code, 200)
+ @requires_tz_support
@override_settings(USE_TZ=True, TIME_ZONE='Africa/Nairobi')
def test_aware_datetime_day_view(self):
bs = BookSigning.objects.create(event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=timezone.utc))
@@ -578,6 +593,7 @@ def test_datetime_date_detail(self):
res = self.client.get('/dates/booksignings/2008/apr/2/%d/' % bs.pk)
self.assertEqual(res.status_code, 200)
+ @requires_tz_support
@override_settings(USE_TZ=True, TIME_ZONE='Africa/Nairobi')
def test_aware_datetime_date_detail(self):
bs = BookSigning.objects.create(event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=timezone.utc))

0 comments on commit be7f109

Please sign in to comment.