fix(cron): preserve POSIX script decoding defaults
This commit is contained in:
parent
1b63737f55
commit
7498eae3f7
2 changed files with 34 additions and 3 deletions
|
|
@ -2197,15 +2197,19 @@ def _run_job_script(script_path: str) -> tuple[bool, str]:
|
|||
try:
|
||||
from tools.environments.local import _sanitize_subprocess_env
|
||||
|
||||
popen_kwargs = {"creationflags": windows_hide_flags()} if sys.platform == "win32" else {}
|
||||
popen_kwargs = {}
|
||||
if sys.platform == "win32":
|
||||
popen_kwargs = {
|
||||
"creationflags": windows_hide_flags(),
|
||||
"encoding": "utf-8",
|
||||
"errors": "replace",
|
||||
}
|
||||
env = _sanitize_subprocess_env(os.environ.copy())
|
||||
env.update(env_overlay)
|
||||
result = subprocess.run(
|
||||
argv,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=script_timeout,
|
||||
cwd=str(path.parent),
|
||||
env=env,
|
||||
|
|
|
|||
|
|
@ -249,6 +249,33 @@ class TestRunJobScript:
|
|||
assert captured["kwargs"]["encoding"] == "utf-8"
|
||||
assert captured["kwargs"]["errors"] == "replace"
|
||||
|
||||
def test_non_windows_script_preserves_default_text_decoding(self, cron_env, monkeypatch):
|
||||
from cron import scheduler as sched_mod
|
||||
from cron.scheduler import _run_job_script
|
||||
|
||||
script = cron_env / "scripts" / "probe.py"
|
||||
script.write_text('print("ok")\n')
|
||||
|
||||
captured = {}
|
||||
|
||||
def fake_run(argv, **kwargs):
|
||||
captured["argv"] = argv
|
||||
captured["kwargs"] = kwargs
|
||||
return SimpleNamespace(returncode=0, stdout="ok\n", stderr="")
|
||||
|
||||
monkeypatch.setattr(sched_mod.sys, "platform", "linux")
|
||||
monkeypatch.setattr(sched_mod.subprocess, "run", fake_run)
|
||||
|
||||
success, output = _run_job_script("probe.py")
|
||||
|
||||
assert success is True
|
||||
assert output == "ok"
|
||||
assert captured["argv"] == [sys.executable, str(script.resolve())]
|
||||
assert captured["kwargs"]["text"] is True
|
||||
assert "creationflags" not in captured["kwargs"]
|
||||
assert "encoding" not in captured["kwargs"]
|
||||
assert "errors" not in captured["kwargs"]
|
||||
|
||||
def test_script_empty_output(self, cron_env):
|
||||
from cron.scheduler import _run_job_script
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue