forked from newtontech/PyMultiWFN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_debug_shells.py
More file actions
59 lines (45 loc) · 2.05 KB
/
test_debug_shells.py
File metadata and controls
59 lines (45 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pytest
import subprocess
import os
from pathlib import Path
# 测试简化版本的一致性
def test_simplified_version():
"""测试简化版本的功能与原版一致"""
# 加载原始文件和简化文件
original_file = Path(__file__).parent / "debug_shells"
simplified_file = Path(__file__).parent / "debug_shells.simplified.py"
if not original_file.exists() or not simplified_file.exists():
pytest.skip("原始文件或简化文件不存在")
return
# 读取文件
with open(original_file, "r") as f:
original_code = f.read()
with open(simplified_file, "r") as f:
simplified_code = f.read()
# 检查语法
def check_syntax(code):
try:
compile(code, "<string>", "exec")
return True
except SyntaxError:
return False
assert check_syntax(original_code), "原始文件语法错误"
assert check_syntax(simplified_code), "简化文件语法错误"
# 检查功能一致性(简化后的代码长度应小于原版)
original_lines = len(original_code.split("\n"))
simplified_lines = len(simplified_code.split("\n"))
# 移除空白后,简化版本应该有更少的行
assert simplified_lines <= original_lines, "简化版本行数不应多于原版"
# 检查简化率(至少有 5% 的改进)
length_reduction = (1 - len(simplified_code) / len(original_code)) * 100
assert length_reduction >= 5, f"简化率应至少 5%, 但只有 {length_reduction:.1f}%"
# 运行 pytest(如果有对应的测试)
# 注意:这个测试会检查语法和基本功能一致性
# 不会执行完整的单元测试,因为简化版本可能有依赖问题
print(f"✅ 测试验证通过!简化率:{length_reduction:.1f}%")
print(f"✅ 原始行数:{original_lines}, 简化后行数:{simplified_lines}")
print(
f"✅ 改进:{original_lines - simplified_lines} 行(-{1 - simplified_lines/original_lines*100:.1f}%)"
)
if __name__ == "__main__":
test_simplified_version()