-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_encoding_fix.py
More file actions
68 lines (52 loc) · 1.94 KB
/
Copy pathtest_encoding_fix.py
File metadata and controls
68 lines (52 loc) · 1.94 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
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""Test script to verify the encoding fix for Java command output."""
import subprocess
import sys
import os
# Add the app directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
from app.runtime.tools.run_command_tool import RunCommandTool
def test_java_utf8_output():
"""Test that Java output is correctly decoded as UTF-8."""
tool = RunCommandTool(workspace_root="D:\\code\\school\\java\\test2")
# First compile
result = tool.execute("javac Main.java", "D:\\code\\school\\java\\test2", 30)
print("=== javac result ===")
print(result)
print()
# Then run
result = tool.execute("java Main", "D:\\code\\school\\java\\test2", 30)
print("=== java result ===")
print(result)
print()
# Check if the output contains correct Chinese characters
if "张三" in result or "李四" in result:
print("✓ SUCCESS: Chinese characters decoded correctly!")
return True
elif "寮犱笁" in result or "鏉庡洓" in result:
print("✗ FAIL: Garbled characters still present!")
return False
else:
print("? UNCLEAR: Could not verify encoding (no Chinese chars found)")
return None
def test_echo_command():
"""Test a simple echo command to ensure basic functionality."""
tool = RunCommandTool(workspace_root="D:\\code\\school\\java\\test2")
if sys.platform == "win32":
result = tool.execute("echo Hello", "D:\\code\\school\\java\\test2", 10)
else:
result = tool.execute("echo Hello", "/tmp", 10)
print("=== echo result ===")
print(result)
print()
if "Hello" in result:
print("✓ echo command works")
return True
return False
if __name__ == "__main__":
print(f"Platform: {sys.platform}")
print(f"Python version: {sys.version}")
print()
test_echo_command()
print("=" * 50)
test_java_utf8_output()