| 63 | |
| 64 | |
| 65 | class ScriptProcess: |
| 66 | ACTIONS = get_dict(Action) |
| 67 | CONDITIONS = get_dict(Condition) |
| 68 | __POP_KEY = {"method", "next", "if", "check", "condition", "loop", "return_flag", "while", "fail_script"} |
| 69 | |
| 70 | @staticmethod |
| 71 | @check |
| 72 | def __condition_check(temp_condition: dict, name: str, pre_deep: str, current_deep: int, |
| 73 | return_record: dict) -> None: |
| 74 | condition = temp_condition.get("condition") |
| 75 | temp_args = {"driver": None} |
| 76 | if not condition: |
| 77 | msg = "(Deep %s) condition of '%s' is missing" % (pre_deep + str(current_deep), name) |
| 78 | raise ScriptSyntaxError(ParamTypeError(msg), "", pre_deep + str(current_deep)) |
| 79 | if not isinstance(condition, str): |
| 80 | msg = "(Deep %s) The value of condition must be type of str" % (pre_deep + str(current_deep)) |
| 81 | raise ScriptSyntaxError(ParamTypeError(msg), "", pre_deep + str(current_deep)) |
| 82 | if condition.startswith("__not-") and condition.endswith("__"): |
| 83 | condition = condition[6: -2] |
| 84 | if condition not in ScriptProcess.CONDITIONS.keys(): |
| 85 | msg = "(Deep %s) Could not found the Condition Method in '%s'" % (pre_deep + str(current_deep), name) |
| 86 | raise ScriptSyntaxError(ParamTypeError(msg), condition, pre_deep + str(current_deep)) |
| 87 | fail_script = temp_condition.get("fail_script") |
| 88 | if fail_script: |
| 89 | ScriptProcess.syntax_check(script=fail_script, |
| 90 | pre_deep=pre_deep + str(current_deep) + "->", |
| 91 | return_record=return_record) |
| 92 | return_flag = temp_condition.get("return_flag") |
| 93 | if return_flag and not isinstance(return_flag, str): |
| 94 | msg = "(Deep %s) return_flag must be the type of str" % (pre_deep + str(current_deep)) |
| 95 | raise ScriptSyntaxError(ParamTypeError(msg), condition, pre_deep + str(current_deep)) |
| 96 | for key, value in temp_condition.items(): |
| 97 | if key.lower() not in ScriptProcess.__POP_KEY: |
| 98 | temp_args[key] = value |
| 99 | if "store" in signature(ScriptProcess.CONDITIONS[condition]).parameters: |
| 100 | temp_args["store"] = None |
| 101 | if return_record: |
| 102 | for key, value in temp_args.items(): |
| 103 | if isinstance(value, str) and value.startswith("__rf-") and value.endswith("__"): |
| 104 | if value[5:-2] not in return_record.keys(): |
| 105 | msg = f"The return_flag:{value[5:-2]} cannot be find in history record." |
| 106 | raise ScriptSyntaxError(ParamTypeError(msg), condition, pre_deep + str(current_deep)) |
| 107 | annotation = signature(ScriptProcess.CONDITIONS[condition]).parameters[key].annotation |
| 108 | pre_return_flag = return_record[value[5:-2]] |
| 109 | if pre_return_flag is Any or annotation is Any: |
| 110 | continue |
| 111 | if pre_return_flag != annotation: |
| 112 | msg = f"The return_flag is {pre_return_flag}, But parameter {key} is {annotation}." |
| 113 | raise ScriptSyntaxError(ParamTypeError(msg), condition, pre_deep + str(current_deep)) |
| 114 | try: |
| 115 | if return_flag: |
| 116 | return_record[return_flag] = signature(ScriptProcess.CONDITIONS[condition]).return_annotation |
| 117 | ScriptProcess.CONDITIONS[condition](**temp_args) |
| 118 | except TypeError as e: |
| 119 | raise ScriptSyntaxError(e, condition, pre_deep + str(current_deep)) |
| 120 | except AssertionError as e: |
| 121 | raise ScriptSyntaxError(e, condition, pre_deep + str(current_deep)) |
| 122 | except ParamTypeError as e: |
nothing calls this directly
no test coverage detected