Skip to content

Commit

Permalink
add ruff ignores to tests; delay datetime check in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sim0nx committed Aug 19, 2023
1 parent 1762cbf commit d2aaac8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import openhab.oauth2_helper

# ruff: noqa: S106

@pytest.fixture(scope='session')
def oh() -> 'openhab.OpenHAB':
Expand All @@ -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)
9 changes: 6 additions & 3 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import openhab

# ruff: noqa: S101, ANN201, T201


def test_fetch_all_items(oh: openhab.OpenHAB):
items = oh.fetch_all_items()
Expand All @@ -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')


Expand Down
8 changes: 5 additions & 3 deletions tests/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -17,15 +19,15 @@ 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')


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')
Expand Down

0 comments on commit d2aaac8

Please sign in to comment.