Skip to content

Commit ef15f71

Browse files
committed
update test suite
1 parent 72ede6d commit ef15f71

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

tests/test_cmd_init.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
configure_pyproject_toml,
1111
get_formatter_cmds,
1212
get_valid_subdirs,
13-
is_valid_pyproject_toml,
1413
)
14+
from codeflash.cli_cmds.validators import PyprojectTomlValidator
1515

1616

1717
@pytest.fixture
@@ -27,38 +27,39 @@ def test_is_valid_pyproject_toml_with_empty_config(temp_dir: Path) -> None:
2727
"""
2828
)
2929
f.flush()
30-
valid, _, _message = is_valid_pyproject_toml(temp_dir / "pyproject.toml")
31-
assert not valid
32-
assert _message == "Missing required field: 'module_root'"
30+
validator = PyprojectTomlValidator()
31+
result = validator.validate(str(temp_dir / "pyproject.toml"))
32+
assert not result.is_valid
33+
assert "Missing required field: 'module_root'" in result.failure_descriptions[0]
3334

3435

3536
def test_is_valid_pyproject_toml_with_incorrect_module_root(temp_dir: Path) -> None:
3637
with (temp_dir / "pyproject.toml").open(mode="w") as f:
37-
wrong_module_root = temp_dir / "invalid_directory"
3838
f.write(
3939
"""[tool.codeflash]
4040
module-root = "invalid_directory"
4141
"""
4242
)
4343
f.flush()
44-
valid, config, _message = is_valid_pyproject_toml(temp_dir / "pyproject.toml")
45-
assert not valid
46-
assert _message == f"Invalid 'module_root': directory does not exist at {wrong_module_root}"
44+
validator = PyprojectTomlValidator()
45+
result = validator.validate(str(temp_dir / "pyproject.toml"))
46+
assert not result.is_valid
47+
assert "Invalid 'module_root'" in result.failure_descriptions[0]
4748

4849

4950
def test_is_valid_pyproject_toml_with_incorrect_tests_root(temp_dir: Path) -> None:
5051
with (temp_dir / "pyproject.toml").open(mode="w") as f:
51-
wrong_tests_root = temp_dir / "incorrect_tests_root"
5252
f.write(
5353
"""[tool.codeflash]
5454
module-root = "."
5555
tests-root = "incorrect_tests_root"
5656
"""
5757
)
5858
f.flush()
59-
valid, config, _message = is_valid_pyproject_toml(temp_dir / "pyproject.toml")
60-
assert not valid
61-
assert _message == f"Invalid 'tests_root': directory does not exist at {wrong_tests_root}"
59+
validator = PyprojectTomlValidator()
60+
result = validator.validate(str(temp_dir / "pyproject.toml"))
61+
assert not result.is_valid
62+
assert "Invalid 'tests_root'" in result.failure_descriptions[0]
6263

6364

6465
def test_is_valid_pyproject_toml_with_valid_config(temp_dir: Path) -> None:
@@ -71,8 +72,9 @@ def test_is_valid_pyproject_toml_with_valid_config(temp_dir: Path) -> None:
7172
"""
7273
)
7374
f.flush()
74-
valid, config, _message = is_valid_pyproject_toml(temp_dir / "pyproject.toml")
75-
assert valid
75+
validator = PyprojectTomlValidator()
76+
result = validator.validate(str(temp_dir / "pyproject.toml"))
77+
assert result.is_valid
7678

7779

7880
def test_get_formatter_cmd(temp_dir: Path) -> None:
@@ -114,8 +116,9 @@ def test_configure_pyproject_toml_for_cli(temp_dir: Path) -> None:
114116
formatter-cmds = ["black $file"]
115117
"""
116118
)
117-
valid, _, _ = is_valid_pyproject_toml(pyproject_path)
118-
assert valid
119+
validator = PyprojectTomlValidator()
120+
result = validator.validate(str(pyproject_path))
121+
assert result.is_valid
119122

120123

121124
def test_configure_pyproject_toml_for_vscode_with_empty_config(temp_dir: Path) -> None:
@@ -139,8 +142,9 @@ def test_configure_pyproject_toml_for_vscode_with_empty_config(temp_dir: Path) -
139142
formatter-cmds = ["black $file"]
140143
"""
141144
)
142-
valid, _, _ = is_valid_pyproject_toml(pyproject_path)
143-
assert valid
145+
validator = PyprojectTomlValidator()
146+
result = validator.validate(str(pyproject_path))
147+
assert result.is_valid
144148

145149

146150
def test_configure_pyproject_toml_for_vscode_with_existing_config(temp_dir: Path) -> None:
@@ -171,8 +175,9 @@ def test_configure_pyproject_toml_for_vscode_with_existing_config(temp_dir: Path
171175
formatter-cmds = ["disabled"]
172176
"""
173177
)
174-
valid, _, _ = is_valid_pyproject_toml(pyproject_path)
175-
assert valid
178+
validator = PyprojectTomlValidator()
179+
result = validator.validate(str(pyproject_path))
180+
assert result.is_valid
176181

177182

178183
def test_get_valid_subdirs(temp_dir: Path) -> None:

0 commit comments

Comments
 (0)