-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_gradle_strategy.py
More file actions
76 lines (64 loc) · 3.48 KB
/
test_gradle_strategy.py
File metadata and controls
76 lines (64 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import annotations
from typing import TYPE_CHECKING
from unittest.mock import MagicMock, patch
from codeflash.languages.java.gradle_strategy import GradleStrategy
if TYPE_CHECKING:
from pathlib import Path
COD_FLAG = "--configure-on-demand"
MOCK_TARGET = "codeflash.languages.java.test_runner._run_cmd_kill_pg_on_timeout"
class TestConfigureOnDemand:
def test_compile_tests_includes_configure_on_demand(self, tmp_path: Path) -> None:
strategy = GradleStrategy()
with patch.object(strategy, "find_executable", return_value="gradlew"), patch(MOCK_TARGET) as mock_run:
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
strategy.compile_tests(tmp_path, {}, test_module=None)
cmd = mock_run.call_args[0][0]
assert COD_FLAG in cmd
def test_compile_tests_multimodule_includes_configure_on_demand(self, tmp_path: Path) -> None:
strategy = GradleStrategy()
with patch.object(strategy, "find_executable", return_value="gradlew"), patch(MOCK_TARGET) as mock_run:
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
strategy.compile_tests(tmp_path, {}, test_module="core")
cmd = mock_run.call_args[0][0]
assert COD_FLAG in cmd
assert ":core:testClasses" in cmd
def test_compile_source_only_includes_configure_on_demand(self, tmp_path: Path) -> None:
strategy = GradleStrategy()
with patch.object(strategy, "find_executable", return_value="gradlew"), patch(MOCK_TARGET) as mock_run:
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
strategy.compile_source_only(tmp_path, {}, test_module=None)
cmd = mock_run.call_args[0][0]
assert COD_FLAG in cmd
def test_get_test_run_command_includes_configure_on_demand(self, tmp_path: Path) -> None:
strategy = GradleStrategy()
with patch.object(strategy, "find_executable", return_value="gradlew"):
cmd = strategy.get_test_run_command(tmp_path)
assert COD_FLAG in cmd
def test_install_multi_module_deps_includes_configure_on_demand(self, tmp_path: Path) -> None:
strategy = GradleStrategy()
with (
patch.object(strategy, "find_executable", return_value="gradlew"),
patch(MOCK_TARGET) as mock_run,
patch("codeflash.languages.java.gradle_strategy._multimodule_deps_installed", set()),
):
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
strategy.install_multi_module_deps(tmp_path, test_module="core", env={})
cmd = mock_run.call_args[0][0]
assert COD_FLAG in cmd
assert ":core:testClasses" in cmd
def test_run_tests_via_build_tool_includes_configure_on_demand(self, tmp_path: Path) -> None:
strategy = GradleStrategy()
reports_dir = tmp_path / "build" / "test-results" / "test"
reports_dir.mkdir(parents=True, exist_ok=True)
with patch.object(strategy, "find_executable", return_value="gradlew"), patch(MOCK_TARGET) as mock_run:
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
strategy.run_tests_via_build_tool(
build_root=tmp_path,
test_paths=["com.example.TestFoo"],
env={},
timeout=60,
mode="behavior",
test_module=None,
)
cmd = mock_run.call_args[0][0]
assert COD_FLAG in cmd