mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-08 16:22:38 +08:00
deploy_environment: add CRLF / lone-CR newline tests
Per @guill review on PR #13425: add tests covering Windows-style line endings, since editors often save files with CRLF and we want to confirm the CR never leaks into the returned value. - `_write_env_file` now opens with `newline=""` so the on-disk bytes match the literal string passed in (deterministic across host OSes, no `\n` -> `\r\n` translation on Windows). New tests: - `test_crlf_line_ending`: `"...\r\n"` -> value (no trailing CR). - `test_crlf_multiline_only_first_line_used`: `readline(128)` stops at the translated newline boundary for CRLF lines. - `test_crlf_with_surrounding_whitespace`: leading/trailing spaces + CRLF still yield the bare value. - `test_lone_cr_line_ending`: classic-Mac / legacy editor `"...\r"` is also handled by universal-newlines decoding. 15/15 unit tests pass. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019df5a8-36be-7107-a4af-c7e4f51687df
This commit is contained in:
parent
0e6b6894ed
commit
fe7efc6283
@ -18,8 +18,14 @@ def _reset_cache_and_install_dir(tmp_path, monkeypatch):
|
|||||||
|
|
||||||
|
|
||||||
def _write_env_file(tmp_path, content: str) -> str:
|
def _write_env_file(tmp_path, content: str) -> str:
|
||||||
|
"""Write the env file with exact content (no newline translation).
|
||||||
|
|
||||||
|
`newline=""` disables Python's text-mode newline translation so the bytes
|
||||||
|
on disk match the literal string passed in, regardless of host OS.
|
||||||
|
Newline-style tests (CRLF, lone CR) rely on this.
|
||||||
|
"""
|
||||||
path = os.path.join(str(tmp_path), ".comfy_environment")
|
path = os.path.join(str(tmp_path), ".comfy_environment")
|
||||||
with open(path, "w", encoding="utf-8") as f:
|
with open(path, "w", encoding="utf-8", newline="") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@ -40,6 +46,26 @@ class TestGetDeployEnvironment:
|
|||||||
_write_env_file(tmp_path, "first-line\nsecond-line\n")
|
_write_env_file(tmp_path, "first-line\nsecond-line\n")
|
||||||
assert get_deploy_environment() == "first-line"
|
assert get_deploy_environment() == "first-line"
|
||||||
|
|
||||||
|
def test_crlf_line_ending(self, tmp_path):
|
||||||
|
# Windows editors often save text files with CRLF line endings.
|
||||||
|
# The CR must not end up in the returned value.
|
||||||
|
_write_env_file(tmp_path, "local-desktop2-standalone\r\n")
|
||||||
|
assert get_deploy_environment() == "local-desktop2-standalone"
|
||||||
|
|
||||||
|
def test_crlf_multiline_only_first_line_used(self, tmp_path):
|
||||||
|
_write_env_file(tmp_path, "first-line\r\nsecond-line\r\n")
|
||||||
|
assert get_deploy_environment() == "first-line"
|
||||||
|
|
||||||
|
def test_crlf_with_surrounding_whitespace(self, tmp_path):
|
||||||
|
_write_env_file(tmp_path, " local-desktop2-standalone \r\n")
|
||||||
|
assert get_deploy_environment() == "local-desktop2-standalone"
|
||||||
|
|
||||||
|
def test_lone_cr_line_ending(self, tmp_path):
|
||||||
|
# Classic-Mac / some legacy editors use a bare CR.
|
||||||
|
# Universal-newlines decoding treats it as a line terminator too.
|
||||||
|
_write_env_file(tmp_path, "local-desktop2-standalone\r")
|
||||||
|
assert get_deploy_environment() == "local-desktop2-standalone"
|
||||||
|
|
||||||
def test_empty_file_falls_back_to_default(self, tmp_path):
|
def test_empty_file_falls_back_to_default(self, tmp_path):
|
||||||
_write_env_file(tmp_path, "")
|
_write_env_file(tmp_path, "")
|
||||||
assert get_deploy_environment() == "local-git"
|
assert get_deploy_environment() == "local-git"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user