Skip to content

Commit 468ef10

Browse files
committed
reset test strings to strict
1 parent 25b0639 commit 468ef10

5 files changed

Lines changed: 20 additions & 38 deletions

File tree

tests/test_setup/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Tests for the codeflash.setup module
1+
# Tests for the codeflash.setup module

tests/test_setup/test_config.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""Tests for config schema and config writer."""
22

33
import json
4-
from pathlib import Path
54

6-
import pytest
75
import tomlkit
86

97
from codeflash.setup.config_schema import CodeflashConfig
@@ -310,7 +308,7 @@ def test_fails_if_no_package_json(self, tmp_path):
310308
success, message = _write_package_json(tmp_path, config)
311309

312310
assert success is False
313-
assert "No package.json" in message
311+
assert message == f"No package.json found at {tmp_path}"
314312

315313

316314
class TestWriteConfig:
@@ -326,7 +324,7 @@ def test_writes_to_pyproject_for_python(self, tmp_path):
326324
success, message = write_config(detected)
327325

328326
assert success is True
329-
assert "pyproject.toml" in message
327+
assert message == f"Config saved to {tmp_path / 'pyproject.toml'}"
330328

331329
def test_writes_to_package_json_for_js(self, tmp_path):
332330
"""Should write to package.json for JavaScript projects."""
@@ -394,4 +392,4 @@ def test_fails_if_already_exists(self, tmp_path):
394392
success, message = create_pyproject_toml(tmp_path)
395393

396394
assert success is False
397-
assert "already exists" in message
395+
assert message == f"pyproject.toml already exists at {tmp_path / 'pyproject.toml'}"

tests/test_setup/test_detector.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
"""Tests for the universal project detector."""
22

33
import json
4-
import tempfile
5-
from pathlib import Path
6-
7-
import pytest
8-
import tomlkit
94

105
from codeflash.setup.detector import (
11-
DetectedProject,
12-
_detect_formatter,
136
_detect_js_formatter,
147
_detect_js_module_root,
158
_detect_js_test_runner,
169
_detect_language,
17-
_detect_module_root,
1810
_detect_python_formatter,
1911
_detect_python_module_root,
2012
_detect_python_test_runner,
21-
_detect_test_runner,
2213
_detect_tests_root,
2314
_find_project_root,
2415
detect_project,
@@ -124,7 +115,8 @@ def test_python_detects_src_layout(self, tmp_path):
124115

125116
module_root, detail = _detect_python_module_root(tmp_path)
126117
assert module_root == src_dir
127-
assert "src" in str(module_root)
118+
assert module_root.name == "mypackage"
119+
assert module_root.parent.name == "src"
128120

129121
def test_python_detects_package_at_root(self, tmp_path):
130122
"""Should detect package at project root."""
@@ -386,4 +378,4 @@ def test_returns_false_for_empty_directory(self, tmp_path):
386378
"""Should return False for empty directory."""
387379
has_config, config_type = has_existing_config(tmp_path)
388380
assert has_config is False
389-
assert config_type is None
381+
assert config_type is None

tests/test_setup/test_e2e_setup.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,20 @@
88
"""
99

1010
import json
11-
import os
1211
from argparse import Namespace
13-
from pathlib import Path
14-
from unittest.mock import patch
1512

1613
import pytest
1714
import tomlkit
1815

1916
from codeflash.setup import (
2017
CodeflashConfig,
21-
DetectedProject,
2218
detect_project,
2319
handle_first_run,
2420
has_existing_config,
2521
is_first_run,
2622
write_config,
2723
)
2824

29-
3025
# =============================================================================
3126
# Fixtures for creating different project types
3227
# =============================================================================
@@ -365,7 +360,7 @@ def test_python_src_layout_detection(self, python_src_layout):
365360

366361
assert detected.language == "python"
367362
assert detected.project_root == python_src_layout
368-
assert "myapp" in str(detected.module_root)
363+
assert detected.module_root.name == "myapp"
369364
assert detected.tests_root == python_src_layout / "tests"
370365
assert detected.test_runner == "pytest"
371366
assert any("ruff" in cmd for cmd in detected.formatter_cmds)
@@ -376,15 +371,15 @@ def test_python_flat_layout_detection(self, python_flat_layout):
376371
detected = detect_project(python_flat_layout)
377372

378373
assert detected.language == "python"
379-
assert "myapp" in str(detected.module_root)
374+
assert detected.module_root.name == "myapp"
380375
assert any("black" in cmd for cmd in detected.formatter_cmds)
381376

382377
def test_python_setup_py_detection(self, python_setup_py_project):
383378
"""Should correctly detect legacy setup.py project."""
384379
detected = detect_project(python_setup_py_project)
385380

386381
assert detected.language == "python"
387-
assert "legacyapp" in str(detected.module_root)
382+
assert detected.module_root.name == "legacyapp"
388383

389384
def test_javascript_npm_detection(self, javascript_npm_project):
390385
"""Should correctly detect JavaScript npm project."""
@@ -578,14 +573,14 @@ def test_first_run_python_project(self, python_src_layout, monkeypatch):
578573

579574
assert result is not None
580575
assert result.language == "python"
581-
assert "myapp" in result.module_root
576+
assert result.module_root.endswith("myapp")
582577
assert result.tests_root is not None
583-
assert "tests" in result.tests_root
578+
assert result.tests_root.endswith("tests")
584579
assert result.pytest_cmd == "pytest"
585580

586581
# Config should be written
587582
content = (python_src_layout / "pyproject.toml").read_text()
588-
assert "codeflash" in content
583+
assert "[tool.codeflash]" in content
589584

590585
def test_first_run_javascript_project(self, javascript_npm_project, monkeypatch):
591586
"""Should complete first-run for JavaScript project."""
@@ -596,7 +591,7 @@ def test_first_run_javascript_project(self, javascript_npm_project, monkeypatch)
596591

597592
assert result is not None
598593
assert result.language == "javascript"
599-
assert "src" in result.module_root
594+
assert result.module_root.endswith("src")
600595
assert result.pytest_cmd == "jest" # Maps to test_runner
601596

602597
def test_first_run_typescript_project(self, typescript_project, monkeypatch):

tests/test_setup/test_first_run.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import json
44
import os
55
from argparse import Namespace
6-
from pathlib import Path
7-
from unittest.mock import MagicMock, patch
8-
9-
import pytest
6+
from unittest.mock import patch
107

118
from codeflash.setup.first_run import (
129
_handle_api_key,
@@ -247,15 +244,15 @@ def test_full_python_first_run(self, tmp_path, monkeypatch):
247244

248245
assert result is not None
249246
assert result.language == "python"
250-
assert "myapp" in result.module_root
251-
assert "tests" in result.tests_root
247+
assert result.module_root.endswith("myapp")
248+
assert result.tests_root.endswith("tests")
252249

253250
# Verify config was written
254251
import tomlkit
255252

256253
content = (tmp_path / "pyproject.toml").read_text()
257254
data = tomlkit.parse(content)
258-
assert "codeflash" in data.get("tool", {})
255+
assert "codeflash" in data["tool"]
259256

260257
def test_full_javascript_first_run(self, tmp_path, monkeypatch):
261258
"""Should complete full first-run for JavaScript project."""
@@ -274,7 +271,7 @@ def test_full_javascript_first_run(self, tmp_path, monkeypatch):
274271

275272
assert result is not None
276273
assert result.language == "javascript"
277-
assert "src" in result.module_root
274+
assert result.module_root.endswith("src")
278275
assert result.pytest_cmd == "jest" # test_runner mapped to pytest_cmd
279276

280277
def test_subsequent_run_uses_saved_config(self, tmp_path, monkeypatch):
@@ -287,4 +284,4 @@ def test_subsequent_run_uses_saved_config(self, tmp_path, monkeypatch):
287284
monkeypatch.chdir(tmp_path)
288285

289286
# Should not be first run
290-
assert is_first_run(tmp_path) is False
287+
assert is_first_run(tmp_path) is False

0 commit comments

Comments
 (0)