Skip to content

Commit

Permalink
Fix tests for Python <3.9 which lack Path.with_stem
Browse files Browse the repository at this point in the history
  • Loading branch information
EliahKagan committed Feb 22, 2024
1 parent 2940662 commit e3e5687
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def _fake_git(*version_info):
yield str(fake_git.absolute())


def _rename_with_stem(path, new_stem):
if sys.version_info >= (3, 9):
path.rename(path.with_stem(new_stem))
else:
path.rename(path.with_name(new_stem + path.suffix))


@ddt.ddt
class TestGit(TestBase):
@classmethod
Expand Down Expand Up @@ -647,10 +654,10 @@ def test_successful_default_refresh_invalidates_cached_version_info(self):
stack.enter_context(mock.patch.object(Git, "USE_SHELL", True))

new_git = Git()
path2.rename(path2.with_stem("git")) # "Install" git, "late" in the PATH.
_rename_with_stem(path2, "git") # "Install" git, "late" in the PATH.
refresh()
self.assertEqual(new_git.version_info, (22, 222, 2), 'before "downgrade"')
path1.rename(path1.with_stem("git")) # "Install" another, higher priority.
_rename_with_stem(path1, "git") # "Install" another, higher priority.
self.assertEqual(new_git.version_info, (22, 222, 2), "stale version")
refresh()
self.assertEqual(new_git.version_info, (11, 111, 1), "fresh version")
Expand Down

0 comments on commit e3e5687

Please sign in to comment.