11import pytest
22from unittest .mock import patch , MagicMock
3- import typer
3+ import click
44import threading
55import time
6+ from click .testing import CliRunner
67
7- from tgit .cli import app , version_callback , main
8+ from tgit .cli import app , version_callback
89
910
1011class TestCLI :
1112 """Test cases for the CLI module"""
1213
1314 def test_app_instance (self ):
14- """Test that app is a Typer instance with correct configuration"""
15- assert isinstance (app , typer . Typer )
16- assert app .info . name == "tgit"
17- assert app .info . help == "TGIT cli"
18- assert app .info . no_args_is_help is True
15+ """Test that app is a Click group with correct configuration"""
16+ assert isinstance (app , click . Group )
17+ assert app .name == "tgit"
18+ assert app .help == "TGIT cli"
19+ assert app .no_args_is_help is True
1920
2021 def test_commands_registered (self ):
2122 """Test that all expected commands are registered"""
2223 # Just verify the app object exists and has the right type
23- # since the command registration details may vary by Typer version
24- assert isinstance (app , typer . Typer )
24+ # since the command registration details may vary by Click version
25+ assert isinstance (app , click . Group )
2526
2627 @patch ("tgit.cli.importlib.metadata.version" )
2728 @patch ("tgit.cli.console.print" )
2829 def test_version_callback_true (self , mock_print , mock_version ):
2930 """Test version callback when value is True"""
3031 mock_version .return_value = "1.0.0"
32+ mock_ctx = MagicMock ()
33+ mock_ctx .resilient_parsing = False
34+ mock_param = MagicMock ()
3135
32- with pytest .raises (typer .Exit ):
33- version_callback (value = True )
36+ version_callback (ctx = mock_ctx , _param = mock_param , value = True )
3437
3538 mock_version .assert_called_once_with ("tgit" )
3639 mock_print .assert_called_once_with ("TGIT - ver.1.0.0" , highlight = False )
40+ mock_ctx .exit .assert_called_once ()
3741
3842 @patch ("tgit.cli.importlib.metadata.version" )
3943 @patch ("tgit.cli.console.print" )
4044 def test_version_callback_false (self , mock_print , mock_version ):
4145 """Test version callback when value is False"""
42- version_callback (value = False )
46+ mock_ctx = MagicMock ()
47+ mock_ctx .resilient_parsing = False
48+ mock_param = MagicMock ()
49+
50+ version_callback (ctx = mock_ctx , _param = mock_param , value = False )
4351
4452 mock_version .assert_not_called ()
4553 mock_print .assert_not_called ()
54+ mock_ctx .exit .assert_not_called ()
4655
4756 @patch ("tgit.cli.threading.Thread" )
48- def test_main_starts_openai_import_thread (self , mock_thread ):
49- """Test that main starts a thread for OpenAI import"""
50- mock_thread_instance = MagicMock ()
51- mock_thread .return_value = mock_thread_instance
52-
53- main (_version = False )
54-
55- mock_thread .assert_called_once ()
56- mock_thread_instance .start .assert_called_once ()
57-
58- @patch ("tgit.cli.threading.Thread" )
59- def test_main_with_version_false (self , mock_thread ):
60- """Test main function with version=False"""
57+ def test_app_starts_openai_import_thread (self , mock_thread ):
58+ """Test that app starts a thread for OpenAI import"""
6159 mock_thread_instance = MagicMock ()
6260 mock_thread .return_value = mock_thread_instance
6361
64- main (_version = False )
62+ # Directly call the app function to test the callback
63+ app .callback ()
6564
66- # Should still start the import thread
65+ # The app should run the callback and start the thread
6766 mock_thread .assert_called_once ()
6867 mock_thread_instance .start .assert_called_once ()
6968
@@ -82,23 +81,8 @@ def mock_import():
8281
8382 assert import_called .is_set ()
8483
85- @patch ("tgit.cli.threading.Thread" )
86- def test_openai_import_with_exception_suppression (self , mock_thread ):
87- """Test that OpenAI import exceptions are suppressed"""
88- # Create a mock thread that we can control
89- mock_thread_instance = MagicMock ()
90- mock_thread .return_value = mock_thread_instance
91-
92- main (_version = False )
93-
94- # Just verify that the thread was created and started
95- mock_thread .assert_called_once ()
96- mock_thread_instance .start .assert_called_once ()
97-
9884 def test_app_callback_registration (self ):
99- """Test that main is registered as app callback"""
100- # The callback should be registered - check if app has the callback mechanism
101- # This may vary by Typer version, so we'll check if the app object is properly configured
102- assert isinstance (app , typer .Typer )
103- # In newer Typer versions, the callback structure might be different
104- # We'll just verify the app exists and is configured correctly
85+ """Test that app is properly configured"""
86+ # Check if app has the callback mechanism
87+ assert isinstance (app , click .Group )
88+ # Verify the app exists and is configured correctly
0 commit comments