22
22
parse_date ,
23
23
tzoffset ,
24
24
from_timestamp )
25
- from test .lib import TestBase
25
+ from test .lib import (
26
+ TestBase ,
27
+ with_rw_repo ,
28
+ )
26
29
from git .util import (
27
30
LockFile ,
28
31
BlockingLockFile ,
@@ -217,16 +220,31 @@ def test_actor(self):
217
220
self .assertIsInstance (Actor .author (cr ),Actor )
218
221
# END assure config reader is handled
219
222
223
+ @with_rw_repo ('HEAD' )
220
224
@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
+
222
240
env = {
223
241
"GIT_AUTHOR_NAME" :"John Doe" ,
224
242
"GIT_AUTHOR_EMAIL" :"jdoe@example.com" ,
225
243
"GIT_COMMITTER_NAME" :"Jane Doe" ,
226
244
"GIT_COMMITTER_EMAIL" :"jane@example.com" ,
227
245
}
228
246
os .environ .update (env )
229
- for cr in (None ,self . rorepo .config_reader ()):
247
+ for cr in (None ,rwrepo .config_reader ()):
230
248
committer = Actor .committer (cr )
231
249
author = Actor .author (cr )
232
250
self .assertEqual (committer .name ,'Jane Doe' )
@@ -238,16 +256,16 @@ def test_actor_get_uid_laziness_not_called(self, mock_get_uid):
238
256
@mock .patch ("getpass.getuser" )
239
257
def test_actor_get_uid_laziness_called (self ,mock_get_uid ):
240
258
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@' ))
249
267
self .assertTrue (mock_get_uid .called )
250
- self .assertEqual (mock_get_uid .call_count ,4 )
268
+ self .assertEqual (mock_get_uid .call_count ,2 )
251
269
252
270
def test_actor_from_string (self ):
253
271
self .assertEqual (Actor ._from_string ("name" ),Actor ("name" ,None ))