@@ -533,6 +533,84 @@ def test_version_info_cache_is_per_instance(self):
533
533
git2 .version_info
534
534
git1 .version_info
535
535
536
+ def test_successful_refresh_with_arg_invalidates_cached_version_info (self ):
537
+ with _rollback_refresh ():
538
+ with _fake_git (11 , 111 , 1 ) as path1 :
539
+ with _fake_git (22 , 222 , 2 ) as path2 :
540
+ new_git = Git ()
541
+ refresh (path1 )
542
+ new_git .version_info
543
+ refresh (path2 )
544
+ self .assertEqual (new_git .version_info , (22 , 222 , 2 ))
545
+
546
+ def test_failed_refresh_with_arg_does_not_invalidate_cached_version_info (self ):
547
+ with _rollback_refresh ():
548
+ with _fake_git (11 , 111 , 1 ) as path1 :
549
+ with _fake_git (22 , 222 , 2 ) as path2 :
550
+ new_git = Git ()
551
+ refresh (path1 )
552
+ new_git .version_info
553
+ os .remove (path1 ) # Arrange that a repeat call for path1 would fail.
554
+ os .remove (path2 ) # Arrange that the new call for path2 will fail.
555
+ with self .assertRaises (GitCommandNotFound ):
556
+ refresh (path2 )
557
+ self .assertEqual (new_git .version_info , (11 , 111 , 1 ))
558
+
559
+ def test_successful_refresh_with_same_arg_invalidates_cached_version_info (self ):
560
+ """Changing git at the same path and refreshing affects version_info."""
561
+ with _rollback_refresh ():
562
+ with _fake_git (11 , 111 , 1 ) as path1 :
563
+ with _fake_git (22 , 222 , 2 ) as path2 :
564
+ new_git = Git ()
565
+ refresh (path1 )
566
+ new_git .version_info
567
+ shutil .copy (path2 , path1 )
568
+ refresh (path1 ) # The fake git at path1 has a different version now.
569
+ self .assertEqual (new_git .version_info , (22 , 222 , 2 ))
570
+
571
+ def test_successful_refresh_with_env_invalidates_cached_version_info (self ):
572
+ with contextlib .ExitStack () as stack :
573
+ stack .enter_context (_rollback_refresh ())
574
+ path1 = stack .enter_context (_fake_git (11 , 111 , 1 ))
575
+ path2 = stack .enter_context (_fake_git (22 , 222 , 2 ))
576
+ with mock .patch .dict (os .environ , {"GIT_PYTHON_GIT_EXECUTABLE" : path1 }):
577
+ new_git = Git ()
578
+ refresh ()
579
+ new_git .version_info
580
+ with mock .patch .dict (os .environ , {"GIT_PYTHON_GIT_EXECUTABLE" : path2 }):
581
+ refresh ()
582
+ self .assertEqual (new_git .version_info , (22 , 222 , 2 ))
583
+
584
+ def test_failed_refresh_with_env_does_not_invalidate_cached_version_info (self ):
585
+ with contextlib .ExitStack () as stack :
586
+ stack .enter_context (_rollback_refresh ())
587
+ path1 = stack .enter_context (_fake_git (11 , 111 , 1 ))
588
+ path2 = stack .enter_context (_fake_git (22 , 222 , 2 ))
589
+ with mock .patch .dict (os .environ , {"GIT_PYTHON_GIT_EXECUTABLE" : path1 }):
590
+ new_git = Git ()
591
+ refresh ()
592
+ new_git .version_info
593
+ os .remove (path1 ) # Arrange that a repeat call for path1 would fail.
594
+ os .remove (path2 ) # Arrange that the new call for path2 will fail.
595
+ with mock .patch .dict (os .environ , {"GIT_PYTHON_GIT_EXECUTABLE" : path2 }):
596
+ with self .assertRaises (GitCommandNotFound ):
597
+ refresh (path2 )
598
+ self .assertEqual (new_git .version_info , (11 , 111 , 1 ))
599
+
600
+ def test_successful_refresh_with_same_env_invalidates_cached_version_info (self ):
601
+ """Changing git at the same path/command and refreshing affects version_info."""
602
+ with contextlib .ExitStack () as stack :
603
+ stack .enter_context (_rollback_refresh ())
604
+ path1 = stack .enter_context (_fake_git (11 , 111 , 1 ))
605
+ path2 = stack .enter_context (_fake_git (22 , 222 , 2 ))
606
+ with mock .patch .dict (os .environ , {"GIT_PYTHON_GIT_EXECUTABLE" : path1 }):
607
+ new_git = Git ()
608
+ refresh ()
609
+ new_git .version_info
610
+ shutil .copy (path2 , path1 )
611
+ refresh () # The fake git at path1 has a different version now.
612
+ self .assertEqual (new_git .version_info , (22 , 222 , 2 ))
613
+
536
614
def test_options_are_passed_to_git (self ):
537
615
# This works because any command after git --version is ignored.
538
616
git_version = self .git (version = True ).NoOp ()
0 commit comments