-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_init_java_go.py
More file actions
115 lines (85 loc) · 5 KB
/
test_init_java_go.py
File metadata and controls
115 lines (85 loc) · 5 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from __future__ import annotations
from pathlib import Path
from unittest.mock import Mock, patch
from codeflash.cli_cmds.init_go import collect_go_setup_info
from codeflash.cli_cmds.init_java import collect_java_setup_info, should_modify_java_config
def test_collect_go_setup_info_skip_confirm_uses_defaults(tmp_path: Path, monkeypatch) -> None:
monkeypatch.chdir(tmp_path)
(tmp_path / "go.mod").write_text("module example.com/demo\n\ngo 1.21\n", encoding="utf-8")
get_git_remote = Mock(return_value="origin")
monkeypatch.setattr("codeflash.cli_cmds.init_go._get_git_remote_for_setup", get_git_remote)
monkeypatch.setattr(
"codeflash.cli_cmds.init_config.ask_for_telemetry",
Mock(side_effect=AssertionError("ask_for_telemetry should not be called")),
)
with patch("codeflash.cli_cmds.init_go.inquirer") as mock_inquirer:
setup_info = collect_go_setup_info(skip_confirm=True)
mock_inquirer.prompt.assert_not_called()
get_git_remote.assert_called_once_with(skip_confirm=True)
assert setup_info.git_remote == "origin"
assert setup_info.disable_telemetry is False
def test_collect_go_setup_info_uses_default_telemetry_on_eof(tmp_path: Path, monkeypatch) -> None:
monkeypatch.chdir(tmp_path)
(tmp_path / "go.mod").write_text("module example.com/demo\n\ngo 1.21\n", encoding="utf-8")
get_git_remote = Mock(return_value="origin")
monkeypatch.setattr("codeflash.cli_cmds.init_go._get_git_remote_for_setup", get_git_remote)
with patch("rich.prompt.Confirm.ask", side_effect=EOFError):
setup_info = collect_go_setup_info()
get_git_remote.assert_called_once_with()
assert setup_info.git_remote == "origin"
assert setup_info.disable_telemetry is False
def test_collect_java_setup_info_skip_confirm_uses_defaults(tmp_path: Path, monkeypatch) -> None:
monkeypatch.chdir(tmp_path)
(tmp_path / "build.gradle").write_text("plugins { id 'java' }\n", encoding="utf-8")
(tmp_path / "src" / "main" / "java").mkdir(parents=True)
(tmp_path / "src" / "test" / "java").mkdir(parents=True)
get_git_remote = Mock(return_value="origin")
monkeypatch.setattr("codeflash.cli_cmds.init_java._get_git_remote_for_setup", get_git_remote)
monkeypatch.setattr(
"codeflash.cli_cmds.init_config.ask_for_telemetry",
Mock(side_effect=AssertionError("ask_for_telemetry should not be called")),
)
with patch("codeflash.cli_cmds.init_java.inquirer") as mock_inquirer:
setup_info = collect_java_setup_info(skip_confirm=True)
mock_inquirer.prompt.assert_not_called()
get_git_remote.assert_called_once_with(skip_confirm=True)
assert setup_info.module_root_override is None
assert setup_info.test_root_override is None
assert setup_info.formatter_override is None
assert setup_info.git_remote == "origin"
assert setup_info.disable_telemetry is False
def test_collect_java_setup_info_uses_defaults_on_eof(tmp_path: Path, monkeypatch) -> None:
monkeypatch.chdir(tmp_path)
(tmp_path / "build.gradle").write_text("plugins { id 'java' }\n", encoding="utf-8")
(tmp_path / "src" / "main" / "java").mkdir(parents=True)
(tmp_path / "src" / "test" / "java").mkdir(parents=True)
get_git_remote = Mock(return_value="origin")
monkeypatch.setattr("codeflash.cli_cmds.init_java._get_git_remote_for_setup", get_git_remote)
monkeypatch.setattr("codeflash.cli_cmds.init_config.ask_for_telemetry", Mock(return_value=True))
with patch("codeflash.cli_cmds.init_java.inquirer") as mock_inquirer, patch(
"rich.prompt.Confirm.ask", side_effect=EOFError
):
setup_info = collect_java_setup_info()
mock_inquirer.prompt.assert_not_called()
get_git_remote.assert_called_once_with()
assert setup_info.module_root_override is None
assert setup_info.test_root_override is None
assert setup_info.formatter_override is None
assert setup_info.git_remote == "origin"
assert setup_info.disable_telemetry is False
def test_should_modify_java_config_skip_confirm_skips_reconfigure_prompt(tmp_path: Path, monkeypatch) -> None:
monkeypatch.chdir(tmp_path)
(tmp_path / "build.gradle").write_text("plugins { id 'java' }\n", encoding="utf-8")
(tmp_path / "gradle.properties").write_text("codeflash.moduleRoot=src/main/java\n", encoding="utf-8")
with patch("rich.prompt.Confirm.ask", side_effect=AssertionError("Confirm.ask should not be called")):
should_modify, config = should_modify_java_config(skip_confirm=True)
assert should_modify is False
assert config is None
def test_should_modify_java_config_uses_default_on_eof(tmp_path: Path, monkeypatch) -> None:
monkeypatch.chdir(tmp_path)
(tmp_path / "build.gradle").write_text("plugins { id 'java' }\n", encoding="utf-8")
(tmp_path / "gradle.properties").write_text("codeflash.moduleRoot=src/main/java\n", encoding="utf-8")
with patch("rich.prompt.Confirm.ask", side_effect=EOFError):
should_modify, config = should_modify_java_config()
assert should_modify is False
assert config is None