From 7dc503e578d505efe23da6cfc190d0927c9e7dff Mon Sep 17 00:00:00 2001 From: ypshidifu Date: Fri, 18 Sep 2026 21:43:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BE=93=E5=85=A5=E6=A8=A1?= =?UTF-8?q?=E6=8B=9F=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_input_sim.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test_input_sim.py diff --git a/test_input_sim.py b/test_input_sim.py new file mode 100644 index 0000000..1e556f4 --- /dev/null +++ b/test_input_sim.py @@ -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()