Fix docstring for expect_response and rename the associated exception

This commit is contained in:
Szymon Borecki
2023-08-09 23:51:12 +02:00
parent 3259de2f25
commit e9fec48ede
3 changed files with 11 additions and 7 deletions
+1 -1
View File
@@ -217,7 +217,7 @@ class ChameleonCLI:
continue
# start process cmd
unit.on_exec(args_parse_result)
except (chameleon_cmd.NegativeResponseError, chameleon_cli_unit.ArgsParserError) as e:
except (chameleon_cmd.UnexpectedResponseError, chameleon_cli_unit.ArgsParserError) as e:
print(f"{colorama.Fore.RED}{str(e)}{colorama.Style.RESET_ALL}")
except Exception:
print(f"CLI exception: {colorama.Fore.RED}{traceback.format_exc()}{colorama.Style.RESET_ALL}")
+1 -1
View File
@@ -2,7 +2,7 @@ import enum
import chameleon_com
import chameleon_status
from chameleon_utils import NegativeResponseError, expect_response
from chameleon_utils import UnexpectedResponseError, expect_response
DATA_CMD_GET_APP_VERSION = 1000
DATA_CMD_CHANGE_MODE = 1001
+9 -5
View File
@@ -4,12 +4,16 @@ from typing import Union
import chameleon_status
class NegativeResponseError(Exception):
class UnexpectedResponseError(Exception):
"""
Not positive response
Unexpected response exception
"""
def expect_response(accepted_responses):
def expect_response(accepted_responses: Union[int, list[int]]):
"""
Decorator for wrapping a Chameleon CMD function to check its response
for expected return codes and throwing an exception otherwise
"""
if isinstance(accepted_responses, int):
accepted_responses = [accepted_responses]
@@ -20,9 +24,9 @@ def expect_response(accepted_responses):
if ret.status not in accepted_responses:
if ret.status in chameleon_status.Device and ret.status in chameleon_status.message:
raise NegativeResponseError(chameleon_status.message[ret.status])
raise UnexpectedResponseError(chameleon_status.message[ret.status])
else:
raise NegativeResponseError(f"Not positive response and unknown status {ret.status}")
raise UnexpectedResponseError(f"Unexpected response and unknown status {ret.status}")
return ret