From d2aaac8d791338b90a87952365a9cd1af4871a9f Mon Sep 17 00:00:00 2001 From: Georges Toth Date: Sat, 19 Aug 2023 22:52:40 +0200 Subject: [PATCH] add ruff ignores to tests; delay datetime check in tests --- tests/conftest.py | 3 ++- tests/test_basic.py | 9 ++++++--- tests/test_oauth.py | 8 +++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 8e4405e..b11689c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ import openhab.oauth2_helper +# ruff: noqa: S106 @pytest.fixture(scope='session') def oh() -> 'openhab.OpenHAB': @@ -26,7 +27,7 @@ def oh_oauth2() -> 'openhab.OpenHAB': oauth2_config = {'client_id': r'http://127.0.0.1/auth', 'token_cache': str(pathlib.Path(__file__).resolve().parent.parent / '.oauth2_token_test'), - 'token': oauth2_token + 'token': oauth2_token, } return openhab.OpenHAB(url_rest, oauth2_config=oauth2_config) diff --git a/tests/test_basic.py b/tests/test_basic.py index b883436..a706efe 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -3,6 +3,8 @@ import openhab +# ruff: noqa: S101, ANN201, T201 + def test_fetch_all_items(oh: openhab.OpenHAB): items = oh.fetch_all_items() @@ -12,18 +14,19 @@ def test_fetch_all_items(oh: openhab.OpenHAB): def test_datetime_update(oh: openhab.OpenHAB): dt_obj = oh.get_item('TheDateTime') - dt_utc_now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc) + dt_utc_now = datetime.datetime.now(tz=datetime.timezone.utc) dt_obj.state = dt_utc_now - print(dt_obj.state) + time.sleep(0.5) assert dt_obj.state.isoformat(timespec='seconds') == dt_utc_now.isoformat(timespec='seconds') def test_datetime_command(oh: openhab.OpenHAB): dt_obj = oh.get_item('TheDateTime') - dt_utc_now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc) + dt_utc_now = datetime.datetime.now(tz=datetime.timezone.utc) dt_obj.command(dt_utc_now) + time.sleep(0.5) assert dt_obj.state.isoformat(timespec='seconds') == dt_utc_now.isoformat(timespec='seconds') diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 95ba466..37e91b8 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -6,7 +6,9 @@ import openhab.oauth2_helper -pytestmark = pytest.mark.skipif('CI' in os.environ, reason="oauth2 tests currently not working in github CI") +# ruff: noqa: S101, ANN201, T201 + +pytestmark = pytest.mark.skipif('CI' in os.environ, reason='oauth2 tests currently not working in github CI') def test_fetch_all_items(oh_oauth2: openhab.OpenHAB): @@ -17,7 +19,7 @@ def test_fetch_all_items(oh_oauth2: openhab.OpenHAB): def test_datetime_update(oh_oauth2: openhab.OpenHAB): dt_obj = oh_oauth2.get_item('TheDateTime') - dt_utc_now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc) + dt_utc_now = datetime.datetime.now(tz=datetime.timezone.utc) dt_obj.state = dt_utc_now assert dt_obj.state.isoformat(timespec='seconds') == dt_utc_now.isoformat(timespec='seconds') @@ -25,7 +27,7 @@ def test_datetime_update(oh_oauth2: openhab.OpenHAB): def test_datetime_command(oh_oauth2: openhab.OpenHAB): dt_obj = oh_oauth2.get_item('TheDateTime') - dt_utc_now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc) + dt_utc_now = datetime.datetime.now(tz=datetime.timezone.utc) dt_obj.command(dt_utc_now) assert dt_obj.state.isoformat(timespec='seconds') == dt_utc_now.isoformat(timespec='seconds')