reset test strings to strict

This commit is contained in:
Sarthak Agarwal 2026-01-31 19:02:28 +05:30
parent 25b063914e
commit 468ef10b9e
5 changed files with 20 additions and 38 deletions

View file

@ -1 +1 @@
# Tests for the codeflash.setup module
# Tests for the codeflash.setup module

View file

@ -1,9 +1,7 @@
"""Tests for config schema and config writer."""
import json
from pathlib import Path
import pytest
import tomlkit
from codeflash.setup.config_schema import CodeflashConfig
@ -310,7 +308,7 @@ class TestWritePackageJson:
success, message = _write_package_json(tmp_path, config)
assert success is False
assert "No package.json" in message
assert message == f"No package.json found at {tmp_path}"
class TestWriteConfig:
@ -326,7 +324,7 @@ class TestWriteConfig:
success, message = write_config(detected)
assert success is True
assert "pyproject.toml" in message
assert message == f"Config saved to {tmp_path / 'pyproject.toml'}"
def test_writes_to_package_json_for_js(self, tmp_path):
"""Should write to package.json for JavaScript projects."""
@ -394,4 +392,4 @@ class TestCreatePyprojectToml:
success, message = create_pyproject_toml(tmp_path)
assert success is False
assert "already exists" in message
assert message == f"pyproject.toml already exists at {tmp_path / 'pyproject.toml'}"

View file

@ -1,24 +1,15 @@
"""Tests for the universal project detector."""
import json
import tempfile
from pathlib import Path
import pytest
import tomlkit
from codeflash.setup.detector import (
DetectedProject,
_detect_formatter,
_detect_js_formatter,
_detect_js_module_root,
_detect_js_test_runner,
_detect_language,
_detect_module_root,
_detect_python_formatter,
_detect_python_module_root,
_detect_python_test_runner,
_detect_test_runner,
_detect_tests_root,
_find_project_root,
detect_project,
@ -124,7 +115,8 @@ class TestDetectModuleRoot:
module_root, detail = _detect_python_module_root(tmp_path)
assert module_root == src_dir
assert "src" in str(module_root)
assert module_root.name == "mypackage"
assert module_root.parent.name == "src"
def test_python_detects_package_at_root(self, tmp_path):
"""Should detect package at project root."""
@ -386,4 +378,4 @@ class TestHasExistingConfig:
"""Should return False for empty directory."""
has_config, config_type = has_existing_config(tmp_path)
assert has_config is False
assert config_type is None
assert config_type is None

View file

@ -8,17 +8,13 @@ These tests validate the complete setup experience across different:
"""
import json
import os
from argparse import Namespace
from pathlib import Path
from unittest.mock import patch
import pytest
import tomlkit
from codeflash.setup import (
CodeflashConfig,
DetectedProject,
detect_project,
handle_first_run,
has_existing_config,
@ -26,7 +22,6 @@ from codeflash.setup import (
write_config,
)
# =============================================================================
# Fixtures for creating different project types
# =============================================================================
@ -365,7 +360,7 @@ class TestE2EDetection:
assert detected.language == "python"
assert detected.project_root == python_src_layout
assert "myapp" in str(detected.module_root)
assert detected.module_root.name == "myapp"
assert detected.tests_root == python_src_layout / "tests"
assert detected.test_runner == "pytest"
assert any("ruff" in cmd for cmd in detected.formatter_cmds)
@ -376,7 +371,7 @@ class TestE2EDetection:
detected = detect_project(python_flat_layout)
assert detected.language == "python"
assert "myapp" in str(detected.module_root)
assert detected.module_root.name == "myapp"
assert any("black" in cmd for cmd in detected.formatter_cmds)
def test_python_setup_py_detection(self, python_setup_py_project):
@ -384,7 +379,7 @@ class TestE2EDetection:
detected = detect_project(python_setup_py_project)
assert detected.language == "python"
assert "legacyapp" in str(detected.module_root)
assert detected.module_root.name == "legacyapp"
def test_javascript_npm_detection(self, javascript_npm_project):
"""Should correctly detect JavaScript npm project."""
@ -578,14 +573,14 @@ class TestE2EFirstRunExperience:
assert result is not None
assert result.language == "python"
assert "myapp" in result.module_root
assert result.module_root.endswith("myapp")
assert result.tests_root is not None
assert "tests" in result.tests_root
assert result.tests_root.endswith("tests")
assert result.pytest_cmd == "pytest"
# Config should be written
content = (python_src_layout / "pyproject.toml").read_text()
assert "codeflash" in content
assert "[tool.codeflash]" in content
def test_first_run_javascript_project(self, javascript_npm_project, monkeypatch):
"""Should complete first-run for JavaScript project."""
@ -596,7 +591,7 @@ class TestE2EFirstRunExperience:
assert result is not None
assert result.language == "javascript"
assert "src" in result.module_root
assert result.module_root.endswith("src")
assert result.pytest_cmd == "jest" # Maps to test_runner
def test_first_run_typescript_project(self, typescript_project, monkeypatch):

View file

@ -3,10 +3,7 @@
import json
import os
from argparse import Namespace
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
from unittest.mock import patch
from codeflash.setup.first_run import (
_handle_api_key,
@ -247,15 +244,15 @@ class TestFirstRunIntegration:
assert result is not None
assert result.language == "python"
assert "myapp" in result.module_root
assert "tests" in result.tests_root
assert result.module_root.endswith("myapp")
assert result.tests_root.endswith("tests")
# Verify config was written
import tomlkit
content = (tmp_path / "pyproject.toml").read_text()
data = tomlkit.parse(content)
assert "codeflash" in data.get("tool", {})
assert "codeflash" in data["tool"]
def test_full_javascript_first_run(self, tmp_path, monkeypatch):
"""Should complete full first-run for JavaScript project."""
@ -274,7 +271,7 @@ class TestFirstRunIntegration:
assert result is not None
assert result.language == "javascript"
assert "src" in result.module_root
assert result.module_root.endswith("src")
assert result.pytest_cmd == "jest" # test_runner mapped to pytest_cmd
def test_subsequent_run_uses_saved_config(self, tmp_path, monkeypatch):
@ -287,4 +284,4 @@ class TestFirstRunIntegration:
monkeypatch.chdir(tmp_path)
# Should not be first run
assert is_first_run(tmp_path) is False
assert is_first_run(tmp_path) is False