pytest-dsl 0.3.0__py3-none-any.whl → 0.3.1__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/cli.py CHANGED
@@ -7,12 +7,14 @@ pytest-dsl命令行入口
7
7
  import sys
8
8
  import argparse
9
9
  import pytest
10
+ import os
10
11
  from pathlib import Path
11
12
 
12
13
  from pytest_dsl.core.lexer import get_lexer
13
14
  from pytest_dsl.core.parser import get_parser
14
15
  from pytest_dsl.core.dsl_executor import DSLExecutor
15
16
  from pytest_dsl.core.yaml_vars import yaml_vars
17
+ from pytest_dsl.core.auto_directory import SETUP_FILE_NAME, TEARDOWN_FILE_NAME, execute_hook_file
16
18
 
17
19
 
18
20
  def read_file(filename):
@@ -24,7 +26,7 @@ def read_file(filename):
24
26
  def parse_args():
25
27
  """解析命令行参数"""
26
28
  parser = argparse.ArgumentParser(description='执行DSL测试文件')
27
- parser.add_argument('dsl_file', help='要执行的DSL文件路径')
29
+ parser.add_argument('path', help='要执行的DSL文件路径或包含DSL文件的目录')
28
30
  parser.add_argument('--yaml-vars', action='append', default=[],
29
31
  help='YAML变量文件路径,可以指定多个文件 (例如: --yaml-vars vars1.yaml --yaml-vars vars2.yaml)')
30
32
  parser.add_argument('--yaml-vars-dir', default=None,
@@ -56,9 +58,33 @@ def load_yaml_variables(args):
56
58
  sys.exit(1)
57
59
 
58
60
 
61
+ def execute_dsl_file(file_path, lexer, parser, executor):
62
+ """执行单个DSL文件"""
63
+ try:
64
+ print(f"执行文件: {file_path}")
65
+ dsl_code = read_file(file_path)
66
+ ast = parser.parse(dsl_code, lexer=lexer)
67
+ executor.execute(ast)
68
+ return True
69
+ except Exception as e:
70
+ print(f"执行失败 {file_path}: {e}")
71
+ return False
72
+
73
+
74
+ def find_dsl_files(directory):
75
+ """查找目录中的所有DSL文件"""
76
+ dsl_files = []
77
+ for root, _, files in os.walk(directory):
78
+ for file in files:
79
+ if file.endswith(('.dsl', '.auto')) and file not in [SETUP_FILE_NAME, TEARDOWN_FILE_NAME]:
80
+ dsl_files.append(os.path.join(root, file))
81
+ return dsl_files
82
+
83
+
59
84
  def main():
60
85
  """命令行入口点"""
61
86
  args = parse_args()
87
+ path = args.path
62
88
 
63
89
  # 加载YAML变量
64
90
  load_yaml_variables(args)
@@ -67,14 +93,51 @@ def main():
67
93
  parser = get_parser()
68
94
  executor = DSLExecutor()
69
95
 
70
- try:
71
- dsl_code = read_file(args.dsl_file)
72
- ast = parser.parse(dsl_code, lexer=lexer)
73
- executor.execute(ast)
74
- except Exception as e:
75
- print(f"执行失败: {e}")
96
+ # 检查路径是文件还是目录
97
+ if os.path.isfile(path):
98
+ # 执行单个文件
99
+ success = execute_dsl_file(path, lexer, parser, executor)
100
+ if not success:
101
+ sys.exit(1)
102
+ elif os.path.isdir(path):
103
+ # 执行目录中的所有DSL文件
104
+ print(f"执行目录: {path}")
105
+
106
+ # 先执行目录的setup文件(如果存在)
107
+ setup_file = os.path.join(path, SETUP_FILE_NAME)
108
+ if os.path.exists(setup_file):
109
+ execute_hook_file(Path(setup_file), True, path)
110
+
111
+ # 查找并执行所有DSL文件
112
+ dsl_files = find_dsl_files(path)
113
+ if not dsl_files:
114
+ print(f"目录中没有找到DSL文件: {path}")
115
+ sys.exit(1)
116
+
117
+ print(f"找到 {len(dsl_files)} 个DSL文件")
118
+
119
+ # 执行所有DSL文件
120
+ failures = 0
121
+ for file_path in dsl_files:
122
+ success = execute_dsl_file(file_path, lexer, parser, executor)
123
+ if not success:
124
+ failures += 1
125
+
126
+ # 最后执行目录的teardown文件(如果存在)
127
+ teardown_file = os.path.join(path, TEARDOWN_FILE_NAME)
128
+ if os.path.exists(teardown_file):
129
+ execute_hook_file(Path(teardown_file), False, path)
130
+
131
+ # 如果有失败的测试,返回非零退出码
132
+ if failures > 0:
133
+ print(f"总计 {failures}/{len(dsl_files)} 个测试失败")
134
+ sys.exit(1)
135
+ else:
136
+ print(f"所有 {len(dsl_files)} 个测试成功完成")
137
+ else:
138
+ print(f"路径不存在: {path}")
76
139
  sys.exit(1)
77
140
 
78
141
 
79
142
  if __name__ == '__main__':
80
- main()
143
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-dsl
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: A DSL testing framework based on pytest
5
5
  Author: Chen Shuanglin
6
6
  License: MIT
@@ -1,5 +1,5 @@
1
1
  pytest_dsl/__init__.py,sha256=FzwXGvmuvMhRBKxvCdh1h-yJ2wUOnDxcTbU4Nt5fHn8,301
2
- pytest_dsl/cli.py,sha256=9H2fEPjBbcPyodzIMwZWw-0iHvlkhpUvMO48Bnx_Kiw,2469
2
+ pytest_dsl/cli.py,sha256=iMGfI2VuBI-ZAZrGfxVcBVtx9P_SMORuwbeMMOnDGXA,4774
3
3
  pytest_dsl/conftest_adapter.py,sha256=cevEb0oEZKTZfUrGe1-CmkFByxKhUtjuurBJP7kpLc0,149
4
4
  pytest_dsl/main_adapter.py,sha256=pUIPN_EzY3JCDlYK7yF_OeLDVqni8vtG15G7gVzPJXg,181
5
5
  pytest_dsl/parsetab.py,sha256=n_-2YnNszS-nq26HI8YbEBhvpNq7n_-092iXlsz34wA,8536
@@ -60,9 +60,9 @@ pytest_dsl/keywords/assertion_keywords.py,sha256=H0vNCvfG3h8R3ST6C5sVTEH8OTWj3x9
60
60
  pytest_dsl/keywords/global_keywords.py,sha256=RZcJ9ksfXZaRvds4247LFXu-8a0LFqTvVaD4n98GUrk,1410
61
61
  pytest_dsl/keywords/http_keywords.py,sha256=oGSdLYEGypYxTw6UFA1iHPaE6hRmeaoLfEoXbP_sIaI,25543
62
62
  pytest_dsl/keywords/system_keywords.py,sha256=3D6htXwoW2w0B3Ywtw1EBqffkGHAaUBoapG4-oJDJQQ,496
63
- pytest_dsl-0.3.0.dist-info/licenses/LICENSE,sha256=Rguy8cb9sYhK6cmrBdXvwh94rKVDh2tVZEWptsHIsVM,1071
64
- pytest_dsl-0.3.0.dist-info/METADATA,sha256=hFa0kDZlbUO302wac6QT7Vi0L9RkR-a7YUwXtY3K17E,11924
65
- pytest_dsl-0.3.0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
66
- pytest_dsl-0.3.0.dist-info/entry_points.txt,sha256=BWrYOFO9UgaDUTdS_W0G6Gl9YAj490cetXJsXrcjruA,94
67
- pytest_dsl-0.3.0.dist-info/top_level.txt,sha256=4CrSx4uNqxj7NvK6k1y2JZrSrJSzi-UvPZdqpUhumWM,11
68
- pytest_dsl-0.3.0.dist-info/RECORD,,
63
+ pytest_dsl-0.3.1.dist-info/licenses/LICENSE,sha256=Rguy8cb9sYhK6cmrBdXvwh94rKVDh2tVZEWptsHIsVM,1071
64
+ pytest_dsl-0.3.1.dist-info/METADATA,sha256=X4FcqaJTrg8r17F20OJascFP77r4ZKYZ47m-k2KILIk,11924
65
+ pytest_dsl-0.3.1.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
66
+ pytest_dsl-0.3.1.dist-info/entry_points.txt,sha256=BWrYOFO9UgaDUTdS_W0G6Gl9YAj490cetXJsXrcjruA,94
67
+ pytest_dsl-0.3.1.dist-info/top_level.txt,sha256=4CrSx4uNqxj7NvK6k1y2JZrSrJSzi-UvPZdqpUhumWM,11
68
+ pytest_dsl-0.3.1.dist-info/RECORD,,