diff options
author | nico <nico@magicbroccoli.de> | 2019-12-12 23:20:59 +0100 |
---|---|---|
committer | nico <nico@magicbroccoli.de> | 2019-12-12 23:20:59 +0100 |
commit | 6f19f160ef0d2d72c1db35abcf03ee28a3982d7c (patch) | |
tree | 6f30c630da4cf6c59198d9621fa0303b6b92e2a0 | |
parent | cb84351270041449ee8a8984758e7e3ef86ea590 (diff) |
code fixup
+ add contextlib.suppress to further improve readability
- remove unnecessary return from if clause
* added back else case
-rw-r--r-- | TSGroupAssigner/group_assign.py | 19 | ||||
-rw-r--r-- | tests/test_group_assign.py | 5 |
2 files changed, 10 insertions, 14 deletions
diff --git a/TSGroupAssigner/group_assign.py b/TSGroupAssigner/group_assign.py index f933129..9f43d35 100644 --- a/TSGroupAssigner/group_assign.py +++ b/TSGroupAssigner/group_assign.py @@ -4,6 +4,7 @@ import datetime as dt import logging import sys import time +from contextlib import suppress import ts3 @@ -97,7 +98,6 @@ class GroupAssigner: # start date already reached proceed if self.startdate <= now: logging.debug('start date is already reached -- not eligible to sleepstart continue') - return # if startdate within the next 24h proceed to sleepstart elif now >= self.startdate - dt.timedelta(days=1): @@ -110,8 +110,9 @@ class GroupAssigner: logging.debug('target date will be reached in {sec} seconds -- sleeping'.format(sec=remaindelta.seconds)) time.sleep(remaindelta.seconds + 1) - # if the date is too far back raise DateException - raise DateException('target date is too far in the future') + else: + # if the date is too far back raise DateException + raise DateException('target date is too far in the future') def __notifycliententerview(self, data: dict): # return all non voice clients without reasonid 0 @@ -177,14 +178,10 @@ class GroupAssigner: while True: self.conn.send_keepalive() - try: - # wait for an event to be thrown + # suppress TimeoutError exceptions + with suppress(ts3.query.TS3TimeoutError): + # wait for events event = self.conn.wait_for_event(timeout=60) - # process TeamSpeak Telnet timeout - except ts3.query.TS3TimeoutError: - pass - - else: - # handle incoming events + # handover event to eventhandler self.__eventhandler(event.event, event.parsed[0]) diff --git a/tests/test_group_assign.py b/tests/test_group_assign.py index 1f86574..c3529a0 100644 --- a/tests/test_group_assign.py +++ b/tests/test_group_assign.py @@ -19,9 +19,8 @@ creds = { class TestGroupAssigner: def test_missing_input(self): - """ - this should fail due to missing arguments - """ + # the main class is missing arguments and should fail with a TypeError + with pytest.raises(TypeError): GroupAssigner().start() |