11from subprocess import CompletedProcess
2- from unittest .mock import patch
2+ from unittest .mock import patch , MagicMock
33
44import pytest
55from repo_smith .command_result import CommandResult
88
99
1010def test_tag_with_annotate ():
11+ repo = MagicMock ()
1112 with patch .object (
1213 Helper ,
1314 "run" ,
1415 return_value = CommandResult (
1516 CompletedProcess (["git" , "tag" , "v0.1.0" , "-a" ], returncode = 0 )
1617 ),
1718 ) as mock_helper :
18- gh = GitHelper (False )
19+ gh = GitHelper (repo , False )
1920 gh .tag ("v0.1.0" , annotate = True )
2021 mock_helper .assert_called_with (["git" , "tag" , "v0.1.0" , "-a" ])
2122
2223
2324def test_tag_with_force ():
25+ repo = MagicMock ()
2426 with patch .object (
2527 Helper ,
2628 "run" ,
2729 return_value = CommandResult (
2830 CompletedProcess (["git" , "tag" , "v0.1.0" , "-f" ], returncode = 0 )
2931 ),
3032 ) as mock_helper :
31- gh = GitHelper (False )
33+ gh = GitHelper (repo , False )
3234 gh .tag ("v0.1.0" , force = True )
3335 mock_helper .assert_called_with (["git" , "tag" , "v0.1.0" , "-f" ])
3436
3537
3638def test_tag_with_message ():
39+ repo = MagicMock ()
3740 with patch .object (
3841 Helper ,
3942 "run" ,
@@ -43,14 +46,15 @@ def test_tag_with_message():
4346 )
4447 ),
4548 ) as mock_helper :
46- gh = GitHelper (False )
49+ gh = GitHelper (repo , False )
4750 gh .tag ("v0.1.0" , message = "This is a message." )
4851 mock_helper .assert_called_with (
4952 ["git" , "tag" , "v0.1.0" , "-m" , "This is a message." ]
5053 )
5154
5255
5356def test_tag_with_multiple_flags ():
57+ repo = MagicMock ()
5458 with patch .object (
5559 Helper ,
5660 "run" ,
@@ -61,30 +65,29 @@ def test_tag_with_multiple_flags():
6165 )
6266 ),
6367 ) as mock_helper :
64- gh = GitHelper (False )
68+ gh = GitHelper (repo , False )
6569 gh .tag ("v0.1.0" , message = "This is a message." , force = True , annotate = True )
6670 mock_helper .assert_called_with (
6771 ["git" , "tag" , "v0.1.0" , "-f" , "-m" , "This is a message." , "-a" ]
6872 )
6973
7074
7175def test_add_all ():
76+ repo = MagicMock ()
7277 with patch .object (
7378 Helper ,
7479 "run" ,
7580 return_value = CommandResult (
76- CompletedProcess (
77- ["git" , "add" , "-a" ],
78- returncode = 0 ,
79- )
81+ CompletedProcess (["git" , "add" , "-A" ], returncode = 0 ),
8082 ),
8183 ) as mock_helper :
82- gh = GitHelper (False )
84+ gh = GitHelper (repo , False )
8385 gh .add (all = True )
84- mock_helper .assert_called_with (["git" , "add" , "-a " ])
86+ mock_helper .assert_called_with (["git" , "add" , "-A " ])
8587
8688
8789def test_commit_all ():
90+ repo = MagicMock ()
8891 with patch .object (
8992 Helper ,
9093 "run" ,
@@ -95,12 +98,13 @@ def test_commit_all():
9598 )
9699 ),
97100 ) as mock_helper :
98- gh = GitHelper (False )
101+ gh = GitHelper (repo , False )
99102 gh .commit (all = True , message = "Test commit" )
100103 mock_helper .assert_called_with (["git" , "commit" , "-a" , "-m" , "Test commit" ])
101104
102105
103106def test_commit_with_pathspec ():
107+ repo = MagicMock ()
104108 with patch .object (
105109 Helper ,
106110 "run" ,
@@ -111,14 +115,15 @@ def test_commit_with_pathspec():
111115 )
112116 ),
113117 ) as mock_helper :
114- gh = GitHelper (False )
118+ gh = GitHelper (repo , False )
115119 gh .commit (pathspec = "file*" , all = True , message = "Test commit" )
116120 mock_helper .assert_called_with (
117121 ["git" , "commit" , "-a" , "-m" , "Test commit" , "file*" ]
118122 )
119123
120124
121125def test_checkout_with_branch_and_start_point ():
126+ repo = MagicMock ()
122127 with patch .object (
123128 Helper ,
124129 "run" ,
@@ -129,7 +134,7 @@ def test_checkout_with_branch_and_start_point():
129134 )
130135 ),
131136 ) as mock_helper :
132- gh = GitHelper (False )
137+ gh = GitHelper (repo , False )
133138 gh .checkout (
134139 branch_name = "test" ,
135140 start_point = "HEAD" ,
@@ -139,6 +144,7 @@ def test_checkout_with_branch_and_start_point():
139144
140145
141146def test_checkout_with_files ():
147+ repo = MagicMock ()
142148 with patch .object (
143149 Helper ,
144150 "run" ,
@@ -149,7 +155,7 @@ def test_checkout_with_files():
149155 )
150156 ),
151157 ) as mock_helper :
152- gh = GitHelper (False )
158+ gh = GitHelper (repo , False )
153159 gh .checkout (
154160 branch_name = "test" ,
155161 paths = ["filea.txt" , "fileb.txt" ],
@@ -160,6 +166,7 @@ def test_checkout_with_files():
160166
161167
162168def test_restore_staged_worktree ():
169+ repo = MagicMock ()
163170 with patch .object (
164171 Helper ,
165172 "run" ,
@@ -170,12 +177,13 @@ def test_restore_staged_worktree():
170177 )
171178 ),
172179 ) as mock_helper :
173- gh = GitHelper (False )
180+ gh = GitHelper (repo , False )
174181 gh .restore (pathspec = "." , staged = True , worktree = True )
175182 mock_helper .assert_called_with (["git" , "restore" , "-W" , "-S" , "." ])
176183
177184
178185def test_restore_ours ():
186+ repo = MagicMock ()
179187 with (
180188 patch .object (
181189 Helper ,
@@ -189,5 +197,5 @@ def test_restore_ours():
189197 ),
190198 pytest .raises (ValueError ),
191199 ):
192- gh = GitHelper (False )
200+ gh = GitHelper (repo , False )
193201 gh .restore (pathspec = "." , ours = True , source = "." , staged = True , worktree = True )
0 commit comments