Handle mixed command output encodings

This commit is contained in:
王鹏
2026-10-09 12:54:03 +08:00
parent 9981ad1368
commit a94193d684
3 changed files with 44 additions and 3 deletions

View File

@@ -11,6 +11,36 @@ from deploy_tool.scanner import ProjectComponent, ScanResult
class DeployerTests(unittest.TestCase):
def test_process_output_accepts_utf8_and_gbk_without_decode_failure(self):
output = []
popen_options = {}
class FakeProcess:
stdout = iter(
[
"npm ERR! ⚠ dependency failed\n".encode("utf-8"),
"安装失败\n".encode("gb18030"),
]
)
def wait(self):
return 1
def fake_popen(*args, **kwargs):
popen_options.update(kwargs)
return FakeProcess()
with patch.object(deployer_module.subprocess, "Popen", side_effect=fake_popen):
exit_code = deployer_module._run_process(
["npm.cmd", "install"],
Path("C:/project/web"),
output.append,
)
self.assertEqual(exit_code, 1)
self.assertEqual(output, ["npm ERR! ⚠ dependency failed", "安装失败"])
self.assertNotIn("text", popen_options)
def test_frozen_app_reuses_executable_for_service_console(self):
with patch.object(deployer_module.sys, "frozen", True, create=True):
launcher = deployer_module._service_console_launcher()