cli-test-framework 0.3.7__tar.gz → 0.4.1__tar.gz
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.
- {cli_test_framework-0.3.7/src/cli_test_framework.egg-info → cli_test_framework-0.4.1}/PKG-INFO +16 -1
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/README.md +15 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/setup.py +1 -1
- cli_test_framework-0.4.1/src/cli_test_framework/core/execution.py +74 -0
- cli_test_framework-0.4.1/src/cli_test_framework/core/process_worker.py +43 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/core/test_case.py +6 -2
- cli_test_framework-0.4.1/src/cli_test_framework/core/types.py +55 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/json_comparator.py +5 -4
- cli_test_framework-0.4.1/src/cli_test_framework/runners/json_runner.py +65 -0
- cli_test_framework-0.4.1/src/cli_test_framework/runners/parallel_json_runner.py +92 -0
- cli_test_framework-0.4.1/src/cli_test_framework/runners/yaml_runner.py +64 -0
- cli_test_framework-0.4.1/src/cli_test_framework/utils/__init__.py +19 -0
- cli_test_framework-0.4.1/src/cli_test_framework/utils/path_resolver.py +229 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1/src/cli_test_framework.egg-info}/PKG-INFO +16 -1
- cli_test_framework-0.4.1/src/cli_test_framework.egg-info/SOURCES.txt +92 -0
- cli_test_framework-0.4.1/tests/README.md +15 -0
- cli_test_framework-0.4.1/tests/__pycache__/__init__.cpython-39.pyc +0 -0
- cli_test_framework-0.4.1/tests/__pycache__/conftest.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/__pycache__/conftest.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/__pycache__/run_all.cpython-312.pyc +0 -0
- cli_test_framework-0.4.1/tests/__pycache__/run_all.cpython-39.pyc +0 -0
- cli_test_framework-0.4.1/tests/conftest.py +15 -0
- cli_test_framework-0.3.7/tests/test_filter_demo.py → cli_test_framework-0.4.1/tests/demos/h5_filter_demo.py +37 -33
- cli_test_framework-0.4.1/tests/demos/manual_report_example.py +32 -0
- cli_test_framework-0.3.7/tests/performance_test.py → cli_test_framework-0.4.1/tests/demos/perf_parallel.py +45 -58
- cli_test_framework-0.4.1/tests/e2e/__init__.py +2 -0
- cli_test_framework-0.4.1/tests/e2e/__pycache__/__init__.cpython-312.pyc +0 -0
- cli_test_framework-0.4.1/tests/e2e/__pycache__/__init__.cpython-39.pyc +0 -0
- cli_test_framework-0.4.1/tests/e2e/__pycache__/test_user_flows.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/e2e/__pycache__/test_user_flows.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/e2e/test_user_flows.py +83 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/__pycache__/test_binary_compare.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/__pycache__/test_binary_compare.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/__pycache__/test_h5_compare.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/__pycache__/test_h5_compare.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/__pycache__/test_json_compare.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/__pycache__/test_json_compare.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/__pycache__/test_text_compare.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/__pycache__/test_text_compare.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/test_binary_compare.py +31 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/test_h5_compare.py +107 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/test_json_compare.py +48 -0
- cli_test_framework-0.4.1/tests/integration/file_compare/test_text_compare.py +40 -0
- cli_test_framework-0.4.1/tests/integration/parallel/__pycache__/test_parallel_runner.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/parallel/__pycache__/test_parallel_runner.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/parallel/test_parallel_runner.py +111 -0
- cli_test_framework-0.4.1/tests/integration/path_handling/__pycache__/test_spaces_in_paths.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/path_handling/__pycache__/test_spaces_in_paths.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/integration/path_handling/test_spaces_in_paths.py +85 -0
- cli_test_framework-0.4.1/tests/run_all.py +62 -0
- cli_test_framework-0.4.1/tests/unit/core/__pycache__/test_setup.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/unit/core/__pycache__/test_setup.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.3.7/tests/test_setup_module.py → cli_test_framework-0.4.1/tests/unit/core/test_setup.py +81 -157
- cli_test_framework-0.4.1/tests/unit/runners/__pycache__/test_json_yaml_runner.cpython-312-pytest-7.4.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/unit/runners/__pycache__/test_json_yaml_runner.cpython-39-pytest-8.3.4.pyc +0 -0
- cli_test_framework-0.4.1/tests/unit/runners/test_json_yaml_runner.py +83 -0
- cli_test_framework-0.3.7/CHANGELOG.md +0 -211
- cli_test_framework-0.3.7/src/cli_test_framework/core/process_worker.py +0 -93
- cli_test_framework-0.3.7/src/cli_test_framework/runners/json_runner.py +0 -99
- cli_test_framework-0.3.7/src/cli_test_framework/runners/parallel_json_runner.py +0 -118
- cli_test_framework-0.3.7/src/cli_test_framework/runners/yaml_runner.py +0 -96
- cli_test_framework-0.3.7/src/cli_test_framework/utils/__init__.py +0 -11
- cli_test_framework-0.3.7/src/cli_test_framework/utils/path_resolver.py +0 -205
- cli_test_framework-0.3.7/src/cli_test_framework.egg-info/SOURCES.txt +0 -58
- cli_test_framework-0.3.7/tests/test1.py +0 -30
- cli_test_framework-0.3.7/tests/test_comprehensive_space.py +0 -118
- cli_test_framework-0.3.7/tests/test_parallel_runner.py +0 -170
- cli_test_framework-0.3.7/tests/test_parallel_space.py +0 -93
- cli_test_framework-0.3.7/tests/test_runners.py +0 -32
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/MANIFEST.in +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/docs/user_manual.md +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/pyproject.toml +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/setup.cfg +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/__init__.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/cli.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/commands/__init__.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/commands/compare.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/core/__init__.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/core/assertions.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/core/base_runner.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/core/parallel_runner.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/core/setup.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/__init__.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/base_comparator.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/binary_comparator.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/csv_comparator.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/factory.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/h5_comparator.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/result.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/text_comparator.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/file_comparator/xml_comparator.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/runners/__init__.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/utils/report_generator.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework.egg-info/dependency_links.txt +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework.egg-info/entry_points.txt +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework.egg-info/requires.txt +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework.egg-info/top_level.txt +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/__init__.py +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/__pycache__/__init__.cpython-312.pyc +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/__pycache__/test_parallel_runner.cpython-312-pytest-7.4.4.pyc +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/__pycache__/test_setup_module.cpython-312-pytest-7.4.4.pyc +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/fixtures/test_cases.json +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/fixtures/test_cases.yaml +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/fixtures/test_cases1.json +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/fixtures/test_with_setup.json +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/fixtures/test_with_setup.yaml +0 -0
- {cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/tests/test_report.txt +0 -0
{cli_test_framework-0.3.7/src/cli_test_framework.egg-info → cli_test_framework-0.4.1}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cli-test-framework
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: A powerful command line testing framework in Python with setup modules, parallel execution, and file comparison capabilities.
|
|
5
5
|
Home-page: https://github.com/ozil111/cli-test-framework
|
|
6
6
|
Author: Xiaotong Wang
|
|
@@ -53,6 +53,7 @@ This is a lightweight and extensible automated testing framework that supports d
|
|
|
53
53
|
- **📊 Comprehensive Reports**: Detailed pass rate statistics and failure diagnostics
|
|
54
54
|
- **🔧 Thread-Safe Design**: Robust concurrent execution with proper synchronization
|
|
55
55
|
- **📝 Advanced File Comparison**: Support for comparing various file types (text, binary, JSON, HDF5) with detailed diff output
|
|
56
|
+
- **🎛️ Resource-Aware Scheduling**: Per-test timeout and resource hints (estimated time / memory / priority) with LPT-based ordering in parallel runs to improve throughput and avoid long-tail blocking
|
|
56
57
|
|
|
57
58
|
## 3. Quick Start
|
|
58
59
|
|
|
@@ -144,6 +145,20 @@ compare-files binary1.bin binary2.bin --similarity
|
|
|
144
145
|
"output_contains": ["Environment: development"]
|
|
145
146
|
}
|
|
146
147
|
},
|
|
148
|
+
{
|
|
149
|
+
"name": "Full_Car_Crash_Simulation",
|
|
150
|
+
"command": "radioss_solver",
|
|
151
|
+
"args": ["-i", "input.0000.rad"],
|
|
152
|
+
"timeout": 36000,
|
|
153
|
+
"resources": {
|
|
154
|
+
"estimated_time": 18000,
|
|
155
|
+
"min_memory_mb": 16000,
|
|
156
|
+
"priority": 10
|
|
157
|
+
},
|
|
158
|
+
"expected": {
|
|
159
|
+
"return_code": 0
|
|
160
|
+
}
|
|
161
|
+
},
|
|
147
162
|
{
|
|
148
163
|
"name": "File Comparison Test",
|
|
149
164
|
"command": "compare-files",
|
|
@@ -18,6 +18,7 @@ This is a lightweight and extensible automated testing framework that supports d
|
|
|
18
18
|
- **📊 Comprehensive Reports**: Detailed pass rate statistics and failure diagnostics
|
|
19
19
|
- **🔧 Thread-Safe Design**: Robust concurrent execution with proper synchronization
|
|
20
20
|
- **📝 Advanced File Comparison**: Support for comparing various file types (text, binary, JSON, HDF5) with detailed diff output
|
|
21
|
+
- **🎛️ Resource-Aware Scheduling**: Per-test timeout and resource hints (estimated time / memory / priority) with LPT-based ordering in parallel runs to improve throughput and avoid long-tail blocking
|
|
21
22
|
|
|
22
23
|
## 3. Quick Start
|
|
23
24
|
|
|
@@ -109,6 +110,20 @@ compare-files binary1.bin binary2.bin --similarity
|
|
|
109
110
|
"output_contains": ["Environment: development"]
|
|
110
111
|
}
|
|
111
112
|
},
|
|
113
|
+
{
|
|
114
|
+
"name": "Full_Car_Crash_Simulation",
|
|
115
|
+
"command": "radioss_solver",
|
|
116
|
+
"args": ["-i", "input.0000.rad"],
|
|
117
|
+
"timeout": 36000,
|
|
118
|
+
"resources": {
|
|
119
|
+
"estimated_time": 18000,
|
|
120
|
+
"min_memory_mb": 16000,
|
|
121
|
+
"priority": 10
|
|
122
|
+
},
|
|
123
|
+
"expected": {
|
|
124
|
+
"return_code": 0
|
|
125
|
+
}
|
|
126
|
+
},
|
|
112
127
|
{
|
|
113
128
|
"name": "File Comparison Test",
|
|
114
129
|
"command": "compare-files",
|
|
@@ -8,7 +8,7 @@ with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
|
|
|
8
8
|
|
|
9
9
|
setup(
|
|
10
10
|
name="cli-test-framework",
|
|
11
|
-
version="0.
|
|
11
|
+
version="0.4.1",
|
|
12
12
|
author="Xiaotong Wang",
|
|
13
13
|
author_email="xiaotongwang98@gmail.com",
|
|
14
14
|
description="A powerful command line testing framework in Python with setup modules, parallel execution, and file comparison capabilities.",
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import time
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from .assertions import Assertions
|
|
6
|
+
from .types import ExpectedResult, TestCaseData, TestResultData
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def validate_result(expected: ExpectedResult, actual: TestResultData) -> None:
|
|
10
|
+
"""
|
|
11
|
+
Pure validation logic. Raises AssertionError on mismatch.
|
|
12
|
+
"""
|
|
13
|
+
assertions = Assertions()
|
|
14
|
+
|
|
15
|
+
if "return_code" in expected:
|
|
16
|
+
assertions.return_code_equals(actual["return_code"], expected["return_code"])
|
|
17
|
+
|
|
18
|
+
if "output_contains" in expected:
|
|
19
|
+
for text in expected["output_contains"]:
|
|
20
|
+
assertions.contains(actual["output"], text)
|
|
21
|
+
|
|
22
|
+
if "output_matches" in expected and expected["output_matches"]:
|
|
23
|
+
assertions.matches(actual["output"], expected["output_matches"])
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def execute_single_test_case(case: TestCaseData, workspace: Optional[str] = None) -> TestResultData:
|
|
27
|
+
"""
|
|
28
|
+
Stateless execution of a single test case.
|
|
29
|
+
"""
|
|
30
|
+
start_time = time.time()
|
|
31
|
+
full_command = f"{case['command']} {' '.join(case['args'])}".strip()
|
|
32
|
+
timeout_limit = case.get("timeout", 3600)
|
|
33
|
+
|
|
34
|
+
result: TestResultData = {
|
|
35
|
+
"name": case["name"],
|
|
36
|
+
"status": "failed",
|
|
37
|
+
"message": "",
|
|
38
|
+
"command": full_command,
|
|
39
|
+
"output": "",
|
|
40
|
+
"return_code": None,
|
|
41
|
+
"duration": 0.0,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
process = subprocess.run(
|
|
46
|
+
full_command,
|
|
47
|
+
cwd=workspace if workspace else None,
|
|
48
|
+
capture_output=True,
|
|
49
|
+
text=True,
|
|
50
|
+
check=False,
|
|
51
|
+
shell=True,
|
|
52
|
+
timeout=timeout_limit if timeout_limit is not None else None,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
output = process.stdout + process.stderr
|
|
56
|
+
result["output"] = output
|
|
57
|
+
result["return_code"] = process.returncode
|
|
58
|
+
|
|
59
|
+
validate_result(case["expected"], result)
|
|
60
|
+
result["status"] = "passed"
|
|
61
|
+
except subprocess.TimeoutExpired as exc:
|
|
62
|
+
result["status"] = "timeout"
|
|
63
|
+
result["message"] = f"Timeout reached! Killed after {timeout_limit} seconds."
|
|
64
|
+
result["output"] = (exc.stdout or "") + (exc.stderr or "")
|
|
65
|
+
result["return_code"] = None
|
|
66
|
+
except AssertionError as exc:
|
|
67
|
+
result["message"] = str(exc)
|
|
68
|
+
except Exception as exc:
|
|
69
|
+
result["message"] = f"Execution error: {str(exc)}"
|
|
70
|
+
finally:
|
|
71
|
+
result["duration"] = time.time() - start_time
|
|
72
|
+
|
|
73
|
+
return result
|
|
74
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
进程工作器模块
|
|
3
|
+
用于多进程并行测试执行,避免序列化问题
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Dict, Any
|
|
7
|
+
from .execution import execute_single_test_case
|
|
8
|
+
from .types import TestCaseData
|
|
9
|
+
|
|
10
|
+
def run_test_in_process(test_index: int, case_data: Dict[str, Any], workspace: str = None) -> Dict[str, Any]:
|
|
11
|
+
"""
|
|
12
|
+
在独立进程中运行单个测试用例
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
test_index: 测试索引
|
|
16
|
+
case_data: 测试用例数据字典
|
|
17
|
+
workspace: 工作目录
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
测试结果字典
|
|
21
|
+
"""
|
|
22
|
+
case: TestCaseData = {
|
|
23
|
+
"name": case_data["name"],
|
|
24
|
+
"command": case_data["command"],
|
|
25
|
+
"args": case_data["args"],
|
|
26
|
+
"expected": case_data["expected"],
|
|
27
|
+
"description": case_data.get("description"),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
command_preview = f"{case['command']} {' '.join(case['args'])}".strip()
|
|
31
|
+
print(f" [Process Worker {test_index}] Executing command: {command_preview}")
|
|
32
|
+
|
|
33
|
+
result = execute_single_test_case(case, workspace)
|
|
34
|
+
|
|
35
|
+
if result["output"].strip():
|
|
36
|
+
print(f" [Process Worker {test_index}] Command output for {case['name']}:")
|
|
37
|
+
for line in result["output"].splitlines():
|
|
38
|
+
print(f" {line}")
|
|
39
|
+
|
|
40
|
+
if result["status"] != "passed" and result.get("message"):
|
|
41
|
+
print(f" [Process Worker {test_index}] Error for {case['name']}: {result['message']}")
|
|
42
|
+
|
|
43
|
+
return result
|
{cli_test_framework-0.3.7 → cli_test_framework-0.4.1}/src/cli_test_framework/core/test_case.py
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
|
-
from typing import List, Dict, Any
|
|
2
|
+
from typing import List, Dict, Any, Optional
|
|
3
3
|
|
|
4
4
|
@dataclass
|
|
5
5
|
class TestCase:
|
|
@@ -8,6 +8,8 @@ class TestCase:
|
|
|
8
8
|
args: List[str]
|
|
9
9
|
expected: Dict[str, Any]
|
|
10
10
|
description: str = ""
|
|
11
|
+
timeout: Optional[float] = None
|
|
12
|
+
resources: Optional[Dict[str, Any]] = None
|
|
11
13
|
|
|
12
14
|
def to_dict(self) -> Dict[str, Any]:
|
|
13
15
|
"""Convert test case to dictionary format"""
|
|
@@ -17,5 +19,7 @@ class TestCase:
|
|
|
17
19
|
"name": self.name,
|
|
18
20
|
"command": self.command,
|
|
19
21
|
"args": self.args,
|
|
20
|
-
"expected": self.expected
|
|
22
|
+
"expected": self.expected,
|
|
23
|
+
"timeout": self.timeout,
|
|
24
|
+
"resources": self.resources,
|
|
21
25
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from typing import Any, Dict, List, Optional, TypedDict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ExpectedResult(TypedDict, total=False):
|
|
5
|
+
"""Expectation configuration for a single test case."""
|
|
6
|
+
|
|
7
|
+
return_code: Optional[int]
|
|
8
|
+
output_contains: List[str]
|
|
9
|
+
output_matches: Optional[str]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ResourceRequirements(TypedDict, total=False):
|
|
13
|
+
"""Optional resource hints for scheduling."""
|
|
14
|
+
|
|
15
|
+
estimated_time: float # seconds, used for ordering (LPT)
|
|
16
|
+
min_memory_mb: float # soft hint to avoid OOM
|
|
17
|
+
priority: int # higher value => higher priority
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestCaseData(TypedDict):
|
|
21
|
+
"""Input data shape for a test case after解析/路径处理."""
|
|
22
|
+
|
|
23
|
+
name: str
|
|
24
|
+
command: str
|
|
25
|
+
args: List[str]
|
|
26
|
+
expected: ExpectedResult
|
|
27
|
+
description: Optional[str]
|
|
28
|
+
timeout: Optional[float]
|
|
29
|
+
resources: Optional[ResourceRequirements]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SetupConfig(TypedDict):
|
|
33
|
+
"""Setup configuration (currently environment variables only)."""
|
|
34
|
+
|
|
35
|
+
environment_variables: Dict[str, str]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class TestSuiteConfig(TypedDict):
|
|
39
|
+
"""Top-level configuration for a suite loaded from JSON/YAML."""
|
|
40
|
+
|
|
41
|
+
setup: Optional[SetupConfig]
|
|
42
|
+
test_cases: List[TestCaseData]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class TestResultData(TypedDict):
|
|
46
|
+
"""Normalized result produced by executing a single test case."""
|
|
47
|
+
|
|
48
|
+
name: str
|
|
49
|
+
status: str # 'passed', 'failed'
|
|
50
|
+
message: str
|
|
51
|
+
command: str
|
|
52
|
+
output: str
|
|
53
|
+
return_code: Optional[int]
|
|
54
|
+
duration: float
|
|
55
|
+
|
|
@@ -53,8 +53,8 @@ class JsonComparator(TextComparator):
|
|
|
53
53
|
json_text = ''.join(text_content)
|
|
54
54
|
try:
|
|
55
55
|
json_data = json.loads(json_text)
|
|
56
|
-
if self.key_field:
|
|
57
|
-
# Only keep the specified key field(s)
|
|
56
|
+
if self.key_field and isinstance(json_data, dict):
|
|
57
|
+
# Only keep the specified key field(s) when top-level is a mapping
|
|
58
58
|
key_fields = self.key_field if isinstance(self.key_field, list) else [self.key_field]
|
|
59
59
|
filtered_data = {key: json_data[key] for key in key_fields if key in json_data}
|
|
60
60
|
return filtered_data
|
|
@@ -79,8 +79,9 @@ class JsonComparator(TextComparator):
|
|
|
79
79
|
self._compare_json_key_based(content1, content2, "", differences)
|
|
80
80
|
else:
|
|
81
81
|
self._compare_json_exact(content1, content2, "", differences)
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
|
|
83
|
+
identical = len(differences) == 0
|
|
84
|
+
return identical, differences
|
|
84
85
|
|
|
85
86
|
def _compare_json_exact(self, obj1, obj2, path, differences, max_diffs=10):
|
|
86
87
|
"""
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from typing import Optional, Dict, Any
|
|
2
|
+
from ..core.base_runner import BaseRunner
|
|
3
|
+
from ..core.test_case import TestCase
|
|
4
|
+
from ..core.execution import execute_single_test_case
|
|
5
|
+
from ..core.types import TestCaseData
|
|
6
|
+
from ..utils.path_resolver import PathResolver, parse_command_string, resolve_paths
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
class JSONRunner(BaseRunner):
|
|
11
|
+
def __init__(self, config_file="test_cases.json", workspace: Optional[str] = None):
|
|
12
|
+
super().__init__(config_file, workspace)
|
|
13
|
+
# Backward-compatible attribute for tests that patch path_resolver
|
|
14
|
+
self.path_resolver = PathResolver(self.workspace)
|
|
15
|
+
|
|
16
|
+
def load_test_cases(self) -> None:
|
|
17
|
+
"""Load test cases from a JSON file."""
|
|
18
|
+
try:
|
|
19
|
+
with open(self.config_path, 'r', encoding='utf-8') as f:
|
|
20
|
+
config = json.load(f)
|
|
21
|
+
|
|
22
|
+
# 加载setup配置
|
|
23
|
+
self.load_setup_from_config(config)
|
|
24
|
+
|
|
25
|
+
required_fields = ["name", "command", "args", "expected"]
|
|
26
|
+
for case in config["test_cases"]:
|
|
27
|
+
if not all(field in case for field in required_fields):
|
|
28
|
+
raise ValueError(f"Test case {case.get('name', 'unnamed')} is missing required fields")
|
|
29
|
+
|
|
30
|
+
# 使用智能命令解析,正确处理包含空格的路径
|
|
31
|
+
# Use resolver attribute (keeps backward compatibility with tests monkeypatching it)
|
|
32
|
+
case["command"] = self.path_resolver.parse_command_string(case["command"])
|
|
33
|
+
case["args"] = self.path_resolver.resolve_paths(case["args"])
|
|
34
|
+
self.test_cases.append(TestCase(**case))
|
|
35
|
+
|
|
36
|
+
print(f"Successfully loaded {len(self.test_cases)} test cases")
|
|
37
|
+
# print(self.test_cases)
|
|
38
|
+
except Exception as e:
|
|
39
|
+
sys.exit(f"Failed to load configuration file: {str(e)}")
|
|
40
|
+
|
|
41
|
+
def run_single_test(self, case: TestCase) -> Dict[str, str]:
|
|
42
|
+
case_data: TestCaseData = {
|
|
43
|
+
"name": case.name,
|
|
44
|
+
"command": case.command,
|
|
45
|
+
"args": case.args,
|
|
46
|
+
"expected": case.expected,
|
|
47
|
+
"description": case.description or None,
|
|
48
|
+
"timeout": case.timeout,
|
|
49
|
+
"resources": case.resources,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
command_preview = f"{case_data['command']} {' '.join(case_data['args'])}".strip()
|
|
53
|
+
print(f" Executing command: {command_preview}")
|
|
54
|
+
|
|
55
|
+
result = execute_single_test_case(case_data, str(self.workspace) if self.workspace else None)
|
|
56
|
+
|
|
57
|
+
if result["output"].strip():
|
|
58
|
+
print(" Command output:")
|
|
59
|
+
for line in result["output"].splitlines():
|
|
60
|
+
print(f" {line}")
|
|
61
|
+
|
|
62
|
+
if result["status"] != "passed" and result.get("message"):
|
|
63
|
+
print(f" Error: {result['message']}")
|
|
64
|
+
|
|
65
|
+
return result
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from typing import Optional, Dict, Any
|
|
2
|
+
from ..core.parallel_runner import ParallelRunner
|
|
3
|
+
from ..core.test_case import TestCase
|
|
4
|
+
from ..core.execution import execute_single_test_case
|
|
5
|
+
from ..core.types import TestCaseData
|
|
6
|
+
from ..utils.path_resolver import PathResolver, parse_command_string, resolve_paths
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
import threading
|
|
10
|
+
|
|
11
|
+
class ParallelJSONRunner(ParallelRunner):
|
|
12
|
+
"""并行JSON测试运行器"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, config_file="test_cases.json", workspace: Optional[str] = None,
|
|
15
|
+
max_workers: Optional[int] = None, execution_mode: str = "thread"):
|
|
16
|
+
"""
|
|
17
|
+
初始化并行JSON运行器
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
config_file: JSON配置文件路径
|
|
21
|
+
workspace: 工作目录
|
|
22
|
+
max_workers: 最大并发数
|
|
23
|
+
execution_mode: 执行模式,'thread' 或 'process'
|
|
24
|
+
"""
|
|
25
|
+
super().__init__(config_file, workspace, max_workers, execution_mode)
|
|
26
|
+
# Backward-compatible attribute for potential external patches/tests
|
|
27
|
+
self.path_resolver = PathResolver(self.workspace)
|
|
28
|
+
self._print_lock = threading.Lock() # 用于控制输出顺序
|
|
29
|
+
|
|
30
|
+
def load_test_cases(self) -> None:
|
|
31
|
+
"""从JSON文件加载测试用例"""
|
|
32
|
+
try:
|
|
33
|
+
with open(self.config_path, 'r', encoding='utf-8') as f:
|
|
34
|
+
config = json.load(f)
|
|
35
|
+
|
|
36
|
+
# 加载setup配置
|
|
37
|
+
self.load_setup_from_config(config)
|
|
38
|
+
|
|
39
|
+
required_fields = ["name", "command", "args", "expected"]
|
|
40
|
+
for case in config["test_cases"]:
|
|
41
|
+
if not all(field in case for field in required_fields):
|
|
42
|
+
raise ValueError(f"Test case {case.get('name', 'unnamed')} is missing required fields")
|
|
43
|
+
|
|
44
|
+
# Use resolver attribute (keeps backward compatibility with tests monkeypatching it)
|
|
45
|
+
case["command"] = self.path_resolver.parse_command_string(case["command"])
|
|
46
|
+
case["args"] = self.path_resolver.resolve_paths(case["args"])
|
|
47
|
+
self.test_cases.append(TestCase(**case))
|
|
48
|
+
|
|
49
|
+
print(f"Successfully loaded {len(self.test_cases)} test cases")
|
|
50
|
+
|
|
51
|
+
# Heuristic scheduling: longest estimated time first to improve parallel utilization.
|
|
52
|
+
if self.test_cases:
|
|
53
|
+
print("Optimizing execution order based on estimated duration...")
|
|
54
|
+
self.test_cases.sort(
|
|
55
|
+
key=lambda c: (c.resources or {}).get("estimated_time", 0),
|
|
56
|
+
reverse=True,
|
|
57
|
+
)
|
|
58
|
+
top_case = self.test_cases[0]
|
|
59
|
+
top_est = (top_case.resources or {}).get("estimated_time", 0)
|
|
60
|
+
print(f"Heaviest task: {top_case.name} (Est: {top_est}s)")
|
|
61
|
+
except Exception as e:
|
|
62
|
+
sys.exit(f"Failed to load configuration file: {str(e)}")
|
|
63
|
+
|
|
64
|
+
def run_single_test(self, case: TestCase) -> Dict[str, Any]:
|
|
65
|
+
"""运行单个测试用例(线程安全版本)"""
|
|
66
|
+
case_data: TestCaseData = {
|
|
67
|
+
"name": case.name,
|
|
68
|
+
"command": case.command,
|
|
69
|
+
"args": case.args,
|
|
70
|
+
"expected": case.expected,
|
|
71
|
+
"description": case.description or None,
|
|
72
|
+
"timeout": case.timeout,
|
|
73
|
+
"resources": case.resources,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
command_preview = f"{case_data['command']} {' '.join(case_data['args'])}".strip()
|
|
77
|
+
with self._print_lock:
|
|
78
|
+
print(f" [Worker] Executing command: {command_preview}")
|
|
79
|
+
|
|
80
|
+
result = execute_single_test_case(case_data, str(self.workspace) if self.workspace else None)
|
|
81
|
+
|
|
82
|
+
if result["output"].strip():
|
|
83
|
+
with self._print_lock:
|
|
84
|
+
print(f" [Worker] Command output for {case.name}:")
|
|
85
|
+
for line in result["output"].splitlines():
|
|
86
|
+
print(f" {line}")
|
|
87
|
+
|
|
88
|
+
if result["status"] != "passed" and result.get("message"):
|
|
89
|
+
with self._print_lock:
|
|
90
|
+
print(f" [Worker] Error for {case.name}: {result['message']}")
|
|
91
|
+
|
|
92
|
+
return result
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from typing import Optional, Dict, Any
|
|
2
|
+
from ..core.base_runner import BaseRunner
|
|
3
|
+
from ..core.test_case import TestCase
|
|
4
|
+
from ..core.execution import execute_single_test_case
|
|
5
|
+
from ..core.types import TestCaseData
|
|
6
|
+
from ..utils.path_resolver import PathResolver, parse_command_string, resolve_paths
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
class YAMLRunner(BaseRunner):
|
|
10
|
+
def __init__(self, config_file="test_cases.yaml", workspace: Optional[str] = None):
|
|
11
|
+
super().__init__(config_file, workspace)
|
|
12
|
+
# Backward-compatible attribute for tests that patch path_resolver
|
|
13
|
+
self.path_resolver = PathResolver(self.workspace)
|
|
14
|
+
|
|
15
|
+
def load_test_cases(self):
|
|
16
|
+
"""Load test cases from a YAML file."""
|
|
17
|
+
try:
|
|
18
|
+
import yaml
|
|
19
|
+
with open(self.config_path, 'r', encoding='utf-8') as f:
|
|
20
|
+
config = yaml.safe_load(f)
|
|
21
|
+
|
|
22
|
+
# 加载setup配置
|
|
23
|
+
self.load_setup_from_config(config)
|
|
24
|
+
|
|
25
|
+
required_fields = ["name", "command", "args", "expected"]
|
|
26
|
+
for case in config["test_cases"]:
|
|
27
|
+
if not all(field in case for field in required_fields):
|
|
28
|
+
raise ValueError(f"Test case {case.get('name', 'unnamed')} is missing required fields")
|
|
29
|
+
|
|
30
|
+
# Use resolver attribute (keeps backward compatibility with tests monkeypatching it)
|
|
31
|
+
case["command"] = self.path_resolver.parse_command_string(case["command"])
|
|
32
|
+
case["args"] = self.path_resolver.resolve_paths(case["args"])
|
|
33
|
+
self.test_cases.append(TestCase(**case))
|
|
34
|
+
|
|
35
|
+
print(f"Successfully loaded {len(self.test_cases)} test cases")
|
|
36
|
+
except Exception as e:
|
|
37
|
+
sys.exit(f"Failed to load configuration file: {str(e)}")
|
|
38
|
+
|
|
39
|
+
def run_single_test(self, case: TestCase) -> Dict[str, Any]:
|
|
40
|
+
"""Run a single test case and return the result"""
|
|
41
|
+
case_data: TestCaseData = {
|
|
42
|
+
"name": case.name,
|
|
43
|
+
"command": case.command,
|
|
44
|
+
"args": case.args,
|
|
45
|
+
"expected": case.expected,
|
|
46
|
+
"description": case.description or None,
|
|
47
|
+
"timeout": case.timeout,
|
|
48
|
+
"resources": case.resources,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
command_preview = f"{case_data['command']} {' '.join(case_data['args'])}".strip()
|
|
52
|
+
print(f" Executing command: {command_preview}")
|
|
53
|
+
|
|
54
|
+
result = execute_single_test_case(case_data, str(self.workspace) if self.workspace else None)
|
|
55
|
+
|
|
56
|
+
if result["output"].strip():
|
|
57
|
+
print(" Command output:")
|
|
58
|
+
for line in result["output"].splitlines():
|
|
59
|
+
print(f" {line}")
|
|
60
|
+
|
|
61
|
+
if result["status"] != "passed" and result.get("message"):
|
|
62
|
+
print(f" Error: {result['message']}")
|
|
63
|
+
|
|
64
|
+
return result
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# File: /python-test-framework/python-test-framework/src/utils/__init__.py
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Utility functions for the CLI Testing Framework
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .path_resolver import (
|
|
8
|
+
PathResolver,
|
|
9
|
+
parse_command_string,
|
|
10
|
+
resolve_paths,
|
|
11
|
+
resolve_command,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
'PathResolver',
|
|
16
|
+
'parse_command_string',
|
|
17
|
+
'resolve_paths',
|
|
18
|
+
'resolve_command',
|
|
19
|
+
]
|