Skip to content

Commit

Permalink
Fixed test that fails when pytz is installed.
Browse files Browse the repository at this point in the history
pytz' localize() method is the bane of my life.
  • Loading branch information
aaugustin committed Sep 10, 2013
1 parent b2b7634 commit 79ccd1a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/utils_tests/test_dateformat.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils.dateformat import format from django.utils.dateformat import format
from django.utils import dateformat 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 from django.utils import translation




Expand All @@ -34,16 +34,17 @@ def test_naive_datetime(self):


def test_datetime_with_local_tzinfo(self): def test_datetime_with_local_tzinfo(self):
ltz = get_default_timezone() 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')), ltz), dt)
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U'))), dt.replace(tzinfo=None)) self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U'))), dt.replace(tzinfo=None))


def test_datetime_with_tzinfo(self): def test_datetime_with_tzinfo(self):
tz = get_fixed_timezone(-510) tz = get_fixed_timezone(-510)
ltz = get_default_timezone() 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')), tz), dt)
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U')), ltz), 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'))), 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')), tz).utctimetuple(), dt.utctimetuple())
self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple(), dt.utctimetuple()) self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple(), dt.utctimetuple())
Expand Down

1 comment on commit 79ccd1a

@marfire
Copy link
Contributor

@marfire marfire commented on 79ccd1a Oct 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.