Skip to content

Commit 1c2b57c

Browse files
committed
Fix test_get_filelines to use binary mode on Windows
Reverted get_filelines change that was breaking formatter comparisons. Fixed test to write files in binary mode to avoid Windows text mode converting \n to \r\n, which caused test failures.
1 parent f0b4a4e commit 1c2b57c

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

hooks/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,4 @@ def get_filelines(self, filename: str):
205205
self.raise_error(f"File {filename} not found", "Check your path to the file.")
206206
with open(filename, "rb") as f:
207207
filetext = f.read()
208-
# Remove Windows carriage returns before splitting
209-
filetext = filetext.replace(b"\r", b"")
210208
return filetext.split(b"\x0a")

tests/test_utils_functions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,9 @@ def __init__(self):
338338

339339
def test_get_filelines_reads_file(self):
340340
"""Test that get_filelines correctly reads file contents."""
341-
with tempfile.NamedTemporaryFile(mode="w", suffix=".c", delete=False) as f:
342-
f.write("line1\nline2\nline3\n")
341+
# Use binary mode to avoid Windows text mode \n to \r\n conversion
342+
with tempfile.NamedTemporaryFile(mode="wb", suffix=".c", delete=False) as f:
343+
f.write(b"line1\nline2\nline3\n")
343344
temp_file = f.name
344345

345346
try:

0 commit comments

Comments
 (0)