pytest-dsl 0.15.2__py3-none-any.whl → 0.15.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_dsl/core/validator.py +71 -1
- {pytest_dsl-0.15.2.dist-info → pytest_dsl-0.15.3.dist-info}/METADATA +1 -1
- {pytest_dsl-0.15.2.dist-info → pytest_dsl-0.15.3.dist-info}/RECORD +7 -7
- {pytest_dsl-0.15.2.dist-info → pytest_dsl-0.15.3.dist-info}/WHEEL +0 -0
- {pytest_dsl-0.15.2.dist-info → pytest_dsl-0.15.3.dist-info}/entry_points.txt +0 -0
- {pytest_dsl-0.15.2.dist-info → pytest_dsl-0.15.3.dist-info}/licenses/LICENSE +0 -0
- {pytest_dsl-0.15.2.dist-info → pytest_dsl-0.15.3.dist-info}/top_level.txt +0 -0
pytest_dsl/core/validator.py
CHANGED
@@ -47,6 +47,7 @@ class DSLValidator:
|
|
47
47
|
def __init__(self):
|
48
48
|
self.errors: List[DSLValidationError] = []
|
49
49
|
self.warnings: List[DSLValidationError] = []
|
50
|
+
self._temp_registered_keywords = [] # 记录临时注册的关键字,用于清理
|
50
51
|
|
51
52
|
def validate(self, content: str, dsl_id: Optional[str] = None
|
52
53
|
) -> Tuple[bool, List[DSLValidationError]]:
|
@@ -61,6 +62,7 @@ class DSLValidator:
|
|
61
62
|
"""
|
62
63
|
self.errors = []
|
63
64
|
self.warnings = []
|
65
|
+
self._temp_registered_keywords = []
|
64
66
|
|
65
67
|
# 基础验证
|
66
68
|
self._validate_basic_format(content)
|
@@ -68,8 +70,12 @@ class DSLValidator:
|
|
68
70
|
# 语法验证
|
69
71
|
ast = self._validate_syntax(content)
|
70
72
|
|
71
|
-
#
|
73
|
+
# 如果语法验证通过,进行预处理和语义验证
|
72
74
|
if ast and not self.errors:
|
75
|
+
# 预注册自定义关键字
|
76
|
+
self._preregister_custom_keywords(ast)
|
77
|
+
|
78
|
+
# 语义验证
|
73
79
|
self._validate_semantics(ast)
|
74
80
|
|
75
81
|
# 元数据验证
|
@@ -80,8 +86,72 @@ class DSLValidator:
|
|
80
86
|
if ast and not self.errors:
|
81
87
|
self._validate_keywords(ast)
|
82
88
|
|
89
|
+
# 清理临时注册的关键字
|
90
|
+
self._cleanup_temp_keywords()
|
91
|
+
|
83
92
|
return len(self.errors) == 0, self.errors + self.warnings
|
84
93
|
|
94
|
+
def _preregister_custom_keywords(self, ast: Node) -> None:
|
95
|
+
"""预注册AST中定义的自定义关键字
|
96
|
+
|
97
|
+
Args:
|
98
|
+
ast: 解析后的AST
|
99
|
+
"""
|
100
|
+
try:
|
101
|
+
from pytest_dsl.core.custom_keyword_manager import custom_keyword_manager
|
102
|
+
|
103
|
+
# 查找并注册自定义关键字
|
104
|
+
self._find_and_register_custom_keywords(ast)
|
105
|
+
|
106
|
+
except Exception as e:
|
107
|
+
# 如果预注册失败,记录警告但不影响验证流程
|
108
|
+
self.warnings.append(DSLValidationError(
|
109
|
+
"关键字预处理警告",
|
110
|
+
f"预注册自定义关键字时出现警告: {str(e)}"
|
111
|
+
))
|
112
|
+
|
113
|
+
def _find_and_register_custom_keywords(self, node: Node) -> None:
|
114
|
+
"""递归查找并注册自定义关键字
|
115
|
+
|
116
|
+
Args:
|
117
|
+
node: 当前节点
|
118
|
+
"""
|
119
|
+
# 检查当前节点是否是自定义关键字定义
|
120
|
+
if node.type in ['CustomKeyword', 'Function']:
|
121
|
+
try:
|
122
|
+
from pytest_dsl.core.custom_keyword_manager import custom_keyword_manager
|
123
|
+
|
124
|
+
# 注册自定义关键字
|
125
|
+
custom_keyword_manager._register_custom_keyword(
|
126
|
+
node, "validation_temp")
|
127
|
+
|
128
|
+
# 记录已注册的关键字名称,用于后续清理
|
129
|
+
keyword_name = node.value
|
130
|
+
self._temp_registered_keywords.append(keyword_name)
|
131
|
+
|
132
|
+
except Exception as e:
|
133
|
+
self.warnings.append(DSLValidationError(
|
134
|
+
"关键字注册警告",
|
135
|
+
f"注册自定义关键字 '{node.value}' 时出现警告: {str(e)}"
|
136
|
+
))
|
137
|
+
|
138
|
+
# 递归处理子节点
|
139
|
+
if hasattr(node, 'children') and node.children:
|
140
|
+
for child in node.children:
|
141
|
+
if isinstance(child, Node):
|
142
|
+
self._find_and_register_custom_keywords(child)
|
143
|
+
|
144
|
+
def _cleanup_temp_keywords(self) -> None:
|
145
|
+
"""清理临时注册的关键字"""
|
146
|
+
try:
|
147
|
+
for keyword_name in self._temp_registered_keywords:
|
148
|
+
# 从关键字管理器中移除临时注册的关键字
|
149
|
+
if keyword_name in keyword_manager._keywords:
|
150
|
+
del keyword_manager._keywords[keyword_name]
|
151
|
+
except Exception as e:
|
152
|
+
# 清理失败不影响验证结果,只记录警告
|
153
|
+
pass
|
154
|
+
|
85
155
|
def _validate_basic_format(self, content: str) -> None:
|
86
156
|
"""基础格式验证"""
|
87
157
|
if not content or not content.strip():
|
@@ -27,7 +27,7 @@ pytest_dsl/core/parser.py,sha256=SvTQ4jgMSe3MITSu9PftraElPAzVaBbNPHMEk1H_lFY,165
|
|
27
27
|
pytest_dsl/core/parsetab.py,sha256=o4XbFKwpsi3fYmfI_F6u5NSM61Qp6gTx-Sfh1jDINxI,31767
|
28
28
|
pytest_dsl/core/plugin_discovery.py,sha256=3pt3EXJ7EPF0rkUlyDZMVHkIiTy2vicdIIQJkrHXZjY,8305
|
29
29
|
pytest_dsl/core/utils.py,sha256=q0AMdw5HO33JvlA3UJeQ7IXh1Z_8K1QlwiM1_yiITrU,5350
|
30
|
-
pytest_dsl/core/validator.py,sha256=
|
30
|
+
pytest_dsl/core/validator.py,sha256=2mjw7yiDEMu80FjJ_y2KCS-vA1Tb4kotrKkmLwpRe8Y,17420
|
31
31
|
pytest_dsl/core/variable_utils.py,sha256=sx5DFZAO_syi0E_0ACisiZUQL9yxGeOfNmMtV6w9V3E,13947
|
32
32
|
pytest_dsl/core/yaml_loader.py,sha256=PC-R05bmHDI1QyBhhnt2jEK2c50Sg2xKsMDDY7p5rRg,8165
|
33
33
|
pytest_dsl/core/yaml_vars.py,sha256=PqbCGT_TmOXH09Pmm72sYtMEvV-sp9ocLqkuAUQYhhc,5047
|
@@ -73,9 +73,9 @@ pytest_dsl/remote/keyword_client.py,sha256=BL80MOaLroUi0v-9sLtkJ55g1R0Iw9SE1k11I
|
|
73
73
|
pytest_dsl/remote/keyword_server.py,sha256=vGIE3Bhh461xX_u1U-Cf5nrWL2GQFYdtQdcMWfFIYgE,22320
|
74
74
|
pytest_dsl/remote/variable_bridge.py,sha256=dv-d3Gq9ttvvrXM1fdlLtoSOPB6vRp0_GBOwX4wvcy8,7121
|
75
75
|
pytest_dsl/templates/keywords_report.html,sha256=7x84iq6hi08nf1iQ95jZ3izcAUPx6JFm0_8xS85CYws,31241
|
76
|
-
pytest_dsl-0.15.
|
77
|
-
pytest_dsl-0.15.
|
78
|
-
pytest_dsl-0.15.
|
79
|
-
pytest_dsl-0.15.
|
80
|
-
pytest_dsl-0.15.
|
81
|
-
pytest_dsl-0.15.
|
76
|
+
pytest_dsl-0.15.3.dist-info/licenses/LICENSE,sha256=Rguy8cb9sYhK6cmrBdXvwh94rKVDh2tVZEWptsHIsVM,1071
|
77
|
+
pytest_dsl-0.15.3.dist-info/METADATA,sha256=579CxhlZ843PKOTXZX93BkD_m85h36LCIthwXShHgcw,29655
|
78
|
+
pytest_dsl-0.15.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
79
|
+
pytest_dsl-0.15.3.dist-info/entry_points.txt,sha256=PLOBbH02OGY1XR1JDKIZB1Em87loUvbgMRWaag-5FhY,204
|
80
|
+
pytest_dsl-0.15.3.dist-info/top_level.txt,sha256=4CrSx4uNqxj7NvK6k1y2JZrSrJSzi-UvPZdqpUhumWM,11
|
81
|
+
pytest_dsl-0.15.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|