-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1024 from ffe4/issue_926
Fix tz.gettz() not returning local time for empty string
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fixed tz.gettz() not returning local time when passed an empty string. | ||
Reported by @labrys (gh issues #925, #926). Fixed by @ffe4 (gh pr #1024) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from datetime import datetime, timedelta | ||
|
||
import pytest | ||
import six | ||
from hypothesis import assume, given | ||
from hypothesis import strategies as st | ||
|
||
from dateutil import tz as tz | ||
|
||
EPOCHALYPSE = datetime.fromtimestamp(2147483647) | ||
NEGATIVE_EPOCHALYPSE = datetime.fromtimestamp(0) - timedelta(seconds=2147483648) | ||
|
||
|
||
@pytest.mark.gettz | ||
@pytest.mark.parametrize("gettz_arg", [None, ""]) | ||
# TODO: Remove bounds when GH #590 is resolved | ||
@given( | ||
dt=st.datetimes( | ||
min_value=NEGATIVE_EPOCHALYPSE, max_value=EPOCHALYPSE, timezones=st.just(tz.UTC), | ||
) | ||
) | ||
def test_gettz_returns_local(gettz_arg, dt): | ||
act_tz = tz.gettz(gettz_arg) | ||
if isinstance(act_tz, tz.tzlocal): | ||
return | ||
|
||
dt_act = dt.astimezone(tz.gettz(gettz_arg)) | ||
if six.PY2: | ||
dt_exp = dt.astimezone(tz.tzlocal()) | ||
else: | ||
dt_exp = dt.astimezone() | ||
|
||
assert dt_act == dt_exp | ||
assert dt_act.tzname() == dt_exp.tzname() | ||
assert dt_act.utcoffset() == dt_exp.utcoffset() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters