|
4 | 4 |
|
5 | 5 | from usethis._config_file import files_manager |
6 | 6 | from usethis._integrations.file.pyproject_toml.io_ import PyprojectTOMLManager |
| 7 | +from usethis._integrations.pre_commit.schema import Language |
7 | 8 | from usethis._test import change_cwd |
8 | 9 | from usethis._tool.config import ConfigEntry, ConfigItem |
9 | 10 | from usethis._tool.impl.deptry import DeptryTool |
@@ -268,3 +269,102 @@ def test_pyproject_toml_exists(self, tmp_path: Path): |
268 | 269 |
|
269 | 270 | # Assert |
270 | 271 | assert (tmp_path / "pyproject.toml").exists() |
| 272 | + |
| 273 | + class TestGetPreCommitConfig: |
| 274 | + def test_uses_system_language_when_no_minimum_version(self, tmp_path: Path): |
| 275 | + # Arrange |
| 276 | + (tmp_path / "pyproject.toml").write_text("""\ |
| 277 | +[project] |
| 278 | +name = "test-project" |
| 279 | +""") |
| 280 | + (tmp_path / "src").mkdir() |
| 281 | + (tmp_path / "src" / "test_project").mkdir() |
| 282 | + (tmp_path / "src" / "test_project" / "__init__.py").touch() |
| 283 | + |
| 284 | + # Act |
| 285 | + with change_cwd(tmp_path), files_manager(): |
| 286 | + result = DeptryTool().get_pre_commit_config() |
| 287 | + |
| 288 | + # Assert |
| 289 | + assert result.repo_configs is not None |
| 290 | + assert result.repo_configs[0].repo.hooks is not None |
| 291 | + assert result.repo_configs[0].repo.hooks[0].language == Language("system") |
| 292 | + |
| 293 | + def test_uses_system_language_when_minimum_version_below_4_4_0( |
| 294 | + self, tmp_path: Path |
| 295 | + ): |
| 296 | + # Arrange |
| 297 | + (tmp_path / "pyproject.toml").write_text("""\ |
| 298 | +[project] |
| 299 | +name = "test-project" |
| 300 | +""") |
| 301 | + (tmp_path / ".pre-commit-config.yaml").write_text("""\ |
| 302 | +minimum_pre_commit_version: '4.3.0' |
| 303 | +repos: [] |
| 304 | +""") |
| 305 | + (tmp_path / "src").mkdir() |
| 306 | + (tmp_path / "src" / "test_project").mkdir() |
| 307 | + (tmp_path / "src" / "test_project" / "__init__.py").touch() |
| 308 | + |
| 309 | + # Act |
| 310 | + with change_cwd(tmp_path), files_manager(): |
| 311 | + result = DeptryTool().get_pre_commit_config() |
| 312 | + |
| 313 | + # Assert |
| 314 | + assert result.repo_configs is not None |
| 315 | + assert result.repo_configs[0].repo.hooks is not None |
| 316 | + assert result.repo_configs[0].repo.hooks[0].language == Language("system") |
| 317 | + |
| 318 | + def test_uses_unsupported_language_when_minimum_version_is_4_4_0( |
| 319 | + self, tmp_path: Path |
| 320 | + ): |
| 321 | + # Arrange |
| 322 | + (tmp_path / "pyproject.toml").write_text("""\ |
| 323 | +[project] |
| 324 | +name = "test-project" |
| 325 | +""") |
| 326 | + (tmp_path / ".pre-commit-config.yaml").write_text("""\ |
| 327 | +minimum_pre_commit_version: '4.4.0' |
| 328 | +repos: [] |
| 329 | +""") |
| 330 | + (tmp_path / "src").mkdir() |
| 331 | + (tmp_path / "src" / "test_project").mkdir() |
| 332 | + (tmp_path / "src" / "test_project" / "__init__.py").touch() |
| 333 | + |
| 334 | + # Act |
| 335 | + with change_cwd(tmp_path), files_manager(): |
| 336 | + result = DeptryTool().get_pre_commit_config() |
| 337 | + |
| 338 | + # Assert |
| 339 | + assert result.repo_configs is not None |
| 340 | + assert result.repo_configs[0].repo.hooks is not None |
| 341 | + assert result.repo_configs[0].repo.hooks[0].language == Language( |
| 342 | + "unsupported" |
| 343 | + ) |
| 344 | + |
| 345 | + def test_uses_unsupported_language_when_minimum_version_above_4_4_0( |
| 346 | + self, tmp_path: Path |
| 347 | + ): |
| 348 | + # Arrange |
| 349 | + (tmp_path / "pyproject.toml").write_text("""\ |
| 350 | +[project] |
| 351 | +name = "test-project" |
| 352 | +""") |
| 353 | + (tmp_path / ".pre-commit-config.yaml").write_text("""\ |
| 354 | +minimum_pre_commit_version: '4.5.0' |
| 355 | +repos: [] |
| 356 | +""") |
| 357 | + (tmp_path / "src").mkdir() |
| 358 | + (tmp_path / "src" / "test_project").mkdir() |
| 359 | + (tmp_path / "src" / "test_project" / "__init__.py").touch() |
| 360 | + |
| 361 | + # Act |
| 362 | + with change_cwd(tmp_path), files_manager(): |
| 363 | + result = DeptryTool().get_pre_commit_config() |
| 364 | + |
| 365 | + # Assert |
| 366 | + assert result.repo_configs is not None |
| 367 | + assert result.repo_configs[0].repo.hooks is not None |
| 368 | + assert result.repo_configs[0].repo.hooks[0].language == Language( |
| 369 | + "unsupported" |
| 370 | + ) |
0 commit comments