2222 parse_date ,
2323 tzoffset ,
2424 from_timestamp )
25- from test .lib import TestBase
25+ from test .lib import (
26+ TestBase ,
27+ with_rw_repo ,
28+ )
2629from git .util import (
2730 LockFile ,
2831 BlockingLockFile ,
@@ -217,16 +220,31 @@ def test_actor(self):
217220 self .assertIsInstance (Actor .author (cr ), Actor )
218221 # END assure config reader is handled
219222
223+ @with_rw_repo ('HEAD' )
220224 @mock .patch ("getpass.getuser" )
221- def test_actor_get_uid_laziness_not_called (self , mock_get_uid ):
225+ def test_actor_get_uid_laziness_not_called (self , rwrepo , mock_get_uid ):
226+ with rwrepo .config_writer () as cw :
227+ cw .set_value ("user" , "name" , "John Config Doe" )
228+ cw .set_value ("user" , "email" , "jcdoe@example.com" )
229+
230+ cr = rwrepo .config_reader ()
231+ committer = Actor .committer (cr )
232+ author = Actor .author (cr )
233+
234+ self .assertEqual (committer .name , 'John Config Doe' )
235+ self .assertEqual (committer .email , 'jcdoe@example.com' )
236+ self .assertEqual (author .name , 'John Config Doe' )
237+ self .assertEqual (author .email , 'jcdoe@example.com' )
238+ self .assertFalse (mock_get_uid .called )
239+
222240 env = {
223241 "GIT_AUTHOR_NAME" : "John Doe" ,
224242 "GIT_AUTHOR_EMAIL" : "jdoe@example.com" ,
225243 "GIT_COMMITTER_NAME" : "Jane Doe" ,
226244 "GIT_COMMITTER_EMAIL" : "jane@example.com" ,
227245 }
228246 os .environ .update (env )
229- for cr in (None , self . rorepo .config_reader ()):
247+ for cr in (None , rwrepo .config_reader ()):
230248 committer = Actor .committer (cr )
231249 author = Actor .author (cr )
232250 self .assertEqual (committer .name , 'Jane Doe' )
@@ -238,16 +256,16 @@ def test_actor_get_uid_laziness_not_called(self, mock_get_uid):
238256 @mock .patch ("getpass.getuser" )
239257 def test_actor_get_uid_laziness_called (self , mock_get_uid ):
240258 mock_get_uid .return_value = "user"
241- for cr in ( None , self . rorepo . config_reader ()):
242- committer = Actor .committer ( cr )
243- author = Actor . author ( cr )
244- if cr is None : # otherwise, use value from config_reader
245- self .assertEqual (committer .name , 'user' )
246- self .assertTrue (committer .email .startswith ('user@' ))
247- self .assertEqual (author .name , 'user' )
248- self .assertTrue (committer .email .startswith ('user@' ))
259+ committer = Actor . committer ( None )
260+ author = Actor .author ( None )
261+ # We can't test with `self.rorepo.config_reader()` here, as the uuid laziness
262+ # depends on whether the user running the test has their global user.name config set.
263+ self .assertEqual (committer .name , 'user' )
264+ self .assertTrue (committer .email .startswith ('user@' ))
265+ self .assertEqual (author .name , 'user' )
266+ self .assertTrue (committer .email .startswith ('user@' ))
249267 self .assertTrue (mock_get_uid .called )
250- self .assertEqual (mock_get_uid .call_count , 4 )
268+ self .assertEqual (mock_get_uid .call_count , 2 )
251269
252270 def test_actor_from_string (self ):
253271 self .assertEqual (Actor ._from_string ("name" ), Actor ("name" , None ))
0 commit comments