1
- """Tests for main CLI module."""
1
+ """Tests for CLI handler module."""
2
2
3
3
import argparse
4
4
import subprocess
7
7
8
8
import pytest
9
9
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
11
12
from commitloom .core .analyzer import CommitAnalysis , Warning , WarningLevel
12
13
from commitloom .core .git import GitError , GitFile
13
14
from commitloom .services .ai_service import CommitSuggestion
17
18
def commit_loom ():
18
19
"""Fixture for CommitLoom instance with mocked dependencies."""
19
20
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" ),
24
25
):
25
26
instance = CommitLoom ()
26
27
instance .git = mock_git .return_value
@@ -167,7 +168,7 @@ def test_create_combined_commit(mock_print_success, commit_loom):
167
168
mock_print_success .assert_called_once_with ("Combined commit created successfully!" )
168
169
169
170
170
- @patch ("commitloom.cli.main .console" )
171
+ @patch ("commitloom.cli.cli_handler .console" )
171
172
def test_run_no_changes (mock_console , commit_loom ):
172
173
"""Test run when there are no changes."""
173
174
commit_loom .git .get_staged_files .return_value = []
@@ -177,7 +178,7 @@ def test_run_no_changes(mock_console, commit_loom):
177
178
mock_console .print_warning .assert_called_once_with ("No files staged for commit." )
178
179
179
180
180
- @patch ("commitloom.cli.main .console" )
181
+ @patch ("commitloom.cli.cli_handler .console" )
181
182
def test_run_simple_change (mock_console , commit_loom ):
182
183
"""Test run with a simple change."""
183
184
# Setup test data
@@ -209,7 +210,7 @@ def test_run_simple_change(mock_console, commit_loom):
209
210
mock_console .print_success .assert_called ()
210
211
211
212
212
- @patch ("commitloom.cli.main .console" )
213
+ @patch ("commitloom.cli.cli_handler .console" )
213
214
def test_run_with_warnings (mock_console , commit_loom ):
214
215
"""Test run with complexity warnings."""
215
216
# Setup test data
@@ -233,7 +234,7 @@ def test_run_with_warnings(mock_console, commit_loom):
233
234
mock_console .print_warnings .assert_called_once ()
234
235
235
236
236
- @patch ("commitloom.cli.main .console" )
237
+ @patch ("commitloom.cli.cli_handler .console" )
237
238
def test_run_with_warnings_continue (mock_console , commit_loom ):
238
239
"""Test run with warnings when user chooses to continue."""
239
240
# Setup test data
@@ -266,7 +267,7 @@ def test_run_with_warnings_continue(mock_console, commit_loom):
266
267
commit_loom .git .create_commit .assert_called_once ()
267
268
268
269
269
- @patch ("commitloom.cli.main .console" )
270
+ @patch ("commitloom.cli.cli_handler .console" )
270
271
def test_run_commit_error (mock_console , commit_loom ):
271
272
"""Test run when commit creation fails."""
272
273
# Setup test data
@@ -298,7 +299,7 @@ def test_run_commit_error(mock_console, commit_loom):
298
299
mock_console .print_error .assert_called ()
299
300
300
301
301
- @patch ("commitloom.cli.main .console" )
302
+ @patch ("commitloom.cli.cli_handler .console" )
302
303
def test_run_with_exception (mock_console , commit_loom ):
303
304
"""Test run when an exception occurs."""
304
305
commit_loom .git .get_staged_files .side_effect = GitError ("Test error" )
@@ -335,9 +336,9 @@ def test_cli_arguments():
335
336
assert args .verbose
336
337
337
338
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" )
341
342
def test_main_keyboard_interrupt (mock_create_parser , mock_commit_loom , mock_console ):
342
343
"""Test handling of KeyboardInterrupt in main."""
343
344
# 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
356
357
mock_console .print_error .assert_called_with ("\n Operation cancelled by user." )
357
358
358
359
359
- @patch ("commitloom.cli.main .console" )
360
- @patch ("commitloom.cli.main .CommitLoom" )
360
+ @patch ("commitloom.__main__ .console" )
361
+ @patch ("commitloom.__main__ .CommitLoom" )
361
362
def test_main_exception_verbose (mock_commit_loom , mock_console ):
362
363
"""Test handling of exceptions in main with verbose logging."""
363
364
mock_commit_loom .return_value .run .side_effect = Exception ("Test error" )
0 commit comments