|
@@ -177,7 +177,12 @@ class test_make_aware:
|
|
class test_localize:
|
|
class test_localize:
|
|
|
|
|
|
def test_tz_without_normalize(self):
|
|
def test_tz_without_normalize(self):
|
|
- tz = tzinfo()
|
|
|
|
|
|
+ class tzz(tzinfo):
|
|
|
|
+
|
|
|
|
+ def utcoffset(self, dt):
|
|
|
|
+ return None # Mock no utcoffset specified
|
|
|
|
+
|
|
|
|
+ tz = tzz()
|
|
assert not hasattr(tz, 'normalize')
|
|
assert not hasattr(tz, 'normalize')
|
|
assert localize(make_aware(datetime.utcnow(), tz), tz)
|
|
assert localize(make_aware(datetime.utcnow(), tz), tz)
|
|
|
|
|
|
@@ -186,6 +191,9 @@ class test_localize:
|
|
class tzz(tzinfo):
|
|
class tzz(tzinfo):
|
|
raises = None
|
|
raises = None
|
|
|
|
|
|
|
|
+ def utcoffset(self, dt):
|
|
|
|
+ return None
|
|
|
|
+
|
|
def normalize(self, dt, **kwargs):
|
|
def normalize(self, dt, **kwargs):
|
|
self.normalized = True
|
|
self.normalized = True
|
|
if self.raises and kwargs and kwargs.get('is_dst') is None:
|
|
if self.raises and kwargs and kwargs.get('is_dst') is None:
|
|
@@ -209,6 +217,26 @@ class test_localize:
|
|
assert tz3.normalized
|
|
assert tz3.normalized
|
|
assert tz3.raised
|
|
assert tz3.raised
|
|
|
|
|
|
|
|
+ def test_localize_changes_utc_dt(self):
|
|
|
|
+ now_utc_time = datetime.now(tz=pytz.utc)
|
|
|
|
+ local_tz = pytz.timezone('US/Eastern')
|
|
|
|
+ localized_time = localize(now_utc_time, local_tz)
|
|
|
|
+ assert localized_time == now_utc_time
|
|
|
|
+
|
|
|
|
+ def test_localize_aware_dt_idempotent(self):
|
|
|
|
+ t = (2017, 4, 23, 21, 36, 59, 0)
|
|
|
|
+ local_zone = pytz.timezone('America/New_York')
|
|
|
|
+ local_time = datetime(*t)
|
|
|
|
+ local_time_aware = datetime(*t, tzinfo=local_zone)
|
|
|
|
+ alternate_zone = pytz.timezone('America/Detroit')
|
|
|
|
+ localized_time = localize(local_time_aware, alternate_zone)
|
|
|
|
+ assert localized_time == local_time_aware
|
|
|
|
+ assert local_zone.utcoffset(
|
|
|
|
+ local_time) == alternate_zone.utcoffset(local_time)
|
|
|
|
+ localized_utc_offset = localized_time.tzinfo.utcoffset(local_time)
|
|
|
|
+ assert localized_utc_offset == alternate_zone.utcoffset(local_time)
|
|
|
|
+ assert localized_utc_offset == local_zone.utcoffset(local_time)
|
|
|
|
+
|
|
|
|
|
|
@pytest.mark.parametrize('s,expected', [
|
|
@pytest.mark.parametrize('s,expected', [
|
|
(999, 999),
|
|
(999, 999),
|