Skip to content

Commit 8da15f4

Browse files
Alon YeshurunCopilot
andcommitted
fix: address review comments - use mock_repl fixture and naming conventions
- Use mock_repl fixture in TestConfig instead of inline with-patch - Add _success suffix to all TestRuntimeMode test names - Fix test_init_defaults_no_mode_key_succeeds -> _success Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 17e174c commit 8da15f4

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

tests/test_commands/test_config.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313

1414
class TestConfig:
15+
@pytest.fixture
16+
def mock_repl(self):
17+
with patch("fabric_cli.core.fab_interactive.start_interactive_mode") as mock:
18+
yield mock
19+
1520
# region config SET
1621
def test_config_set_success(self, mock_print_done, cli_executor: CLIExecutor):
1722
# Execute command
@@ -173,24 +178,22 @@ def test_config_clear_cache_success(
173178

174179
# region config MODE (deprecated)
175180
def test_config_set_mode_interactive_shows_deprecation_warning(
176-
self, mock_questionary_print, mock_print_warning, cli_executor: CLIExecutor
181+
self, mock_questionary_print, mock_print_warning, mock_repl, cli_executor: CLIExecutor
177182
):
178183
"""Test that 'config set mode interactive' shows deprecation warning and launches REPL."""
179-
with patch("fabric_cli.core.fab_interactive.start_interactive_mode") as mock_repl:
180-
cli_executor.exec_command(f"config set mode {constant.FAB_MODE_INTERACTIVE}")
184+
cli_executor.exec_command(f"config set mode {constant.FAB_MODE_INTERACTIVE}")
181185

182-
mock_print_warning.assert_any_call(DEPRECATION_WARNING)
183-
mock_repl.assert_called_once()
186+
mock_print_warning.assert_any_call(DEPRECATION_WARNING)
187+
mock_repl.assert_called_once()
184188

185189
def test_config_set_mode_command_line_shows_deprecation_warning(
186-
self, mock_questionary_print, mock_print_warning, cli_executor: CLIExecutor
190+
self, mock_questionary_print, mock_print_warning, mock_repl, cli_executor: CLIExecutor
187191
):
188192
"""Test that 'config set mode command_line' shows deprecation warning without launching REPL."""
189-
with patch("fabric_cli.core.fab_interactive.start_interactive_mode") as mock_repl:
190-
cli_executor.exec_command(f"config set mode {constant.FAB_MODE_COMMANDLINE}")
193+
cli_executor.exec_command(f"config set mode {constant.FAB_MODE_COMMANDLINE}")
191194

192-
mock_print_warning.assert_any_call(DEPRECATION_WARNING)
193-
mock_repl.assert_not_called()
195+
mock_print_warning.assert_any_call(DEPRECATION_WARNING)
196+
mock_repl.assert_not_called()
194197

195198
def test_config_get_mode_shows_deprecation_warning(
196199
self, mock_questionary_print, mock_print_warning, cli_executor: CLIExecutor

tests/test_core/test_fab_context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,30 +446,30 @@ class TestRuntimeMode:
446446
def teardown_method(self):
447447
Context()._runtime_mode = fab_constant.FAB_MODE_COMMANDLINE
448448

449-
def test_default_runtime_mode_is_command_line(self):
449+
def test_default_runtime_mode_is_command_line_success(self):
450450
"""Default runtime mode must be COMMANDLINE when no REPL is active."""
451451
assert Context().get_runtime_mode() == fab_constant.FAB_MODE_COMMANDLINE
452452

453-
def test_set_runtime_mode_to_interactive(self):
453+
def test_set_runtime_mode_to_interactive_success(self):
454454
"""set_runtime_mode(INTERACTIVE) should switch the mode."""
455455
Context().set_runtime_mode(fab_constant.FAB_MODE_INTERACTIVE)
456456
assert Context().get_runtime_mode() == fab_constant.FAB_MODE_INTERACTIVE
457457

458-
def test_set_runtime_mode_back_to_command_line(self):
458+
def test_set_runtime_mode_back_to_command_line_success(self):
459459
"""Switching to INTERACTIVE then back to COMMANDLINE must work."""
460460
Context().set_runtime_mode(fab_constant.FAB_MODE_INTERACTIVE)
461461
Context().set_runtime_mode(fab_constant.FAB_MODE_COMMANDLINE)
462462
assert Context().get_runtime_mode() == fab_constant.FAB_MODE_COMMANDLINE
463463

464-
def test_runtime_mode_not_in_config_keys(self):
464+
def test_runtime_mode_not_in_config_keys_success(self):
465465
"""'mode' must no longer appear in FAB_CONFIG_KEYS_TO_VALID_VALUES."""
466466
assert fab_constant.FAB_MODE not in fab_constant.FAB_CONFIG_KEYS_TO_VALID_VALUES
467467

468-
def test_runtime_mode_not_in_config_defaults(self):
468+
def test_runtime_mode_not_in_config_defaults_success(self):
469469
"""'mode' must no longer appear in CONFIG_DEFAULT_VALUES."""
470470
assert fab_constant.FAB_MODE not in fab_constant.CONFIG_DEFAULT_VALUES
471471

472-
def test_runtime_mode_not_module_level(self):
472+
def test_runtime_mode_not_module_level_success(self):
473473
"""Runtime mode must live on Context, not as module-level functions."""
474474
from fabric_cli.core import fab_context as ctx_module
475475
assert not hasattr(ctx_module, "set_runtime_mode")

tests/test_core/test_fab_state_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_init_defaults_removes_mode_key(monkeypatch):
128128
assert result[fab_constant.FAB_CACHE_ENABLED] == "true"
129129

130130

131-
def test_init_defaults_no_mode_key_succeeds(monkeypatch):
131+
def test_init_defaults_no_mode_key_success(monkeypatch):
132132
"""Config without 'mode' must initialize cleanly (distinct from removes_mode_key: verifies no error on absence)."""
133133
config_file = _create_temp_config(monkeypatch, {
134134
fab_constant.FAB_DEBUG_ENABLED: "true",

0 commit comments

Comments
 (0)