jackson 1 week ago
parent
commit
eae9bb2ceb

BIN
scripts/__pycache__/audit.cpython-313.pyc


BIN
scripts/__pycache__/kit_path.cpython-313.pyc


BIN
scripts/__pycache__/rule_check.cpython-313.pyc


BIN
scripts/__pycache__/sync_package.cpython-313.pyc


BIN
tests/__pycache__/test_kit_path.cpython-313.pyc


BIN
tests/__pycache__/test_mcp_audit.cpython-313.pyc


+ 7 - 2
tests/test_mcp_audit.py

@@ -1,5 +1,6 @@
 import copy
 import copy
 import json
 import json
+import os
 import subprocess
 import subprocess
 import sys
 import sys
 import tempfile
 import tempfile
@@ -10,6 +11,9 @@ ROOT = Path(__file__).resolve().parents[1]
 sys.path.insert(0, str(ROOT / "scripts"))
 sys.path.insert(0, str(ROOT / "scripts"))
 import mcp_audit as mcp
 import mcp_audit as mcp
 
 
+# 子进程输出按 UTF-8 读取;Windows 控制台默认代码页不是 UTF-8,须显式指定
+CHILD_ENV = {**os.environ, "PYTHONIOENCODING": "utf-8"}
+
 
 
 def snapshot():
 def snapshot():
     row = {
     row = {
@@ -376,7 +380,7 @@ class CommandLineTests(unittest.TestCase):
             path.write_text(json.dumps(source), encoding="utf-8")
             path.write_text(json.dumps(source), encoding="utf-8")
             result = subprocess.run([sys.executable, str(ROOT / "scripts/mcp_audit.py"), "evidence", str(path),
             result = subprocess.run([sys.executable, str(ROOT / "scripts/mcp_audit.py"), "evidence", str(path),
                                      "--scope", "context", "/certification_files/toy_file", "/certification_files/fda_file"],
                                      "--scope", "context", "/certification_files/toy_file", "/certification_files/fda_file"],
-                                    capture_output=True, text=True, encoding="utf-8")
+                                    capture_output=True, text=True, encoding="utf-8", env=CHILD_ENV)
             self.assertEqual(result.returncode, 0, result.stderr)
             self.assertEqual(result.returncode, 0, result.stderr)
             values = json.loads(result.stdout)
             values = json.loads(result.stdout)
             self.assertEqual(values["/certification_files/toy_file"]["status"], "supplied")
             self.assertEqual(values["/certification_files/toy_file"]["status"], "supplied")
@@ -390,7 +394,8 @@ class CommandLineTests(unittest.TestCase):
             source_path.write_text(json.dumps(snapshot(), ensure_ascii=False), encoding="utf-8")
             source_path.write_text(json.dumps(snapshot(), ensure_ascii=False), encoding="utf-8")
             def run(*args):
             def run(*args):
                 return subprocess.run([sys.executable, str(ROOT / "scripts/mcp_audit.py"), *map(str, args)],
                 return subprocess.run([sys.executable, str(ROOT / "scripts/mcp_audit.py"), *map(str, args)],
-                                      capture_output=True, text=True, encoding="utf-8", cwd=directory)
+                                      capture_output=True, text=True, encoding="utf-8", cwd=directory,
+                                      env=CHILD_ENV)
             prepared = run("prepare", source_path, "--out", payload_path)
             prepared = run("prepare", source_path, "--out", payload_path)
             self.assertEqual(prepared.returncode, 0, prepared.stderr)
             self.assertEqual(prepared.returncode, 0, prepared.stderr)
             self.assertEqual(json.loads(payload_path.read_text(encoding="utf-8"))["result"], "hold")
             self.assertEqual(json.loads(payload_path.read_text(encoding="utf-8"))["result"], "hold")