33from pathlib import Path
44
55import pytest
6+ import tomlkit
67
78from codeflash .cli_cmds .init_config import (
89 CLISetupInfo ,
910 VsCodeSetupInfo ,
1011 configure_pyproject_toml ,
12+ create_empty_pyproject_toml ,
1113 get_formatter_cmds ,
1214 get_valid_subdirs ,
1315 is_valid_pyproject_toml ,
1416)
17+ from codeflash .code_utils .pyproject_utils import infer_minimal_project_name
1518
1619
1720@pytest .fixture
@@ -103,17 +106,14 @@ def test_configure_pyproject_toml_for_cli(temp_dir: Path) -> None:
103106 assert success
104107
105108 config_content = pyproject_path .read_text ()
106- assert (
107- config_content
108- == """[tool.codeflash]
109- # All paths are relative to this pyproject.toml's directory.
110- module-root = "."
111- tests-root = "tests"
112- ignore-paths = []
113- disable-telemetry = true
114- formatter-cmds = ["black $file"]
115- """
116- )
109+ data = tomlkit .parse (config_content )
110+ assert data ["project" ]["name" ] == infer_minimal_project_name (temp_dir )
111+ assert data ["project" ]["version" ] == "0.0.0"
112+ assert data ["tool" ]["codeflash" ]["module-root" ] == "."
113+ assert data ["tool" ]["codeflash" ]["tests-root" ] == "tests"
114+ assert data ["tool" ]["codeflash" ]["ignore-paths" ] == []
115+ assert data ["tool" ]["codeflash" ]["disable-telemetry" ] is True
116+ assert data ["tool" ]["codeflash" ]["formatter-cmds" ] == ["black $file" ]
117117 valid , _ , _ = is_valid_pyproject_toml (pyproject_path )
118118 assert valid
119119
@@ -131,14 +131,12 @@ def test_configure_pyproject_toml_for_vscode_with_empty_config(temp_dir: Path) -
131131 assert success
132132
133133 config_content = pyproject_path .read_text ()
134- assert (
135- config_content
136- == """[tool.codeflash]
137- module-root = "."
138- tests-root = "tests"
139- formatter-cmds = ["black $file"]
140- """
141- )
134+ data = tomlkit .parse (config_content )
135+ assert data ["project" ]["name" ] == infer_minimal_project_name (temp_dir )
136+ assert data ["project" ]["version" ] == "0.0.0"
137+ assert data ["tool" ]["codeflash" ]["module-root" ] == "."
138+ assert data ["tool" ]["codeflash" ]["tests-root" ] == "tests"
139+ assert data ["tool" ]["codeflash" ]["formatter-cmds" ] == ["black $file" ]
142140 valid , _ , _ = is_valid_pyproject_toml (pyproject_path )
143141 assert valid
144142
@@ -162,15 +160,13 @@ def test_configure_pyproject_toml_for_vscode_with_existing_config(temp_dir: Path
162160
163161 config_content = pyproject_path .read_text ()
164162 # the benchmarks-root shouldn't get overwritten
165- assert (
166- config_content
167- == """[tool.codeflash]
168- module-root = "."
169- tests-root = "tests"
170- benchmarks-root = "tests/benchmarks"
171- formatter-cmds = ["disabled"]
172- """
173- )
163+ data = tomlkit .parse (config_content )
164+ assert data ["project" ]["name" ] == infer_minimal_project_name (temp_dir )
165+ assert data ["project" ]["version" ] == "0.0.0"
166+ assert data ["tool" ]["codeflash" ]["module-root" ] == "."
167+ assert data ["tool" ]["codeflash" ]["tests-root" ] == "tests"
168+ assert data ["tool" ]["codeflash" ]["benchmarks-root" ] == "tests/benchmarks"
169+ assert data ["tool" ]["codeflash" ]["formatter-cmds" ] == ["disabled" ]
174170 valid , _ , _ = is_valid_pyproject_toml (pyproject_path )
175171 assert valid
176172
@@ -186,3 +182,18 @@ def test_get_valid_subdirs(temp_dir: Path) -> None:
186182 assert "tests" in dirs
187183 assert "dir1" in dirs
188184 assert "dir2" in dirs
185+
186+
187+ def test_create_empty_pyproject_toml_adds_minimal_project_metadata (
188+ temp_dir : Path , monkeypatch : pytest .MonkeyPatch
189+ ) -> None :
190+ pyproject_path = temp_dir / "pyproject.toml"
191+ monkeypatch .setattr ("codeflash.cli_cmds.init_config.is_LSP_enabled" , lambda : True )
192+ monkeypatch .setattr ("codeflash.cli_cmds.init_config.ph" , lambda * args , ** kwargs : None )
193+
194+ create_empty_pyproject_toml (pyproject_path )
195+
196+ data = tomlkit .parse (pyproject_path .read_text ())
197+ assert data ["project" ]["name" ] == infer_minimal_project_name (temp_dir )
198+ assert data ["project" ]["version" ] == "0.0.0"
199+ assert data ["tool" ]["codeflash" ] == {}
0 commit comments