44import sys
55
66from tgit .utils import run_command , simple_run_command , get_commit_command , type_emojis
7+ from tgit .types import TGitSettings , CommitSettings
78
89
910class TestRunCommand :
@@ -16,9 +17,14 @@ def test_run_command_user_confirms(self, mock_confirm, mock_popen):
1617 process_mock = mock_popen .return_value
1718 process_mock .communicate .return_value = (b"output" , b"" )
1819 process_mock .returncode = 0
20+ settings = TGitSettings (
21+ commit = CommitSettings (emoji = False , types = []),
22+ api_key = "" , api_url = "" , model = "" ,
23+ show_command = False , skip_confirm = False
24+ )
1925
2026 # Act
21- run_command ("echo 'test'" )
27+ run_command (settings , "echo 'test'" )
2228
2329 # Assert
2430 mock_confirm .assert_called_once_with ("Do you want to continue?" , default = True )
@@ -30,89 +36,102 @@ def test_run_command_user_cancels(self, mock_confirm, mock_popen):
3036 """Test run_command when user cancels execution."""
3137 # Arrange
3238 mock_confirm .return_value .ask .return_value = False
39+ settings = TGitSettings (
40+ commit = CommitSettings (emoji = False , types = []),
41+ api_key = "" , api_url = "" , model = "" ,
42+ show_command = False , skip_confirm = False
43+ )
3344
3445 # Act
35- run_command ("echo 'test'" )
46+ run_command (settings , "echo 'test'" )
3647
3748 # Assert
3849 mock_confirm .assert_called_once_with ("Do you want to continue?" , default = True )
3950 mock_popen .assert_not_called ()
4051
41- @patch ("tgit.utils.settings" )
4252 @patch ("tgit.utils.subprocess.Popen" )
4353 @patch ("tgit.utils.questionary.confirm" )
44- def test_run_command_skip_confirm (self , mock_confirm , mock_popen , mock_settings ):
54+ def test_run_command_skip_confirm (self , mock_confirm , mock_popen ):
4555 """Test run_command when skip_confirm is True."""
4656 # Arrange
47- mock_settings .skip_confirm = True
48- mock_settings .show_command = False
57+ settings = TGitSettings (
58+ commit = CommitSettings (emoji = False , types = []),
59+ api_key = "" , api_url = "" , model = "" ,
60+ show_command = False , skip_confirm = True
61+ )
4962 process_mock = mock_popen .return_value
5063 process_mock .communicate .return_value = (b"output" , b"" )
5164 process_mock .returncode = 0
5265
5366 # Act
54- run_command ("echo 'test'" )
67+ run_command (settings , "echo 'test'" )
5568
5669 # Assert
5770 mock_confirm .assert_not_called ()
5871 mock_popen .assert_called_once ()
5972
60- @patch ("tgit.utils.settings" )
6173 @patch ("tgit.utils.console.print" )
6274 @patch ("tgit.utils.subprocess.Popen" )
6375 @patch ("tgit.utils.questionary.confirm" )
64- def test_run_command_show_command (self , mock_confirm , mock_popen , mock_console_print , mock_settings ):
76+ def test_run_command_show_command (self , mock_confirm , mock_popen , mock_console_print ):
6577 """Test run_command when show_command is True."""
6678 # Arrange
67- mock_settings .show_command = True
68- mock_settings .skip_confirm = False
79+ settings = TGitSettings (
80+ commit = CommitSettings (emoji = False , types = []),
81+ api_key = "" , api_url = "" , model = "" ,
82+ show_command = True , skip_confirm = False
83+ )
6984 mock_confirm .return_value .ask .return_value = True
7085 process_mock = mock_popen .return_value
7186 process_mock .communicate .return_value = (b"output" , b"" )
7287 process_mock .returncode = 0
7388
7489 # Act
75- run_command ("echo 'test'" )
90+ run_command (settings , "echo 'test'" )
7691
7792 # Assert
7893 assert mock_console_print .call_count >= 1
7994 mock_confirm .assert_called_once ()
8095 mock_popen .assert_called_once ()
8196
82- @patch ("tgit.utils.settings" )
8397 @patch ("tgit.utils.subprocess.Popen" )
8498 @patch ("tgit.utils.questionary.confirm" )
8599 @patch ("tgit.utils.sys.stderr.write" )
86- def test_run_command_error_handling (self , mock_stderr_write , mock_confirm , mock_popen , mock_settings ):
100+ def test_run_command_error_handling (self , mock_stderr_write , mock_confirm , mock_popen ):
87101 """Test run_command error handling."""
88102 # Arrange
89- mock_settings .skip_confirm = True
90- mock_settings .show_command = False
103+ settings = TGitSettings (
104+ commit = CommitSettings (emoji = False , types = []),
105+ api_key = "" , api_url = "" , model = "" ,
106+ show_command = False , skip_confirm = True
107+ )
91108 mock_confirm .return_value .ask .return_value = True
92109 process_mock = mock_popen .return_value
93110 process_mock .communicate .return_value = (b"" , b"error message" )
94111 process_mock .returncode = 1
95112
96113 # Act
97- run_command ("failing command" )
114+ run_command (settings , "failing command" )
98115
99116 # Assert
100117 mock_stderr_write .assert_called_once_with ("error message" )
101118
102- @patch ("tgit.utils.settings" )
103119 @patch ("tgit.utils.subprocess.Popen" )
104120 @patch ("tgit.utils.questionary.confirm" )
105- def test_run_command_multiple_commands (self , mock_confirm , mock_popen , mock_settings ):
121+ def test_run_command_multiple_commands (self , mock_confirm , mock_popen ):
106122 """Test run_command with multiple commands."""
107123 # Arrange
108- mock_settings .skip_confirm = True
109- mock_settings .show_command = False
124+ settings = TGitSettings (
125+ commit = CommitSettings (emoji = False , types = []),
126+ api_key = "" , api_url = "" , model = "" ,
127+ show_command = False , skip_confirm = True
128+ )
110129 process_mock = mock_popen .return_value
111130 process_mock .communicate .return_value = (b"output" , b"" )
112131 process_mock .returncode = 0
113132
114133 # Act
115- run_command ("echo 'first'\n echo 'second'" )
134+ run_command (settings , "echo 'first'\n echo 'second'" )
116135
117136 # Assert
118137 assert mock_popen .call_count == 2
0 commit comments