Skip to content

Commit

Permalink
Merge pull request #10 from pganssle/add_unwrap_shim
Browse files Browse the repository at this point in the history
Add a method to unwrap shim classes
  • Loading branch information
pganssle committed Jun 15, 2020
2 parents d0dbeb6 + 7936bad commit ccbe3da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/pytz_deprecation_shim/_impl.py
Expand Up @@ -82,6 +82,21 @@ def __repr__(self):
repr(self._key),
)

def unwrap_shim(self):
"""Returns the underlying class that the shim is a wrapper for.
This is a shim-specific method equivalent to
:func:`pytz_deprecation_shim.helpers.upgrade_tzinfo`. It is provided as
a method to allow end-users to upgrade shim timezones without requiring
an explicit dependency on ``pytz_deprecation_shim``, e.g.:
.. code-block:: python
if getattr(tz, "unwrap_shim", None) is None:
tz = tz.unwrap_shim()
"""
return self._zone

@property
def zone(self):
warnings.warn(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_shims.py
Expand Up @@ -17,6 +17,7 @@
dt_strategy,
enfold,
get_fold,
offset_minute_strategy,
round_normalized,
valid_zone_strategy,
)
Expand Down Expand Up @@ -214,3 +215,17 @@ def test_folds_from_utc(key, dt_utc, expected_fold):

dt = dt_utc.astimezone(zone)
assert get_fold(dt) == expected_fold


@hypothesis.given(
shim_zone=hst.one_of(
[
valid_zone_strategy.map(pds.timezone),
offset_minute_strategy.map(pds.fixed_offset_timezone),
hst.just(pds.UTC),
]
)
)
def test_unwrap_shim(shim_zone):
"""Tests that .unwrap(_shim) always does the same as upgrade_tzinfo()."""
assert shim_zone.unwrap_shim() is pds.helpers.upgrade_tzinfo(shim_zone)

0 comments on commit ccbe3da

Please sign in to comment.