Skip to content

Commit bb5a5f1

Browse files
author
Test User
committed
🔧 refactor: update tests for CLI handler module
🔧 refactor: update tests for CLI handler module 🔧 Refactor: - Changed import for CommitLoom from main to cli_handler. - Updated all patches in tests to reflect new import paths. 📝 Documentation: - Updated module docstring from 'main CLI module' to 'CLI handler module'. Refactored tests to align with the new structure of the CLI handler module.
1 parent cce8989 commit bb5a5f1

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

tests/test_main.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Tests for main CLI module."""
1+
"""Tests for CLI handler module."""
22

33
import argparse
44
import subprocess
@@ -7,7 +7,8 @@
77

88
import pytest
99

10-
from commitloom.cli.main import CommitLoom, create_parser, main
10+
from commitloom.__main__ import create_parser, main
11+
from commitloom.cli.cli_handler import CommitLoom
1112
from commitloom.core.analyzer import CommitAnalysis, Warning, WarningLevel
1213
from commitloom.core.git import GitError, GitFile
1314
from commitloom.services.ai_service import CommitSuggestion
@@ -17,10 +18,10 @@
1718
def commit_loom():
1819
"""Fixture for CommitLoom instance with mocked dependencies."""
1920
with (
20-
patch("commitloom.cli.main.GitOperations") as mock_git,
21-
patch("commitloom.cli.main.CommitAnalyzer") as mock_analyzer,
22-
patch("commitloom.cli.main.AIService") as mock_ai,
23-
patch("commitloom.cli.main.load_dotenv"),
21+
patch("commitloom.cli.cli_handler.GitOperations") as mock_git,
22+
patch("commitloom.cli.cli_handler.CommitAnalyzer") as mock_analyzer,
23+
patch("commitloom.cli.cli_handler.AIService") as mock_ai,
24+
patch("commitloom.cli.cli_handler.load_dotenv"),
2425
):
2526
instance = CommitLoom()
2627
instance.git = mock_git.return_value
@@ -167,7 +168,7 @@ def test_create_combined_commit(mock_print_success, commit_loom):
167168
mock_print_success.assert_called_once_with("Combined commit created successfully!")
168169

169170

170-
@patch("commitloom.cli.main.console")
171+
@patch("commitloom.cli.cli_handler.console")
171172
def test_run_no_changes(mock_console, commit_loom):
172173
"""Test run when there are no changes."""
173174
commit_loom.git.get_staged_files.return_value = []
@@ -177,7 +178,7 @@ def test_run_no_changes(mock_console, commit_loom):
177178
mock_console.print_warning.assert_called_once_with("No files staged for commit.")
178179

179180

180-
@patch("commitloom.cli.main.console")
181+
@patch("commitloom.cli.cli_handler.console")
181182
def test_run_simple_change(mock_console, commit_loom):
182183
"""Test run with a simple change."""
183184
# Setup test data
@@ -209,7 +210,7 @@ def test_run_simple_change(mock_console, commit_loom):
209210
mock_console.print_success.assert_called()
210211

211212

212-
@patch("commitloom.cli.main.console")
213+
@patch("commitloom.cli.cli_handler.console")
213214
def test_run_with_warnings(mock_console, commit_loom):
214215
"""Test run with complexity warnings."""
215216
# Setup test data
@@ -233,7 +234,7 @@ def test_run_with_warnings(mock_console, commit_loom):
233234
mock_console.print_warnings.assert_called_once()
234235

235236

236-
@patch("commitloom.cli.main.console")
237+
@patch("commitloom.cli.cli_handler.console")
237238
def test_run_with_warnings_continue(mock_console, commit_loom):
238239
"""Test run with warnings when user chooses to continue."""
239240
# Setup test data
@@ -266,7 +267,7 @@ def test_run_with_warnings_continue(mock_console, commit_loom):
266267
commit_loom.git.create_commit.assert_called_once()
267268

268269

269-
@patch("commitloom.cli.main.console")
270+
@patch("commitloom.cli.cli_handler.console")
270271
def test_run_commit_error(mock_console, commit_loom):
271272
"""Test run when commit creation fails."""
272273
# Setup test data
@@ -298,7 +299,7 @@ def test_run_commit_error(mock_console, commit_loom):
298299
mock_console.print_error.assert_called()
299300

300301

301-
@patch("commitloom.cli.main.console")
302+
@patch("commitloom.cli.cli_handler.console")
302303
def test_run_with_exception(mock_console, commit_loom):
303304
"""Test run when an exception occurs."""
304305
commit_loom.git.get_staged_files.side_effect = GitError("Test error")
@@ -335,9 +336,9 @@ def test_cli_arguments():
335336
assert args.verbose
336337

337338

338-
@patch("commitloom.cli.main.console")
339-
@patch("commitloom.cli.main.CommitLoom")
340-
@patch("commitloom.cli.main.create_parser")
339+
@patch("commitloom.__main__.console")
340+
@patch("commitloom.__main__.CommitLoom")
341+
@patch("commitloom.__main__.create_parser")
341342
def test_main_keyboard_interrupt(mock_create_parser, mock_commit_loom, mock_console):
342343
"""Test handling of KeyboardInterrupt in main."""
343344
# Setup mock parser that always returns empty args
@@ -356,8 +357,8 @@ def test_main_keyboard_interrupt(mock_create_parser, mock_commit_loom, mock_cons
356357
mock_console.print_error.assert_called_with("\nOperation cancelled by user.")
357358

358359

359-
@patch("commitloom.cli.main.console")
360-
@patch("commitloom.cli.main.CommitLoom")
360+
@patch("commitloom.__main__.console")
361+
@patch("commitloom.__main__.CommitLoom")
361362
def test_main_exception_verbose(mock_commit_loom, mock_console):
362363
"""Test handling of exceptions in main with verbose logging."""
363364
mock_commit_loom.return_value.run.side_effect = Exception("Test error")

0 commit comments

Comments
 (0)