Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17463 -- Conditionally skipped tests that Windows isn't able t…

…o run.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17278 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a62ce30661c62606b5648ac27ac808bbb1b0e6bb 1 parent e8a6fee
Aymeric Augustin authored

Showing 1 changed file with 26 additions and 1 deletion. Show diff stats Hide diff stats

  1. 27  tests/modeltests/timezones/tests.py
27  tests/modeltests/timezones/tests.py
@@ -22,7 +22,7 @@
22 22
 from django.test.utils import override_settings
23 23
 from django.utils import timezone
24 24
 from django.utils.tzinfo import FixedOffset
25  
-from django.utils.unittest import skipIf
  25
+from django.utils.unittest import skipIf, skipUnless
26 26
 
27 27
 from .forms import EventForm, EventSplitForm, EventModelForm
28 28
 from .models import Event, MaybeEvent, Timestamp
@@ -42,6 +42,15 @@
42 42
 
43 43
 TZ_SUPPORT = hasattr(time, 'tzset')
44 44
 
  45
+# On OSes that don't provide tzset (Windows), we can't set the timezone
  46
+# in which the program runs. As a consequence, we must skip tests that
  47
+# don't enforce a specific timezone (with timezone.override or equivalent),
  48
+# or attempt to interpret naive datetimes in the default timezone.
  49
+
  50
+requires_tz_support = skipUnless(TZ_SUPPORT,
  51
+        "This test relies on the ability to run a program in an arbitrary "
  52
+        "time zone, but your operating system isn't able to do that.")
  53
+
45 54
 
46 55
 class BaseDateTimeTests(TestCase):
47 56
 
@@ -238,6 +247,7 @@ def test_query_dates(self):
238 247
 #@override_settings(USE_TZ=True)
239 248
 class NewDatabaseTests(BaseDateTimeTests):
240 249
 
  250
+    @requires_tz_support
241 251
     @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
242 252
     def test_naive_datetime(self):
243 253
         dt = datetime.datetime(2011, 9, 1, 13, 20, 30)
@@ -251,6 +261,7 @@ def test_naive_datetime(self):
251 261
         # naive datetimes are interpreted in local time
252 262
         self.assertEqual(event.dt, dt.replace(tzinfo=EAT))
253 263
 
  264
+    @requires_tz_support
254 265
     @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
255 266
     @skipUnlessDBFeature('supports_microsecond_precision')
256 267
     def test_naive_datetime_with_microsecond(self):
@@ -265,6 +276,7 @@ def test_naive_datetime_with_microsecond(self):
265 276
         # naive datetimes are interpreted in local time
266 277
         self.assertEqual(event.dt, dt.replace(tzinfo=EAT))
267 278
 
  279
+    @requires_tz_support
268 280
     @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
269 281
     @skipIfDBFeature('supports_microsecond_precision')
270 282
     def test_naive_datetime_with_microsecond_unsupported(self):
@@ -347,6 +359,7 @@ def test_query_filter_with_pytz_timezones(self):
347 359
         self.assertEqual(Event.objects.filter(dt__in=(prev, dt, next)).count(), 1)
348 360
         self.assertEqual(Event.objects.filter(dt__range=(prev, next)).count(), 1)
349 361
 
  362
+    @requires_tz_support
350 363
     @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6")
351 364
     def test_query_filter_with_naive_datetime(self):
352 365
         dt = datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=EAT)
@@ -567,6 +580,7 @@ def test_aware_datetime_in_other_timezone(self):
567 580
 #@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
568 581
 class TemplateTests(BaseDateTimeTests):
569 582
 
  583
+    @requires_tz_support
570 584
     def test_localtime_templatetag_and_filters(self):
571 585
         """
572 586
         Test the {% localtime %} templatetag and related filters.
@@ -686,6 +700,7 @@ def test_localtime_filters_do_not_raise_exceptions(self):
686 700
             ctx = Context({'dt': datetime.datetime(2011, 9, 1, 13, 20, 30), 'tz': 'not a tz'})
687 701
             self.assertEqual(tpl.render(ctx), "")
688 702
 
  703
+    @requires_tz_support
689 704
     def test_timezone_templatetag(self):
690 705
         """
691 706
         Test the {% timezone %} templatetag.
@@ -725,6 +740,7 @@ def test_timezone_templatetag_invalid_argument(self):
725 740
         with self.assertRaises(ValueError if pytz is None else pytz.UnknownTimeZoneError):
726 741
             Template("{% load tz %}{% timezone tz %}{% endtimezone %}").render(Context({'tz': 'foobar'}))
727 742
 
  743
+    @skipIf(sys.platform.startswith('win'), "Windows uses non-standard time zone names")
728 744
     def test_get_current_timezone_templatetag(self):
729 745
         """
730 746
         Test the {% get_current_timezone %} templatetag.
@@ -757,6 +773,7 @@ def test_get_current_timezone_templatetag_invalid_argument(self):
757 773
         with self.assertRaises(TemplateSyntaxError):
758 774
             Template("{% load tz %}{% get_current_timezone %}").render()
759 775
 
  776
+    @skipIf(sys.platform.startswith('win'), "Windows uses non-standard time zone names")
760 777
     def test_tz_template_context_processor(self):
761 778
         """
762 779
         Test the django.core.context_processors.tz template context processor.
@@ -765,6 +782,7 @@ def test_tz_template_context_processor(self):
765 782
         self.assertEqual(tpl.render(Context()), "")
766 783
         self.assertEqual(tpl.render(RequestContext(HttpRequest())), "Africa/Nairobi" if pytz else "EAT")
767 784
 
  785
+    @requires_tz_support
768 786
     def test_date_and_time_template_filters(self):
769 787
         tpl = Template("{{ dt|date:'Y-m-d' }} at {{ dt|time:'H:i:s' }}")
770 788
         ctx = Context({'dt': datetime.datetime(2011, 9, 1, 20, 20, 20, tzinfo=UTC)})
@@ -790,6 +808,7 @@ def test_localtime_with_time_zone_setting_set_to_none(self):
790 808
             self.assertTrue(tpl.render(ctx).startswith("2011"))
791 809
         timezone._localtime = None
792 810
 
  811
+    @requires_tz_support
793 812
     def test_now_template_tag_uses_current_time_zone(self):
794 813
         # Regression for #17343
795 814
         tpl = Template("{% now \"O\" %}")
@@ -838,6 +857,7 @@ def test_model_form(self):
838 857
 #@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)
839 858
 class NewFormsTests(BaseDateTimeTests):
840 859
 
  860
+    @requires_tz_support
841 861
     def test_form(self):
842 862
         form = EventForm({'dt': u'2011-09-01 13:20:30'})
843 863
         self.assertTrue(form.is_valid())
@@ -867,11 +887,13 @@ def test_form_with_ambiguous_time(self):
867 887
                 [u"2011-10-30 02:30:00 couldn't be interpreted in time zone "
868 888
                  u"Europe/Paris; it may be ambiguous or it may not exist."])
869 889
 
  890
+    @requires_tz_support
870 891
     def test_split_form(self):
871 892
         form = EventSplitForm({'dt_0': u'2011-09-01', 'dt_1': u'13:20:30'})
872 893
         self.assertTrue(form.is_valid())
873 894
         self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
874 895
 
  896
+    @requires_tz_support
875 897
     def test_model_form(self):
876 898
         EventModelForm({'dt': u'2011-09-01 13:20:30'}).save()
877 899
         e = Event.objects.get()
@@ -888,6 +910,7 @@ class AdminTests(BaseDateTimeTests):
888 910
     def setUp(self):
889 911
         self.client.login(username='super', password='secret')
890 912
 
  913
+    @requires_tz_support
891 914
     def test_changelist(self):
892 915
         e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
893 916
         response = self.client.get(reverse('admin:timezones_event_changelist'))
@@ -899,6 +922,7 @@ def test_changelist_in_other_timezone(self):
899 922
             response = self.client.get(reverse('admin:timezones_event_changelist'))
900 923
         self.assertContains(response, e.dt.astimezone(ICT).isoformat())
901 924
 
  925
+    @requires_tz_support
902 926
     def test_change_editable(self):
903 927
         e = Event.objects.create(dt=datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC))
904 928
         response = self.client.get(reverse('admin:timezones_event_change', args=(e.pk,)))
@@ -912,6 +936,7 @@ def test_change_editable_in_other_timezone(self):
912 936
         self.assertContains(response, e.dt.astimezone(ICT).date().isoformat())
913 937
         self.assertContains(response, e.dt.astimezone(ICT).time().isoformat())
914 938
 
  939
+    @requires_tz_support
915 940
     def test_change_readonly(self):
916 941
         Timestamp.objects.create()
917 942
         # re-fetch the object for backends that lose microseconds (MySQL)

0 notes on commit a62ce30

Please sign in to comment.
Something went wrong with that request. Please try again.