|
8 | 8 |
|
9 | 9 | from codeflash.cli_cmds.init_javascript import ( |
10 | 10 | JsPackageManager, |
| 11 | + ProjectLanguage, |
| 12 | + detect_project_language, |
11 | 13 | determine_js_package_manager, |
12 | 14 | get_package_install_command, |
13 | 15 | should_modify_package_json_config, |
@@ -344,3 +346,95 @@ def test_collect_js_setup_info_skip_confirm(self, tmp_project: Path, monkeypatch |
344 | 346 | assert setup_info.module_root_override is None |
345 | 347 | assert setup_info.formatter_override is None |
346 | 348 | assert setup_info.git_remote == "origin" |
| 349 | + |
| 350 | + |
| 351 | +class TestDetectProjectLanguage: |
| 352 | + """Tests for detect_project_language function.""" |
| 353 | + |
| 354 | + def test_detects_java_from_pom_xml(self, tmp_project: Path) -> None: |
| 355 | + (tmp_project / "pom.xml").write_text("<project/>") |
| 356 | + |
| 357 | + result = detect_project_language(tmp_project) |
| 358 | + |
| 359 | + assert result == ProjectLanguage.JAVA |
| 360 | + |
| 361 | + def test_detects_java_from_build_gradle(self, tmp_project: Path) -> None: |
| 362 | + (tmp_project / "build.gradle").write_text("") |
| 363 | + |
| 364 | + result = detect_project_language(tmp_project) |
| 365 | + |
| 366 | + assert result == ProjectLanguage.JAVA |
| 367 | + |
| 368 | + def test_detects_java_from_build_gradle_kts(self, tmp_project: Path) -> None: |
| 369 | + (tmp_project / "build.gradle.kts").write_text("") |
| 370 | + |
| 371 | + result = detect_project_language(tmp_project) |
| 372 | + |
| 373 | + assert result == ProjectLanguage.JAVA |
| 374 | + |
| 375 | + def test_detects_typescript_from_tsconfig(self, tmp_project: Path) -> None: |
| 376 | + (tmp_project / "tsconfig.json").write_text("{}") |
| 377 | + |
| 378 | + result = detect_project_language(tmp_project) |
| 379 | + |
| 380 | + assert result == ProjectLanguage.TYPESCRIPT |
| 381 | + |
| 382 | + def test_detects_javascript_from_package_json(self, tmp_project: Path) -> None: |
| 383 | + (tmp_project / "package.json").write_text("{}") |
| 384 | + |
| 385 | + result = detect_project_language(tmp_project) |
| 386 | + |
| 387 | + assert result == ProjectLanguage.JAVASCRIPT |
| 388 | + |
| 389 | + def test_detects_python_from_pyproject_toml(self, tmp_project: Path) -> None: |
| 390 | + (tmp_project / "pyproject.toml").write_text("") |
| 391 | + |
| 392 | + result = detect_project_language(tmp_project) |
| 393 | + |
| 394 | + assert result == ProjectLanguage.PYTHON |
| 395 | + |
| 396 | + def test_defaults_to_python_for_empty_directory(self, tmp_project: Path) -> None: |
| 397 | + result = detect_project_language(tmp_project) |
| 398 | + |
| 399 | + assert result == ProjectLanguage.PYTHON |
| 400 | + |
| 401 | + def test_java_takes_priority_over_python(self, tmp_project: Path) -> None: |
| 402 | + (tmp_project / "pom.xml").write_text("<project/>") |
| 403 | + (tmp_project / "pyproject.toml").write_text("") |
| 404 | + |
| 405 | + result = detect_project_language(tmp_project) |
| 406 | + |
| 407 | + assert result == ProjectLanguage.JAVA |
| 408 | + |
| 409 | + def test_java_takes_priority_over_javascript(self, tmp_project: Path) -> None: |
| 410 | + (tmp_project / "build.gradle").write_text("") |
| 411 | + (tmp_project / "package.json").write_text("{}") |
| 412 | + |
| 413 | + result = detect_project_language(tmp_project) |
| 414 | + |
| 415 | + assert result == ProjectLanguage.JAVA |
| 416 | + |
| 417 | + def test_java_takes_priority_over_typescript(self, tmp_project: Path) -> None: |
| 418 | + (tmp_project / "pom.xml").write_text("<project/>") |
| 419 | + (tmp_project / "tsconfig.json").write_text("{}") |
| 420 | + |
| 421 | + result = detect_project_language(tmp_project) |
| 422 | + |
| 423 | + assert result == ProjectLanguage.JAVA |
| 424 | + |
| 425 | + def test_javascript_with_js_indicators_over_python(self, tmp_project: Path) -> None: |
| 426 | + (tmp_project / "package.json").write_text("{}") |
| 427 | + (tmp_project / "pyproject.toml").write_text("") |
| 428 | + (tmp_project / "node_modules").mkdir() |
| 429 | + |
| 430 | + result = detect_project_language(tmp_project) |
| 431 | + |
| 432 | + assert result == ProjectLanguage.JAVASCRIPT |
| 433 | + |
| 434 | + def test_python_over_package_json_without_js_indicators(self, tmp_project: Path) -> None: |
| 435 | + (tmp_project / "package.json").write_text("{}") |
| 436 | + (tmp_project / "pyproject.toml").write_text("") |
| 437 | + |
| 438 | + result = detect_project_language(tmp_project) |
| 439 | + |
| 440 | + assert result == ProjectLanguage.PYTHON |
0 commit comments