1.1.0版本
This commit is contained in:
3
UniTAP/dev/modules/opf/handlers/__init__.py
Normal file
3
UniTAP/dev/modules/opf/handlers/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .base import OPFDialogAnswer, OpfHandlerBase
|
||||
from .default import OpfHandlerDefault
|
||||
from .internal import OpfHandlerInternal
|
||||
51
UniTAP/dev/modules/opf/handlers/base.py
Normal file
51
UniTAP/dev/modules/opf/handlers/base.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import abc
|
||||
from typing import Callable
|
||||
from enum import IntEnum
|
||||
|
||||
from .opf_functions import OPFFunctions, logging, OPFDialogAnswer
|
||||
from UniTAP.dev.modules.opf.parsers import OPFParametersParser
|
||||
|
||||
|
||||
class WrongOPFFunctionSignature(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class OpfHandlerBase:
|
||||
"""
|
||||
Class `OpfHandlerBase` allows working with functions that helps to do required actions during DUT tests.
|
||||
- Use DSC content library `set_dsc_content_library`. If DSC image does not exist, it will be generated.
|
||||
"""
|
||||
__FUNCTIONS_MAP = {
|
||||
19: OPFFunctions.opf_19_handler,
|
||||
103: OPFFunctions.opf_103_handler,
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.__parser = OPFParametersParser()
|
||||
self.__tx = None
|
||||
self.__rx = None
|
||||
self.__callback_before_handling = {}
|
||||
self._dsc_content_library_path = ""
|
||||
|
||||
def _set_roles(self, role_tx, role_rx):
|
||||
self.__tx = role_tx
|
||||
self.__rx = role_rx
|
||||
|
||||
def set_dsc_content_library(self, dsc_content_library_path: str = ""):
|
||||
"""
|
||||
Set new path to DSC content library folder.
|
||||
If path is empty, content library will not use (all images will be generated into OPF functions without saving).
|
||||
|
||||
Arguments:
|
||||
dsc_content_library_path (`str`) - full path to DSC content library folder.
|
||||
"""
|
||||
self._dsc_content_library_path = dsc_content_library_path
|
||||
|
||||
def handle(self, opf_id, reply_answer, *args) -> OPFDialogAnswer:
|
||||
opf_params = self.__parser.parse(opf_id, *args)
|
||||
|
||||
OPFFunctions.dsc_content_library_path = self._dsc_content_library_path
|
||||
return reply_answer(self.__FUNCTIONS_MAP.get(opf_id)(self.__tx, self.__rx, *opf_params))
|
||||
|
||||
def _is_opf_processed(self, opf_id: int):
|
||||
return self.__FUNCTIONS_MAP.get(opf_id) is not None
|
||||
46
UniTAP/dev/modules/opf/handlers/default.py
Normal file
46
UniTAP/dev/modules/opf/handlers/default.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import inspect
|
||||
import warnings
|
||||
from typing import Callable
|
||||
|
||||
from UniTAP.dev.modules.opf.handlers.base import OpfHandlerBase, OPFDialogAnswer,\
|
||||
WrongOPFFunctionSignature
|
||||
from UniTAP.dev.modules.opf.parsers import OPFParametersParser
|
||||
|
||||
|
||||
class OpfHandlerDefault(OpfHandlerBase):
|
||||
"""
|
||||
Class `OpfHandlerDefault` inherit functionality from `OpfHandlerBase` and allows overriding opf functions.
|
||||
Function `assign_function_for_opf_id` allows doing it.
|
||||
"""
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.__user_callback_dict = {}
|
||||
self.__parser = OPFParametersParser()
|
||||
|
||||
def handle(self, opf_id, reply_answer, *args) -> OPFDialogAnswer:
|
||||
base_opf_handler = super()._is_opf_processed(opf_id)
|
||||
user_opf_handler = self.__user_callback_dict.get(opf_id, None) is not None
|
||||
if not user_opf_handler and not base_opf_handler:
|
||||
warnings.warn(f"Test requested operator feedback dialog with id: {opf_id}, but user "
|
||||
f"function was not provided. Test will be aborted.")
|
||||
return reply_answer(OPFDialogAnswer.ABORT)
|
||||
|
||||
if user_opf_handler:
|
||||
opf_params_for_user = self.__parser.parse(opf_id, *args)
|
||||
return reply_answer(self.__user_callback_dict.get(opf_id, None)(*opf_params_for_user))
|
||||
else:
|
||||
return super().handle(opf_id, reply_answer, *args)
|
||||
|
||||
def assign_function_for_opf_id(self, opf_id: int, func: Callable):
|
||||
"""
|
||||
Assign new function for doing required actions from OPF.
|
||||
|
||||
Arguments:
|
||||
opf_id (`int`) - id of OPF.
|
||||
func (`Callable`) - object of function
|
||||
"""
|
||||
signature = inspect.getfullargspec(func)
|
||||
if signature.annotations['return'] != OPFDialogAnswer:
|
||||
raise WrongOPFFunctionSignature(f"Function MUST declare {OPFDialogAnswer} "
|
||||
f"as return value")
|
||||
self.__user_callback_dict[opf_id] = func
|
||||
110
UniTAP/dev/modules/opf/handlers/internal.py
Normal file
110
UniTAP/dev/modules/opf/handlers/internal.py
Normal file
@@ -0,0 +1,110 @@
|
||||
import inspect
|
||||
from typing import Callable
|
||||
|
||||
from UniTAP.dev.modules.opf.handlers.base import OpfHandlerBase, WrongOPFFunctionSignature
|
||||
from UniTAP.dev.modules.opf.parsers import OPFParametersParser
|
||||
from .opf_functions import *
|
||||
|
||||
|
||||
class OpfHandlerInternal(OpfHandlerBase):
|
||||
|
||||
__FUNCTIONS_MAP = {
|
||||
1: OPFFunctions.opf_1_handler,
|
||||
2: OPFFunctions.opf_2_handler,
|
||||
3: OPFFunctions.opf_3_handler,
|
||||
4: OPFFunctions.opf_4_handler,
|
||||
5: OPFFunctions.opf_5_handler,
|
||||
6: OPFFunctions.opf_6_handler,
|
||||
7: OPFFunctions.opf_7_handler,
|
||||
8: OPFFunctions.opf_8_handler,
|
||||
9: OPFFunctions.opf_9_handler,
|
||||
10: OPFFunctions.opf_10_handler,
|
||||
11: OPFFunctions.opf_11_handler,
|
||||
12: OPFFunctions.opf_12_handler,
|
||||
13: OPFFunctions.opf_13_handler,
|
||||
14: OPFFunctions.opf_14_handler,
|
||||
15: OPFFunctions.opf_15_handler,
|
||||
16: OPFFunctions.opf_16_handler,
|
||||
17: OPFFunctions.opf_17_handler,
|
||||
18: OPFFunctions.opf_18_handler,
|
||||
19: OPFFunctions.opf_19_handler,
|
||||
20: OPFFunctions.opf_20_handler,
|
||||
21: OPFFunctions.opf_21_handler,
|
||||
101: OPFFunctions.opf_101_handler,
|
||||
102: OPFFunctions.opf_102_handler,
|
||||
103: OPFFunctions.opf_103_handler,
|
||||
104: OPFFunctions.opf_104_handler,
|
||||
105: OPFFunctions.opf_105_handler,
|
||||
106: OPFFunctions.opf_106_handler,
|
||||
107: OPFFunctions.opf_107_handler,
|
||||
120: OPFFunctions.opf_120_handler,
|
||||
121: OPFFunctions.opf_121_handler,
|
||||
122: OPFFunctions.opf_122_handler,
|
||||
123: OPFFunctions.opf_123_handler,
|
||||
140: OPFFunctions.opf_140_handler,
|
||||
141: OPFFunctions.opf_141_handler,
|
||||
142: OPFFunctions.opf_142_handler,
|
||||
143: OPFFunctions.opf_143_handler,
|
||||
144: OPFFunctions.opf_144_handler,
|
||||
145: OPFFunctions.opf_145_handler,
|
||||
150: OPFFunctions.opf_150_handler,
|
||||
161: OPFFunctions.opf_161_handler
|
||||
}
|
||||
|
||||
__FUNCTIONS_MAP_AFTER = {
|
||||
1: OPFFunctions.opf_1_after_handler
|
||||
}
|
||||
|
||||
def __init__(self, port_tx, port_rx):
|
||||
super().__init__()
|
||||
self.__parser = OPFParametersParser()
|
||||
self.__tx = port_tx
|
||||
self.__rx = port_rx
|
||||
self.__callback_before_handling = {}
|
||||
self.__callback_after_handling = {}
|
||||
|
||||
def handle(self, opf_id, reply_answer, *args) -> OPFDialogAnswer:
|
||||
opf_params = self.__parser.parse(opf_id, *args)
|
||||
user_opf_before_callback = self.__callback_before_handling.get(opf_id, None)
|
||||
user_opf_after_callback = self.__callback_after_handling.get(opf_id, None)
|
||||
internal_opf_after_callback = self.__FUNCTIONS_MAP_AFTER.get(opf_id, None)
|
||||
|
||||
#
|
||||
# Callback before main callback
|
||||
#
|
||||
if user_opf_before_callback is not None:
|
||||
opf_before_result = user_opf_before_callback(*opf_params)
|
||||
# Interrupt OPF in case of fail "before" OPF
|
||||
if opf_before_result not in [OPFDialogAnswer.PASS, OPFDialogAnswer.PROCEED]:
|
||||
return reply_answer(opf_before_result)
|
||||
|
||||
#
|
||||
# Main callback
|
||||
#
|
||||
OPFFunctions.dsc_content_library_path = self._dsc_content_library_path
|
||||
opf_internal_result = self.__FUNCTIONS_MAP.get(opf_id)(self.__tx, self.__rx, *opf_params)
|
||||
reply_answer(opf_internal_result)
|
||||
|
||||
#
|
||||
# Callback after main callback
|
||||
#
|
||||
if user_opf_after_callback is not None:
|
||||
user_opf_after_callback(*opf_params)
|
||||
elif internal_opf_after_callback is not None:
|
||||
internal_opf_after_callback(self.__tx, self.__rx, *opf_params)
|
||||
|
||||
return opf_internal_result
|
||||
|
||||
def assign_function_before_handling_opf_id(self, opf_id: int, func: Callable):
|
||||
signature = inspect.getfullargspec(func)
|
||||
if signature.annotations['return'] != OPFDialogAnswer:
|
||||
raise WrongOPFFunctionSignature(f"Function MUST declare {OPFDialogAnswer} "
|
||||
f"as return value")
|
||||
self.__callback_before_handling[opf_id] = func
|
||||
|
||||
def assign_function_after_handling_opf_id(self, opf_id: int, func: Callable):
|
||||
signature = inspect.getfullargspec(func)
|
||||
if signature.annotations['return'] != OPFDialogAnswer:
|
||||
raise WrongOPFFunctionSignature(f"Function MUST declare {OPFDialogAnswer} "
|
||||
f"as return value")
|
||||
self.__callback_after_handling[opf_id] = func
|
||||
1390
UniTAP/dev/modules/opf/handlers/opf_functions.py
Normal file
1390
UniTAP/dev/modules/opf/handlers/opf_functions.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user