@@ -321,17 +321,17 @@ def test_version(self):
321
321
self .assertIsInstance (n , int )
322
322
# END verify number types
323
323
324
- def test_cmd_override (self ):
325
- with mock .patch .object (
326
- type (self .git ),
327
- "GIT_PYTHON_GIT_EXECUTABLE" ,
328
- osp .join ("some" , "path" , "which" , "doesn't" , "exist" , "gitbinary" ),
329
- ):
330
- self .assertRaises (GitCommandNotFound , self .git .version )
331
-
332
324
def test_git_exc_name_is_git (self ):
333
325
self .assertEqual (self .git .git_exec_name , "git" )
334
326
327
+ def test_cmd_override (self ):
328
+ """Directly set bad GIT_PYTHON_GIT_EXECUTABLE causes git operations to raise."""
329
+ bad_path = osp .join ("some" , "path" , "which" , "doesn't" , "exist" , "gitbinary" )
330
+ with mock .patch .object (Git , "GIT_PYTHON_GIT_EXECUTABLE" , bad_path ):
331
+ with self .assertRaises (GitCommandNotFound ) as ctx :
332
+ self .git .version ()
333
+ self .assertEqual (ctx .exception .command , [bad_path , "version" ])
334
+
335
335
@ddt .data (("0" ,), ("q" ,), ("quiet" ,), ("s" ,), ("silence" ,), ("silent" ,), ("n" ,), ("none" ,))
336
336
def test_initial_refresh_from_bad_git_path_env_quiet (self , case ):
337
337
"""In "q" mode, bad initial path sets "git" and is quiet."""
@@ -341,7 +341,7 @@ def test_initial_refresh_from_bad_git_path_env_quiet(self, case):
341
341
"GIT_PYTHON_REFRESH" : mode ,
342
342
}
343
343
with _rollback_refresh ():
344
- type( self . git ) .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
344
+ Git .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
345
345
346
346
with mock .patch .dict (os .environ , set_vars ):
347
347
refresh ()
@@ -356,14 +356,14 @@ def test_initial_refresh_from_bad_git_path_env_warn(self, case):
356
356
"GIT_PYTHON_REFRESH" : mode ,
357
357
}
358
358
with _rollback_refresh ():
359
- type( self . git ) .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
359
+ Git .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
360
360
361
361
with mock .patch .dict (os .environ , env_vars ):
362
362
with self .assertLogs (cmd .__name__ , logging .CRITICAL ) as ctx :
363
363
refresh ()
364
364
self .assertEqual (len (ctx .records ), 1 )
365
365
message = ctx .records [0 ].getMessage ()
366
- self .assertRegex (message , r"\AWARNING: Bad git executable.\n" )
366
+ self .assertRegex (message , r"\ABad git executable.\n" )
367
367
self .assertEqual (self .git .GIT_PYTHON_GIT_EXECUTABLE , "git" )
368
368
369
369
@ddt .data (("2" ,), ("r" ,), ("raise" ,), ("e" ,), ("error" ,))
@@ -375,7 +375,7 @@ def test_initial_refresh_from_bad_git_path_env_error(self, case):
375
375
"GIT_PYTHON_REFRESH" : mode ,
376
376
}
377
377
with _rollback_refresh ():
378
- type( self . git ) .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
378
+ Git .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
379
379
380
380
with mock .patch .dict (os .environ , env_vars ):
381
381
with self .assertRaisesRegex (ImportError , r"\ABad git executable.\n" ):
@@ -386,7 +386,7 @@ def test_initial_refresh_from_good_absolute_git_path_env(self):
386
386
absolute_path = shutil .which ("git" )
387
387
388
388
with _rollback_refresh ():
389
- type( self . git ) .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
389
+ Git .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
390
390
391
391
with mock .patch .dict (os .environ , {"GIT_PYTHON_GIT_EXECUTABLE" : absolute_path }):
392
392
refresh ()
@@ -397,8 +397,8 @@ def test_initial_refresh_from_good_relative_git_path_env(self):
397
397
with _rollback_refresh ():
398
398
# Set the fallback to a string that wouldn't work and isn't "git", so we are
399
399
# more likely to detect if "git" is not set from the environment variable.
400
- with mock .patch .object (type ( self . git ) , "git_exec_name" , "" ):
401
- type( self . git ) .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
400
+ with mock .patch .object (Git , "git_exec_name" , "" ):
401
+ Git .GIT_PYTHON_GIT_EXECUTABLE = None # Simulate startup.
402
402
403
403
# Now observe if setting the environment variable to "git" takes effect.
404
404
with mock .patch .dict (os .environ , {"GIT_PYTHON_GIT_EXECUTABLE" : "git" }):
@@ -442,7 +442,7 @@ def test_refresh_from_good_relative_git_path_env(self):
442
442
"""Good relative path from environment is kept relative and set."""
443
443
with _rollback_refresh ():
444
444
# Set as the executable name a string that wouldn't work and isn't "git".
445
- type( self . git ) .GIT_PYTHON_GIT_EXECUTABLE = ""
445
+ Git .GIT_PYTHON_GIT_EXECUTABLE = ""
446
446
447
447
# Now observe if setting the environment variable to "git" takes effect.
448
448
with mock .patch .dict (os .environ , {"GIT_PYTHON_GIT_EXECUTABLE" : "git" }):
0 commit comments