Skip to content

Commit 28755c0

Browse files
committed
fix windows tests
1 parent b30a52b commit 28755c0

6 files changed

Lines changed: 13 additions & 10 deletions

File tree

codeflash/code_utils/config_js.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,21 @@ def detect_module_root(project_root: Path, package_data: dict[str, Any]) -> str:
8181
if entry_path and isinstance(entry_path, str):
8282
parent = Path(entry_path).parent
8383
if parent != Path() and (project_root / parent).is_dir():
84-
return str(parent)
84+
return parent.as_posix()
8585

8686
# Check module field (ESM)
8787
module_field = package_data.get("module")
8888
if module_field and isinstance(module_field, str):
8989
parent = Path(module_field).parent
9090
if parent != Path() and (project_root / parent).is_dir():
91-
return str(parent)
91+
return parent.as_posix()
9292

9393
# Check main field (CJS)
9494
main_field = package_data.get("main")
9595
if main_field and isinstance(main_field, str):
9696
parent = Path(main_field).parent
9797
if parent != Path() and (project_root / parent).is_dir():
98-
return str(parent)
98+
return parent.as_posix()
9999

100100
# Check for src/ directory convention
101101
if (project_root / "src").is_dir():

codeflash/languages/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ class TestInfo:
177177
@property
178178
def full_test_path(self) -> str:
179179
"""Get full test path in pytest format (file::class::function)."""
180+
file_path = self.test_file.as_posix()
180181
if self.test_class:
181-
return f"{self.test_file}::{self.test_class}::{self.test_name}"
182-
return f"{self.test_file}::{self.test_name}"
182+
return f"{file_path}::{self.test_class}::{self.test_name}"
183+
return f"{file_path}::{self.test_name}"
183184

184185

185186
@dataclass

tests/code_utils/test_config_js.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import json
6+
import sys
67
from pathlib import Path
78

89
import pytest
@@ -72,6 +73,7 @@ def test_returns_none_for_nonexistent_file(self, tmp_path: Path) -> None:
7273

7374
assert result is None
7475

76+
@pytest.mark.skipif(sys.platform == "win32", reason="chmod doesn't restrict read access on Windows")
7577
def test_returns_none_for_unreadable_file(self, tmp_path: Path) -> None:
7678
"""Should return None if file cannot be read."""
7779
package_json = tmp_path / "package.json"

tests/test_languages/test_javascript_instrumentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_line_profiler_generates_init_code(self):
3535
assert profiler.profiler_var in init_code
3636
assert "hit" in init_code # Changed from recordLine to hit
3737
assert "save" in init_code
38-
assert str(output_file) in init_code
38+
assert output_file.as_posix() in init_code
3939

4040
def test_line_profiler_instruments_simple_function(self):
4141
"""Test line profiler can instrument a simple function."""
@@ -101,7 +101,7 @@ def test_tracer_generates_init_code(self):
101101
assert tracer.tracer_var in init_code
102102
assert "serialize" in init_code
103103
assert "wrap" in init_code
104-
assert str(output_db) in init_code
104+
assert output_db.as_posix() in init_code
105105

106106
def test_tracer_instruments_simple_function(self):
107107
"""Test tracer can instrument a simple function."""

tests/test_languages/test_javascript_test_discovery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ def test_circular_imports(self, js_support):
10031003

10041004
def test_unicode_in_test_names(self, js_support):
10051005
"""Test handling of unicode characters in test names."""
1006-
with tempfile.NamedTemporaryFile(suffix=".test.js", mode="w", delete=False) as f:
1006+
with tempfile.NamedTemporaryFile(suffix=".test.js", mode="w", delete=False, encoding="utf-8") as f:
10071007
f.write("""
10081008
test('handles emoji 🎉', () => {});
10091009
describe('日本語テスト', () => {
@@ -1013,7 +1013,7 @@ def test_unicode_in_test_names(self, js_support):
10131013
f.flush()
10141014
file_path = Path(f.name)
10151015

1016-
source = file_path.read_text()
1016+
source = file_path.read_text(encoding="utf-8")
10171017
from codeflash.languages.treesitter_utils import get_analyzer_for_file
10181018
analyzer = get_analyzer_for_file(file_path)
10191019
test_names = js_support._find_jest_tests(source, analyzer)

tests/test_languages/test_language_parity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def js_support():
288288

289289
def write_temp_file(content: str, suffix: str) -> Path:
290290
"""Write content to a temporary file and return the path."""
291-
with tempfile.NamedTemporaryFile(suffix=suffix, mode="w", delete=False) as f:
291+
with tempfile.NamedTemporaryFile(suffix=suffix, mode="w", delete=False, encoding="utf-8") as f:
292292
f.write(content)
293293
f.flush()
294294
return Path(f.name)

0 commit comments

Comments
 (0)