Skip to content

Commit

Permalink
zoneinfo module only arrived in Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
cjw296 committed Mar 1, 2024
1 parent 839c94d commit ebf80f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions docs/comparing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Comparing objects and sequences

.. currentmodule:: testfixtures

.. invisible-code-block: python

from testfixtures.compat import PY_39_PLUS, PY_312_PLUS

The helpers here provide ways of making assertions about object equality
even when those objects don't natively support comparison. Where differences
are found, feedback is provided in a way that makes it quick and easy to see what the
Expand Down Expand Up @@ -253,6 +257,8 @@ following:
datetimes and times
~~~~~~~~~~~~~~~~~~~

.. skip: start if(not PY_39_PLUS, reason="zoneinfo arrived in 3.9")

Given the following two :class:`~datetime.datetime` objects:

>>> from datetime import datetime
Expand Down Expand Up @@ -282,6 +288,8 @@ Traceback (most recent call last):
...
AssertionError: datetime.datetime(2024, 10, 27, 1, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/London')) != datetime.datetime(2024, 10, 27, 1, 0, fold=1, tzinfo=zoneinfo.ZoneInfo(key='Europe/London'))

.. skip: end

This problem can also be seen with :class:`~datetime.time` objects, where given
the following two times:

Expand Down Expand Up @@ -836,10 +844,6 @@ When comparing mappings such as :class:`dict` and :class:`~collections.OrderedDi
you may need to check the order of the keys is as you expect.
:class:`MappingComparison` objects can be used for this:

.. invisible-code-block: python

from testfixtures.compat import PY_312_PLUS

.. skip: start if(not PY_312_PLUS, reason="Python 3.12 has nicer reprs")

>>> from collections import OrderedDict
Expand Down
1 change: 1 addition & 0 deletions testfixtures/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

PY_VERSION: Tuple[int, int] = sys.version_info[:2]

PY_39_PLUS: bool = PY_VERSION >= (3, 9)
PY_310_PLUS: bool = PY_VERSION >= (3, 10)
PY_311_PLUS: bool = PY_VERSION >= (3, 11)
PY_312_PLUS: bool = PY_VERSION >= (3, 12)

0 comments on commit ebf80f0

Please sign in to comment.