添加输入模拟测试脚本

This commit is contained in:
ypshidifu
2026-09-18 21:43:29 +08:00
parent c8d46eca54
commit 7dc503e578
+49
View File
@@ -0,0 +1,49 @@
import os
import sys
# 模拟用户在交互式模式下的输入(包含引号)
def test_interactive_input():
# 用户在控制台输入的命令(包括引号)
test_cases = [
# 用户输入包含引号的完整命令
('"D:\\桌面\\server-icon.png">d:/桌面/源码/1.bmp "你好阿爸"', '带引号的完整命令'),
# 用户输入不带引号的命令
('D:\\桌面\\server-icon.png>d:/桌面/源码/1.bmp 你好阿爸', '不带引号的命令'),
# 用户输入简单格式转换
('"D:\\桌面\\server-icon.png>.bmp" "测试水印"', '简单格式转换带引号'),
# 用户输入指定输出目录
('"D:\\桌面\\server-icon.png">./output/test.bmp "水印内容"', '指定输出目录'),
]
for cmd, description in test_cases:
print(f'测试: {description}')
print(f' 用户输入: {cmd!r}')
# 模拟 main() 中的处理逻辑
if '>' in cmd:
parts = cmd.split('>', 1)
image_part = parts[0].strip()
rest = parts[1].strip()
print(f' 分割后 - image_part: {image_part!r}, rest: {rest!r}')
tokens = rest.split(None, 1)
if len(tokens) == 2:
output_spec, text = tokens
full_arg = f'{image_part}>{output_spec}'
print(f' 组装后 - full_arg: {full_arg!r}, text: {text!r}')
# 模拟 process_single 的处理
image_arg = full_arg.strip().strip('"').strip("'")
text = text.strip().strip('"').strip("'")
print(f' 去引号后 - image_arg: {image_arg!r}, text: {text!r}')
if '>' in image_arg:
p = image_arg.rsplit('>', 1)
img = p[0].strip().strip('"').strip("'")
spec = p[1].strip()
print(f' 最终 - input_path: {img!r}, output_spec: {spec!r}')
print(f' 文件存在: {os.path.isfile(img)}')
print()
if __name__ == '__main__':
test_interactive_input()