From 9a7f6d14a8445a72044f91ea05794414e281918d Mon Sep 17 00:00:00 2001 From: spacemanspiff2007 <10754716+spacemanspiff2007@users.noreply.github.com> Date: Thu, 10 Oct 2024 04:12:28 +0200 Subject: [PATCH] - Dev7: Fixed logical error for instantview --- requirements_setup.txt | 2 +- src/HABApp/__version__.py | 2 +- src/HABApp/core/lib/instant_view.py | 8 +++--- tests/test_core/test_lib/test_instant_view.py | 26 ++++++++++++------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/requirements_setup.txt b/requirements_setup.txt index c3e845e9..d05134d8 100644 --- a/requirements_setup.txt +++ b/requirements_setup.txt @@ -9,7 +9,7 @@ aiomqtt == 2.3.0 # eascheduler == git+https://github.com/spacemanspiff2007/eascheduler.git@rework -immutables == 0.20 +immutables == 0.21 easyconfig == 0.3.2 stack_data == 0.6.3 colorama == 0.4.6 diff --git a/src/HABApp/__version__.py b/src/HABApp/__version__.py index 690eff4d..a18e3708 100644 --- a/src/HABApp/__version__.py +++ b/src/HABApp/__version__.py @@ -10,4 +10,4 @@ # Development versions contain the DEV-COUNTER postfix: # - 24.01.0.DEV-1 -__version__ = '24.09.0.DEV-6' +__version__ = '24.09.0.DEV-7' diff --git a/src/HABApp/core/lib/instant_view.py b/src/HABApp/core/lib/instant_view.py index cd0cba24..95d09336 100644 --- a/src/HABApp/core/lib/instant_view.py +++ b/src/HABApp/core/lib/instant_view.py @@ -90,16 +90,16 @@ def newer_than(self, obj=None, **kwargs): return self._cmp(gt, obj, **kwargs) def __lt__(self, other: HINT_OBJ) -> bool: - return self._cmp(lt, other) + return self._cmp(gt, other) def __le__(self, other: HINT_OBJ) -> bool: - return self._cmp(le, other) + return self._cmp(ge, other) def __gt__(self, other: HINT_OBJ) -> bool: - return self._cmp(gt, other) + return self._cmp(lt, other) def __ge__(self, other: HINT_OBJ) -> bool: - return self._cmp(ge, other) + return self._cmp(le, other) def __eq__(self, other: InstantView | Instant) -> bool: if isinstance(other, InstantView): diff --git a/tests/test_core/test_lib/test_instant_view.py b/tests/test_core/test_lib/test_instant_view.py index 9c2f67cc..23d63c2f 100644 --- a/tests/test_core/test_lib/test_instant_view.py +++ b/tests/test_core/test_lib/test_instant_view.py @@ -17,25 +17,30 @@ def view(): def test_methods(view: InstantView): - assert view < seconds(1) - assert not view < seconds(60) - assert view <= seconds(60) - - assert view > seconds(61) + assert view > seconds(59) assert not view > seconds(60) assert view >= seconds(60) + assert view < seconds(61) + assert not view < seconds(60) + assert view <= seconds(60) + def test_cmp_obj(view: InstantView): - assert view < TimeDelta(seconds=59) - assert view < dt_timedelta(seconds=59) - assert view < 'PT59S' - assert view < 59 + assert view > TimeDelta(seconds=59) + assert view > dt_timedelta(seconds=59) + assert view > 'PT59S' + assert view > 59 def test_cmp_funcs(view: InstantView): assert view.older_than(seconds=59) + assert view > 59 + assert view >= 60 + assert view.newer_than(seconds=61) + assert view < 61 + assert view <= 60 def test_delta_funcs(view: InstantView): @@ -51,4 +56,5 @@ def test_convert(): def test_repr(): view = InstantView(SystemDateTime(2021, 1, 2, 10, 11, 12).instant()) - assert str(view) == 'InstantView(2021-01-02T10:11:12+01:00)' + # Cut the timezone away because we don't know where the test is running + assert str(view)[:-6] == 'InstantView(2021-01-02T10:11:12+'