From ebf80f0b859ad2cc13ef6d5d2fa2265edbb5682a Mon Sep 17 00:00:00 2001 From: Chris Withers Date: Fri, 1 Mar 2024 06:53:54 +0000 Subject: [PATCH] zoneinfo module only arrived in Python 3.9 --- docs/comparing.txt | 12 ++++++++---- testfixtures/compat.py | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/comparing.txt b/docs/comparing.txt index 63d8d30..a6fbe3b 100644 --- a/docs/comparing.txt +++ b/docs/comparing.txt @@ -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 @@ -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 @@ -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: @@ -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 diff --git a/testfixtures/compat.py b/testfixtures/compat.py index 82efc09..0ec7cb4 100644 --- a/testfixtures/compat.py +++ b/testfixtures/compat.py @@ -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)