pytest-dsl 0.15.1__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/dsl_executor.py +595 -352
- pytest_dsl/core/parser.py +20 -2
- pytest_dsl/core/validator.py +71 -1
- {pytest_dsl-0.15.1.dist-info → pytest_dsl-0.15.3.dist-info}/METADATA +1 -1
- {pytest_dsl-0.15.1.dist-info → pytest_dsl-0.15.3.dist-info}/RECORD +9 -9
- {pytest_dsl-0.15.1.dist-info → pytest_dsl-0.15.3.dist-info}/WHEEL +0 -0
- {pytest_dsl-0.15.1.dist-info → pytest_dsl-0.15.3.dist-info}/entry_points.txt +0 -0
- {pytest_dsl-0.15.1.dist-info → pytest_dsl-0.15.3.dist-info}/licenses/LICENSE +0 -0
- {pytest_dsl-0.15.1.dist-info → pytest_dsl-0.15.3.dist-info}/top_level.txt +0 -0
pytest_dsl/core/parser.py
CHANGED
@@ -198,9 +198,27 @@ def p_expr_atom(p):
|
|
198
198
|
elif isinstance(p[1], Node):
|
199
199
|
p[0] = p[1]
|
200
200
|
else:
|
201
|
-
#
|
201
|
+
# 为基本表达式设置行号信息和类型信息
|
202
202
|
expr_line = getattr(p.slice[1], 'lineno', None)
|
203
|
-
|
203
|
+
|
204
|
+
# 根据token类型创建不同的节点类型
|
205
|
+
token_type = p.slice[1].type
|
206
|
+
if token_type == 'STRING':
|
207
|
+
# 字符串字面量
|
208
|
+
expr_node = Node('StringLiteral', value=p[1])
|
209
|
+
elif token_type == 'NUMBER':
|
210
|
+
# 数字字面量
|
211
|
+
expr_node = Node('NumberLiteral', value=p[1])
|
212
|
+
elif token_type == 'ID':
|
213
|
+
# 变量引用
|
214
|
+
expr_node = Node('VariableRef', value=p[1])
|
215
|
+
elif token_type == 'PLACEHOLDER':
|
216
|
+
# 变量占位符 ${var}
|
217
|
+
expr_node = Node('PlaceholderRef', value=p[1])
|
218
|
+
else:
|
219
|
+
# 其他类型,保持原来的行为
|
220
|
+
expr_node = Node('Expression', value=p[1])
|
221
|
+
|
204
222
|
if expr_line is not None:
|
205
223
|
expr_node.set_position(expr_line)
|
206
224
|
p[0] = expr_node
|
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():
|
@@ -9,7 +9,7 @@ pytest_dsl/core/auto_decorator.py,sha256=9Mga-GB4AzV5nkB6zpfaq8IuHa0KOH8LlFvnWyH
|
|
9
9
|
pytest_dsl/core/auto_directory.py,sha256=egyTnVxtGs4P75EIivRauLRPJfN9aZpoGVvp_Ma72AM,2714
|
10
10
|
pytest_dsl/core/context.py,sha256=fXpVQon666Lz_PCexjkWMBBr-Xcd1SkDMp2vHar6eIs,664
|
11
11
|
pytest_dsl/core/custom_keyword_manager.py,sha256=F9aSbth4x4-5nHb0N5uG04CpgwGnQv4RDGeRKR2WuIk,16001
|
12
|
-
pytest_dsl/core/dsl_executor.py,sha256=
|
12
|
+
pytest_dsl/core/dsl_executor.py,sha256=G3Ad97REt1jWwRvp7LS2Nq7zy3S2ZtYKlJeAJANDstI,60200
|
13
13
|
pytest_dsl/core/dsl_executor_utils.py,sha256=ZJLSYSsiKHqg53d3Bl--ZF8m9abd5kpqdevWl31KEZg,2276
|
14
14
|
pytest_dsl/core/execution_tracker.py,sha256=Pwcxraxt_xkOouq32KBqola-OVfnbaomCoMTyUIqoN4,9476
|
15
15
|
pytest_dsl/core/global_context.py,sha256=NcEcS2V61MT70tgAsGsFWQq0P3mKjtHQr1rgT3yTcyY,3535
|
@@ -23,11 +23,11 @@ pytest_dsl/core/keyword_loader.py,sha256=3GQ4w5Zf2XdkoJ85uYXh9YB93_8L8OAb7vvuKE3
|
|
23
23
|
pytest_dsl/core/keyword_manager.py,sha256=5WZWwlYk74kGHh1T6WjCuVd8eelq2-UEXvDIe4U7rEI,7730
|
24
24
|
pytest_dsl/core/keyword_utils.py,sha256=1zIKzbA8Lhifc97skzN4oJV-2Cljzf9aVSutwjU7LaA,19847
|
25
25
|
pytest_dsl/core/lexer.py,sha256=o_EJIadfhgyCImI73Y9ybqlBE9AisgA6nOhxpXNlaMw,4648
|
26
|
-
pytest_dsl/core/parser.py,sha256=
|
26
|
+
pytest_dsl/core/parser.py,sha256=SvTQ4jgMSe3MITSu9PftraElPAzVaBbNPHMEk1H_lFY,16597
|
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
|