summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-10-07 21:06:49 -0400
committerTim Graham <timograham@gmail.com>2016-10-27 08:53:20 -0400
commit414ad25b090a63eaaf297b1164c8f7d814a710a2 (patch)
treee3d0e6fdffee0793baad41a339c2d63db742c33a /tests
parentd84ffcc22b2a0dbc0a44a67d56da7e3647e2f87a (diff)
Fixed #27327 -- Simplified time zone handling by requiring pytz.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_widgets/tests.py9
-rw-r--r--tests/cache/tests.py15
-rw-r--r--tests/datetimes/tests.py7
-rw-r--r--tests/db_functions/test_datetime.py9
-rw-r--r--tests/file_storage/tests.py18
-rw-r--r--tests/humanize_tests/tests.py8
-rw-r--r--tests/requirements/base.txt1
-rw-r--r--tests/schema/tests.py4
-rw-r--r--tests/syndication_tests/tests.py5
-rw-r--r--tests/timezones/tests.py32
-rw-r--r--tests/utils_tests/test_dateformat.py21
-rw-r--r--tests/utils_tests/test_timezone.py64
12 files changed, 27 insertions, 166 deletions
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py
index 057771bfa4..443e6c6e18 100644
--- a/tests/admin_widgets/tests.py
+++ b/tests/admin_widgets/tests.py
@@ -5,7 +5,8 @@ import gettext
import os
from datetime import datetime, timedelta
from importlib import import_module
-from unittest import skipIf
+
+import pytz
from django import forms
from django.conf import settings
@@ -23,11 +24,6 @@ from django.utils import six, translation
from . import models
from .widgetadmin import site as widget_admin_site
-try:
- import pytz
-except ImportError:
- pytz = None
-
class TestDataMixin(object):
@@ -794,7 +790,6 @@ class DateTimePickerSeleniumTests(AdminWidgetSeleniumTestCase):
self.wait_for_text('#calendarin0 caption', expected_caption)
-@skipIf(pytz is None, "this test requires pytz")
@override_settings(TIME_ZONE='Asia/Singapore')
class DateTimePickerShortcutsSeleniumTests(AdminWidgetSeleniumTestCase):
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 122017b54e..832727d53c 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -1832,17 +1832,16 @@ class CacheI18nTest(TestCase):
@override_settings(USE_I18N=False, USE_L10N=False, USE_TZ=True)
def test_cache_key_with_non_ascii_tzname(self):
- # Regression test for #17476
- class CustomTzName(timezone.UTC):
- name = ''
-
- def tzname(self, dt):
- return self.name
+ # Timezone-dependent cache keys should use ASCII characters only
+ # (#17476). The implementation here is a bit odd (timezone.utc is an
+ # instance, not a class), but it simulates the correct conditions.
+ class CustomTzName(timezone.utc):
+ pass
request = self.factory.get(self.path)
response = HttpResponse()
- with timezone.override(CustomTzName()):
- CustomTzName.name = 'Hora estándar de Argentina'.encode('UTF-8') # UTF-8 string
+ with timezone.override(CustomTzName):
+ CustomTzName.zone = 'Hora estándar de Argentina'.encode('UTF-8') # UTF-8 string
sanitized_name = 'Hora_estndar_de_Argentina'
self.assertIn(
sanitized_name, learn_cache_key(request, response),
diff --git a/tests/datetimes/tests.py b/tests/datetimes/tests.py
index efef456c43..273333e61c 100644
--- a/tests/datetimes/tests.py
+++ b/tests/datetimes/tests.py
@@ -1,18 +1,12 @@
from __future__ import unicode_literals
import datetime
-from unittest import skipIf
from django.test import TestCase, override_settings
from django.utils import timezone
from .models import Article, Category, Comment
-try:
- import pytz
-except ImportError:
- pytz = None
-
class DateTimesTests(TestCase):
def test_related_model_traverse(self):
@@ -84,7 +78,6 @@ class DateTimesTests(TestCase):
],
)
- @skipIf(pytz is None, "this test requires pytz")
@override_settings(USE_TZ=True)
def test_21432(self):
now = timezone.localtime(timezone.now().replace(microsecond=0))
diff --git a/tests/db_functions/test_datetime.py b/tests/db_functions/test_datetime.py
index 1b44c9a658..f9a9a54c1c 100644
--- a/tests/db_functions/test_datetime.py
+++ b/tests/db_functions/test_datetime.py
@@ -1,7 +1,8 @@
from __future__ import unicode_literals
from datetime import datetime
-from unittest import skipIf
+
+import pytz
from django.conf import settings
from django.db import connection
@@ -16,11 +17,6 @@ from django.utils import timezone
from .models import DTModel
-try:
- import pytz
-except ImportError:
- pytz = None
-
def microsecond_support(value):
return value if connection.features.supports_microsecond_precision else value.replace(microsecond=0)
@@ -659,7 +655,6 @@ class DateFunctionTests(TestCase):
list(DTModel.objects.annotate(truncated=TruncSecond('start_date', output_field=DateField())))
-@skipIf(pytz is None, "this test requires pytz")
@override_settings(USE_TZ=True, TIME_ZONE='UTC')
class DateFunctionWithTimeZoneTests(DateFunctionTests):
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index acb663ef7a..5492f105f7 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -32,12 +32,6 @@ from django.utils.six.moves.urllib.request import urlopen
from .models import Storage, temp_storage, temp_storage_location
-try:
- import pytz
-except ImportError:
- pytz = None
-
-
FILE_SUFFIX_REGEX = '[A-Za-z0-9]{7}'
@@ -99,10 +93,6 @@ class FileSystemStorageTests(unittest.TestCase):
storage.url(storage.base_url)
-# Tests for TZ-aware time methods need pytz.
-requires_pytz = unittest.skipIf(pytz is None, "this test requires pytz")
-
-
class FileStorageTests(SimpleTestCase):
storage_class = FileSystemStorage
@@ -157,7 +147,6 @@ class FileStorageTests(SimpleTestCase):
# different.
now_in_algiers = timezone.make_aware(datetime.now())
- # Use a fixed offset timezone so we don't need pytz.
with timezone.override(timezone.get_fixed_timezone(-300)):
# At this point the system TZ is +1 and the Django TZ
# is -5. The following will be aware in UTC.
@@ -191,7 +180,6 @@ class FileStorageTests(SimpleTestCase):
# different.
now_in_algiers = timezone.make_aware(datetime.now())
- # Use a fixed offset timezone so we don't need pytz.
with timezone.override(timezone.get_fixed_timezone(-300)):
# At this point the system TZ is +1 and the Django TZ
# is -5.
@@ -220,7 +208,6 @@ class FileStorageTests(SimpleTestCase):
_dt = timezone.make_aware(dt, now_in_algiers.tzinfo)
self.assertLess(abs(_dt - now_in_algiers), timedelta(seconds=2))
- @requires_pytz
def test_file_get_accessed_time(self):
"""
File storage returns a Datetime object for the last accessed time of
@@ -236,7 +223,6 @@ class FileStorageTests(SimpleTestCase):
self.assertEqual(atime, datetime.fromtimestamp(os.path.getatime(self.storage.path(f_name))))
self.assertLess(timezone.now() - self.storage.get_accessed_time(f_name), timedelta(seconds=2))
- @requires_pytz
@requires_tz_support
def test_file_get_accessed_time_timezone(self):
self._test_file_time_getter(self.storage.get_accessed_time)
@@ -256,7 +242,6 @@ class FileStorageTests(SimpleTestCase):
self.assertEqual(atime, datetime.fromtimestamp(os.path.getatime(self.storage.path(f_name))))
self.assertLess(datetime.now() - self.storage.accessed_time(f_name), timedelta(seconds=2))
- @requires_pytz
def test_file_get_created_time(self):
"""
File storage returns a datetime for the creation time of a file.
@@ -271,7 +256,6 @@ class FileStorageTests(SimpleTestCase):
self.assertEqual(ctime, datetime.fromtimestamp(os.path.getctime(self.storage.path(f_name))))
self.assertLess(timezone.now() - self.storage.get_created_time(f_name), timedelta(seconds=2))
- @requires_pytz
@requires_tz_support
def test_file_get_created_time_timezone(self):
self._test_file_time_getter(self.storage.get_created_time)
@@ -291,7 +275,6 @@ class FileStorageTests(SimpleTestCase):
self.assertEqual(ctime, datetime.fromtimestamp(os.path.getctime(self.storage.path(f_name))))
self.assertLess(datetime.now() - self.storage.created_time(f_name), timedelta(seconds=2))
- @requires_pytz
def test_file_get_modified_time(self):
"""
File storage returns a datetime for the last modified time of a file.
@@ -306,7 +289,6 @@ class FileStorageTests(SimpleTestCase):
self.assertEqual(mtime, datetime.fromtimestamp(os.path.getmtime(self.storage.path(f_name))))
self.assertLess(timezone.now() - self.storage.get_modified_time(f_name), timedelta(seconds=2))
- @requires_pytz
@requires_tz_support
def test_file_get_modified_time_timezone(self):
self._test_file_time_getter(self.storage.get_modified_time)
diff --git a/tests/humanize_tests/tests.py b/tests/humanize_tests/tests.py
index 22ae426954..a3cc512239 100644
--- a/tests/humanize_tests/tests.py
+++ b/tests/humanize_tests/tests.py
@@ -2,7 +2,6 @@ from __future__ import unicode_literals
import datetime
from decimal import Decimal
-from unittest import skipIf
from django.contrib.humanize.templatetags import humanize
from django.template import Context, Template, defaultfilters
@@ -12,12 +11,6 @@ from django.utils.html import escape
from django.utils.timezone import get_fixed_timezone, utc
from django.utils.translation import ugettext as _
-try:
- import pytz
-except ImportError:
- pytz = None
-
-
# Mock out datetime in some tests so they don't fail occasionally when they
# run too slow. Use a fixed datetime for datetime.now(). DST change in
# America/Chicago (the default time zone) happened on March 11th in 2012.
@@ -174,7 +167,6 @@ class HumanizeTests(SimpleTestCase):
# As 24h of difference they will never be the same
self.assertNotEqual(naturalday_one, naturalday_two)
- @skipIf(pytz is None, "this test requires pytz")
def test_naturalday_uses_localtime(self):
# Regression for #18504
# This is 2012-03-08HT19:30:00-06:00 in America/Chicago
diff --git a/tests/requirements/base.txt b/tests/requirements/base.txt
index 374b836fad..f9cb570c62 100644
--- a/tests/requirements/base.txt
+++ b/tests/requirements/base.txt
@@ -8,7 +8,6 @@ Pillow
PyYAML
# pylibmc/libmemcached can't be built on Windows.
pylibmc; sys.platform != 'win32'
-pytz > dev
selenium
sqlparse
tblib
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 9aeada3e67..567a1f86da 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -22,7 +22,7 @@ from django.test import (
TransactionTestCase, mock, skipIfDBFeature, skipUnlessDBFeature,
)
from django.test.utils import CaptureQueriesContext
-from django.utils.timezone import UTC
+from django.utils import timezone
from .fields import (
CustomManyToManyField, InheritedManyToManyField, MediumBlobField,
@@ -2187,7 +2187,7 @@ class SchemaTests(TransactionTestCase):
TimeField if auto_now or auto_add_now is set (#25005).
"""
now = datetime.datetime(month=1, day=1, year=2000, hour=1, minute=1)
- now_tz = datetime.datetime(month=1, day=1, year=2000, hour=1, minute=1, tzinfo=UTC())
+ now_tz = datetime.datetime(month=1, day=1, year=2000, hour=1, minute=1, tzinfo=timezone.utc)
mocked_datetime.now = mock.MagicMock(return_value=now)
mocked_tz.now = mock.MagicMock(return_value=now_tz)
# Create the table
diff --git a/tests/syndication_tests/tests.py b/tests/syndication_tests/tests.py
index 6f4655838a..60285efea7 100644
--- a/tests/syndication_tests/tests.py
+++ b/tests/syndication_tests/tests.py
@@ -16,11 +16,6 @@ from django.utils.feedgenerator import (
from .models import Article, Entry
-try:
- import pytz
-except ImportError:
- pytz = None
-
TZ = timezone.get_default_timezone()
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py
index e72fff069b..d95877d227 100644
--- a/tests/timezones/tests.py
+++ b/tests/timezones/tests.py
@@ -8,6 +8,8 @@ from contextlib import contextmanager
from unittest import SkipTest, skipIf
from xml.dom.minidom import parseString
+import pytz
+
from django.contrib.auth.models import User
from django.core import serializers
from django.core.exceptions import ImproperlyConfigured
@@ -33,13 +35,6 @@ from .models import (
AllDayEvent, Event, MaybeEvent, Session, SessionEvent, Timestamp,
)
-try:
- import pytz
-except ImportError:
- pytz = None
-
-requires_pytz = skipIf(pytz is None, "this test requires pytz")
-
# These tests use the EAT (Eastern Africa Time) and ICT (Indochina Time)
# who don't have Daylight Saving Time, so we can represent them easily
# with FixedOffset, and use them directly as tzinfo in the constructors.
@@ -363,7 +358,6 @@ class NewDatabaseTests(TestCase):
self.assertEqual(Event.objects.filter(dt__gte=dt2).count(), 1)
self.assertEqual(Event.objects.filter(dt__gt=dt2).count(), 0)
- @requires_pytz
def test_query_filter_with_pytz_timezones(self):
tz = pytz.timezone('Europe/Paris')
dt = datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=tz)
@@ -908,7 +902,6 @@ class TemplateTests(SimpleTestCase):
expected = results[k1][k2]
self.assertEqual(actual, expected, '%s / %s: %r != %r' % (k1, k2, actual, expected))
- @requires_pytz
def test_localtime_filters_with_pytz(self):
"""
Test the |localtime, |utc, and |timezone filters with pytz.
@@ -976,7 +969,6 @@ class TemplateTests(SimpleTestCase):
"2011-09-01T13:20:30+03:00|2011-09-01T17:20:30+07:00|2011-09-01T13:20:30+03:00"
)
- @requires_pytz
def test_timezone_templatetag_with_pytz(self):
"""
Test the {% timezone %} templatetag with pytz.
@@ -996,7 +988,7 @@ class TemplateTests(SimpleTestCase):
def test_timezone_templatetag_invalid_argument(self):
with self.assertRaises(TemplateSyntaxError):
Template("{% load tz %}{% timezone %}{% endtimezone %}").render()
- with self.assertRaises(ValueError if pytz is None else pytz.UnknownTimeZoneError):
+ with self.assertRaises(pytz.UnknownTimeZoneError):
Template("{% load tz %}{% timezone tz %}{% endtimezone %}").render(Context({'tz': 'foobar'}))
@skipIf(sys.platform.startswith('win'), "Windows uses non-standard time zone names")
@@ -1006,7 +998,7 @@ class TemplateTests(SimpleTestCase):
"""
tpl = Template("{% load tz %}{% get_current_timezone as time_zone %}{{ time_zone }}")
- self.assertEqual(tpl.render(Context()), "Africa/Nairobi" if pytz else "EAT")
+ self.assertEqual(tpl.render(Context()), "Africa/Nairobi")
with timezone.override(UTC):
self.assertEqual(tpl.render(Context()), "UTC")
@@ -1019,7 +1011,6 @@ class TemplateTests(SimpleTestCase):
with timezone.override(UTC):
self.assertEqual(tpl.render(Context({'tz': ICT})), "+0700")
- @requires_pytz
def test_get_current_timezone_templatetag_with_pytz(self):
"""
Test the {% get_current_timezone %} templatetag with pytz.
@@ -1048,7 +1039,7 @@ class TemplateTests(SimpleTestCase):
context = Context()
self.assertEqual(tpl.render(context), "")
request_context = RequestContext(HttpRequest(), processors=[context_processors.tz])
- self.assertEqual(tpl.render(request_context), "Africa/Nairobi" if pytz else "EAT")
+ self.assertEqual(tpl.render(request_context), "Africa/Nairobi")
@requires_tz_support
def test_date_and_time_template_filters(self):
@@ -1068,15 +1059,6 @@ class TemplateTests(SimpleTestCase):
with timezone.override(ICT):
self.assertEqual(tpl.render(ctx), "2011-09-01 at 20:20:20")
- def test_localtime_with_time_zone_setting_set_to_none(self):
- # Regression for #17274
- tpl = Template("{% load tz %}{{ dt }}")
- ctx = Context({'dt': datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=EAT)})
-
- with self.settings(TIME_ZONE=None):
- # the actual value depends on the system time zone of the host
- self.assertTrue(tpl.render(ctx).startswith("2011"))
-
@requires_tz_support
def test_now_template_tag_uses_current_time_zone(self):
# Regression for #17343
@@ -1094,7 +1076,6 @@ class LegacyFormsTests(TestCase):
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 9, 1, 13, 20, 30))
- @requires_pytz
def test_form_with_non_existent_time(self):
form = EventForm({'dt': '2011-03-27 02:30:00'})
with timezone.override(pytz.timezone('Europe/Paris')):
@@ -1102,7 +1083,6 @@ class LegacyFormsTests(TestCase):
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 3, 27, 2, 30, 0))
- @requires_pytz
def test_form_with_ambiguous_time(self):
form = EventForm({'dt': '2011-10-30 02:30:00'})
with timezone.override(pytz.timezone('Europe/Paris')):
@@ -1141,7 +1121,6 @@ class NewFormsTests(TestCase):
# Datetime inputs formats don't allow providing a time zone.
self.assertFalse(form.is_valid())
- @requires_pytz
def test_form_with_non_existent_time(self):
with timezone.override(pytz.timezone('Europe/Paris')):
form = EventForm({'dt': '2011-03-27 02:30:00'})
@@ -1153,7 +1132,6 @@ class NewFormsTests(TestCase):
]
)
- @requires_pytz
def test_form_with_ambiguous_time(self):
with timezone.override(pytz.timezone('Europe/Paris')):
form = EventForm({'dt': '2011-10-30 02:30:00'})
diff --git a/tests/utils_tests/test_dateformat.py b/tests/utils_tests/test_dateformat.py
index bda69fb4cd..bd99b31a42 100644
--- a/tests/utils_tests/test_dateformat.py
+++ b/tests/utils_tests/test_dateformat.py
@@ -1,8 +1,6 @@
from __future__ import unicode_literals
-import sys
from datetime import date, datetime
-from unittest import skipIf
from django.test import SimpleTestCase, override_settings
from django.test.utils import TZ_SUPPORT, requires_tz_support
@@ -12,11 +10,6 @@ from django.utils.timezone import (
get_default_timezone, get_fixed_timezone, make_aware, utc,
)
-try:
- import pytz
-except ImportError:
- pytz = None
-
@override_settings(TIME_ZONE='Europe/Copenhagen')
class DateFormatTests(SimpleTestCase):
@@ -36,18 +29,16 @@ class DateFormatTests(SimpleTestCase):
dt = datetime(2009, 5, 16, 5, 30, 30)
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U'))), dt)
- @skipIf(sys.platform.startswith('win') and not pytz, "Test requires pytz on Windows")
def test_naive_ambiguous_datetime(self):
- # dt is ambiguous in Europe/Copenhagen. LocalTimezone guesses the
- # offset (and gets it wrong 50% of the time) while pytz refuses the
- # temptation to guess. In any case, this shouldn't crash.
+ # dt is ambiguous in Europe/Copenhagen. pytz raises an exception for
+ # the ambiguity, which results in an empty string.
dt = datetime(2015, 10, 25, 2, 30, 0)
# Try all formatters that involve self.timezone.
- self.assertEqual(format(dt, 'I'), '0' if pytz is None else '')
- self.assertEqual(format(dt, 'O'), '+0100' if pytz is None else '')
- self.assertEqual(format(dt, 'T'), 'CET' if pytz is None else '')
- self.assertEqual(format(dt, 'Z'), '3600' if pytz is None else '')
+ self.assertEqual(format(dt, 'I'), '')
+ self.assertEqual(format(dt, 'O'), '')
+ self.assertEqual(format(dt, 'T'), '')
+ self.assertEqual(format(dt, 'Z'), '')
@requires_tz_support
def test_datetime_with_local_tzinfo(self):
diff --git a/tests/utils_tests/test_timezone.py b/tests/utils_tests/test_timezone.py
index 1be1d63b2c..2fe5445c48 100644
--- a/tests/utils_tests/test_timezone.py
+++ b/tests/utils_tests/test_timezone.py
@@ -1,21 +1,12 @@
-import copy
import datetime
-import pickle
import sys
-import unittest
+
+import pytz
from django.test import SimpleTestCase, mock, override_settings
from django.utils import timezone
-try:
- import pytz
-except ImportError:
- pytz = None
-
-requires_pytz = unittest.skipIf(pytz is None, "this test requires pytz")
-
-if pytz is not None:
- CET = pytz.timezone("Europe/Paris")
+CET = pytz.timezone("Europe/Paris")
EAT = timezone.get_fixed_timezone(180) # Africa/Nairobi
ICT = timezone.get_fixed_timezone(420) # Asia/Bangkok
@@ -24,33 +15,6 @@ PY36 = sys.version_info >= (3, 6)
class TimezoneTests(SimpleTestCase):
- def test_localtime(self):
- now = datetime.datetime.utcnow().replace(tzinfo=timezone.utc)
- local_tz = timezone.LocalTimezone()
- with timezone.override(local_tz):
- local_now = timezone.localtime(now)
- self.assertEqual(local_now.tzinfo, local_tz)
- local_now = timezone.localtime(now, timezone=local_tz)
- self.assertEqual(local_now.tzinfo, local_tz)
-
- def test_localtime_naive(self):
- now = datetime.datetime.now()
- if PY36:
- self.assertEqual(timezone.localtime(now), now.replace(tzinfo=timezone.LocalTimezone()))
- else:
- with self.assertRaisesMessage(ValueError, 'astimezone() cannot be applied to a naive datetime'):
- timezone.localtime(now)
-
- def test_localtime_out_of_range(self):
- local_tz = timezone.LocalTimezone()
- long_ago = datetime.datetime(1900, 1, 1, tzinfo=timezone.utc)
- try:
- timezone.localtime(long_ago, local_tz)
- except (OverflowError, ValueError) as exc:
- self.assertIn("install pytz", exc.args[0])
- else:
- self.skipTest("Failed to trigger an OverflowError or ValueError")
-
def test_now(self):
with override_settings(USE_TZ=True):
self.assertTrue(timezone.is_aware(timezone.now()))
@@ -133,18 +97,6 @@ class TimezoneTests(SimpleTestCase):
finally:
timezone.deactivate()
- def test_copy(self):
- self.assertIsInstance(copy.copy(timezone.UTC()), timezone.UTC)
- self.assertIsInstance(copy.copy(timezone.LocalTimezone()), timezone.LocalTimezone)
-
- def test_deepcopy(self):
- self.assertIsInstance(copy.deepcopy(timezone.UTC()), timezone.UTC)
- self.assertIsInstance(copy.deepcopy(timezone.LocalTimezone()), timezone.LocalTimezone)
-
- def test_pickling_unpickling(self):
- self.assertIsInstance(pickle.loads(pickle.dumps(timezone.UTC())), timezone.UTC)
- self.assertIsInstance(pickle.loads(pickle.dumps(timezone.LocalTimezone())), timezone.LocalTimezone)
-
def test_is_aware(self):
self.assertTrue(timezone.is_aware(datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)))
self.assertFalse(timezone.is_aware(datetime.datetime(2011, 9, 1, 13, 20, 30)))
@@ -175,7 +127,6 @@ class TimezoneTests(SimpleTestCase):
with self.assertRaisesMessage(ValueError, 'astimezone() cannot be applied to a naive datetime'):
timezone.make_naive(*args)
- @requires_pytz
def test_make_aware2(self):
self.assertEqual(
timezone.make_aware(datetime.datetime(2011, 9, 1, 12, 20, 30), CET),
@@ -183,7 +134,6 @@ class TimezoneTests(SimpleTestCase):
with self.assertRaises(ValueError):
timezone.make_aware(CET.localize(datetime.datetime(2011, 9, 1, 12, 20, 30)), CET)
- @requires_pytz
def test_make_aware_pytz(self):
self.assertEqual(
timezone.make_naive(CET.localize(datetime.datetime(2011, 9, 1, 12, 20, 30)), CET),
@@ -202,7 +152,6 @@ class TimezoneTests(SimpleTestCase):
with self.assertRaises(ValueError):
timezone.make_naive(datetime.datetime(2011, 9, 1, 12, 20, 30), CET)
- @requires_pytz
def test_make_aware_pytz_ambiguous(self):
# 2:30 happens twice, once before DST ends and once after
ambiguous = datetime.datetime(2015, 10, 25, 2, 30)
@@ -216,7 +165,6 @@ class TimezoneTests(SimpleTestCase):
self.assertEqual(std.tzinfo.utcoffset(std), datetime.timedelta(hours=1))
self.assertEqual(dst.tzinfo.utcoffset(dst), datetime.timedelta(hours=2))
- @requires_pytz
def test_make_aware_pytz_non_existent(self):
# 2:30 never happened due to DST
non_existent = datetime.datetime(2015, 3, 29, 2, 30)
@@ -229,9 +177,3 @@ class TimezoneTests(SimpleTestCase):
self.assertEqual(std - dst, datetime.timedelta(hours=1))
self.assertEqual(std.tzinfo.utcoffset(std), datetime.timedelta(hours=1))
self.assertEqual(dst.tzinfo.utcoffset(dst), datetime.timedelta(hours=2))
-
- # round trip to UTC then back to CET
- std = timezone.localtime(timezone.localtime(std, timezone.UTC()), CET)
- dst = timezone.localtime(timezone.localtime(dst, timezone.UTC()), CET)
- self.assertEqual((std.hour, std.minute), (3, 30))
- self.assertEqual((dst.hour, dst.minute), (1, 30))