Files
Strata/terminal/tools/test_setup_run_script_newlines.py
T
Niko1221 0c68292e70 setup: run-<model>.bat and the build .bat are written with single CRLF line ends (#1939)
From PR #1939 (markusrenneronline; its commit 87c2fd943; the PR's merge commit is left out), author kept. setup writes the
"\r\n" of these two Windows batch files itself, and text mode on Windows turned each one into "\r\r\n". They are written
as bytes now. The PR passed newline="" to Path.write_text, which needs Python 3.10; write_bytes gives the same bytes on
every version, so that is what is used (setup.py has no minimum Python check). Applies on the 0.2.16 layout, redone by
hand (setup.py moved, line numbers drifted). The PR's test (test_setup_run_script_newlines.py) is kept at
terminal/tools/; on the owner PC (Windows) it fails on the old code (the run script has "\r\r\n") and passes with the
change.
2026-11-19 13:12:44 +01:00

33 lines
1.2 KiB
Python

"""run-<model>.bat is written with plain CRLF line ends: setup writes the \\r\\n itself, so text mode on Windows must not
translate them again (it made "@echo off\\r\\r\\n"). The test writes the script into a temporary folder with WIN set,
so it runs on Linux too (where the doubling cannot happen, but the line ends are still checked).
python -m unittest tools.test_setup_run_script_newlines
"""
from __future__ import annotations
import sys
import tempfile
import unittest
from pathlib import Path
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
import setup # noqa: E402
class RunScriptNewlines(unittest.TestCase):
def test_bat_has_single_crlf(self):
with tempfile.TemporaryDirectory() as d:
with mock.patch.object(setup, "WIN", True), mock.patch.object(setup, "ROOT", Path(d)):
script = setup.write_run_script("IQ3_XXS", Path(d) / "strata-iq3_xxs.json", 8080)
data = script.read_bytes()
self.assertNotIn(b"\r\r\n", data)
self.assertTrue(data.startswith(b"@echo off\r\ntitle Strata IQ3_XXS\r\n"), data[:40])
self.assertTrue(data.endswith(b"if errorlevel 1 pause\r\n"))
if __name__ == "__main__":
unittest.main()