Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed test that fails when pytz is installed.

pytz' localize() method is the bane of my life.
  • Loading branch information...
commit 79ccd1a101e6379c5a49da18fc006816e5ed127c 1 parent b2b7634
@aaugustin aaugustin authored
Showing with 4 additions and 3 deletions.
  1. +4 −3 tests/utils_tests/test_dateformat.py
View
7 tests/utils_tests/test_dateformat.py
@@ -7,7 +7,7 @@
from django.test.utils import override_settings
from django.utils.dateformat import format
from django.utils import dateformat
-from django.utils.timezone import utc, get_fixed_timezone, get_default_timezone
+from django.utils.timezone import utc, get_fixed_timezone, get_default_timezone, make_aware
from django.utils import translation
@@ -34,16 +34,17 @@ def test_naive_datetime(self):
def test_datetime_with_local_tzinfo(self):
ltz = get_default_timezone()
- dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=ltz)
+ dt = make_aware(datetime(2009, 5, 16, 5, 30, 30), ltz)
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U')), ltz), dt)
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U'))), dt.replace(tzinfo=None))
def test_datetime_with_tzinfo(self):
tz = get_fixed_timezone(-510)
ltz = get_default_timezone()
- dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=tz)
+ dt = make_aware(datetime(2009, 5, 16, 5, 30, 30), ltz)
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U')), tz), dt)
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U')), ltz), dt)
+ # astimezone() is safe here because the target timezone doesn't have DST
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U'))), dt.astimezone(ltz).replace(tzinfo=None))
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U')), tz).utctimetuple(), dt.utctimetuple())
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple(), dt.utctimetuple())

1 comment on commit 79ccd1a

@marfire

@aaugustin I'm still seeing failures in Windows (https://code.djangoproject.com/ticket/21165#comment:9). Is it just me?

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