Skip to content

Commit

Permalink
Update utest to mock _git_remote_verbose in a new way, since it is no…
Browse files Browse the repository at this point in the history
…w called via the GitRepository class rather than on the specific GitRepository instance.
  • Loading branch information
johnpaulalex committed Feb 24, 2023
1 parent d7a42ae commit 4233954
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions test/test_unit_repository_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,19 @@ def setUp(self):
self._repo._current_ref = self._current_ref_empty
self._create_tmp_git_dir()

# We have to override this class method rather than the self._repo
# instance method because it is called via
# GitRepository._remote_name_for_url, which is itself a @classmethod
# calls cls._git_remote_verbose().
self._orignal_git_remote_verbose = GitRepository._git_remote_verbose
GitRepository._git_remote_verbose = self._git_remote_origin_upstream
def tearDown(self):
"""Cleanup tmp stuff on the file system
"""
self._remove_tmp_git_dir()

GitRepository._git_remote_verbose = self._orignal_git_remote_verbose

def _create_tmp_git_dir(self):
"""Create a temporary fake git directory for testing purposes.
"""
Expand All @@ -229,20 +237,18 @@ def _remove_tmp_git_dir(self):
@staticmethod
def _current_ref_empty():
"""Return an empty string.
Drop-in for GitRepository._current_ref
"""
return EMPTY_STR

@staticmethod
def _git_remote_origin_upstream():
"""Return an info string that is a checkout hash
"""
return GIT_REMOTE_OUTPUT_ORIGIN_UPSTREAM
def _git_remote_origin_upstream(dir=None):
"""Return an info string that is a checkout hash.
@staticmethod
def _git_remote_none():
"""Return an info string that is a checkout hash
Drop-in for GitRepository._git_remote_verbose.
"""
return EMPTY_STR
return GIT_REMOTE_OUTPUT_ORIGIN_UPSTREAM

@staticmethod
def _git_current_hash(myhash):
Expand Down Expand Up @@ -291,9 +297,6 @@ def test_sync_dir_exist_no_git_info(self):
"""Test that a non-existent git repo returns an unknown status
"""
stat = ExternalStatus()
# Now we over-ride the _git_remote_verbose method on the repo to return
# a known value without requiring access to git.
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._tag = 'tag1'
self._repo._git_current_hash = self._git_current_hash('')
self._repo._git_revparse_commit = self._git_revparse_commit(
Expand All @@ -313,7 +316,6 @@ def test_sync_invalid_reference(self):
"""Test that an invalid reference returns out-of-sync
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._tag = 'tag1'
self._repo._git_current_hash = self._git_current_hash('abc123')
self._repo._git_revparse_commit = self._git_revparse_commit(
Expand All @@ -333,7 +335,6 @@ def test_sync_tag_on_same_hash(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._tag = 'tag1'
self._repo._git_current_hash = self._git_current_hash('abc123')
self._repo._git_revparse_commit = self._git_revparse_commit(
Expand All @@ -348,7 +349,6 @@ def test_sync_tag_on_different_hash(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._tag = 'tag1'
self._repo._git_current_hash = self._git_current_hash('def456')
self._repo._git_revparse_commit = self._git_revparse_commit(
Expand All @@ -368,7 +368,6 @@ def test_sync_hash_on_same_hash(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._tag = ''
self._repo._hash = 'abc'
self._repo._git_current_hash = self._git_current_hash('abc123')
Expand All @@ -384,7 +383,6 @@ def test_sync_hash_on_different_hash(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._tag = ''
self._repo._hash = 'abc'
self._repo._git_current_hash = self._git_current_hash('def456')
Expand All @@ -405,7 +403,6 @@ def test_sync_branch_on_same_hash(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._branch = 'feature-2'
self._repo._tag = ''
self._repo._git_current_hash = self._git_current_hash('abc123')
Expand All @@ -421,7 +418,6 @@ def test_sync_branch_on_diff_hash(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._branch = 'feature-2'
self._repo._tag = ''
self._repo._git_current_hash = self._git_current_hash('abc123')
Expand All @@ -437,7 +433,6 @@ def test_sync_branch_diff_remote(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._branch = 'feature-2'
self._repo._tag = ''
self._repo._url = '/path/to/other/repo'
Expand All @@ -453,7 +448,6 @@ def test_sync_branch_diff_remote2(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._branch = 'feature-2'
self._repo._tag = ''
self._repo._url = '/path/to/local/repo2'
Expand All @@ -469,7 +463,6 @@ def test_sync_branch_on_unknown_remote(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._branch = 'feature-2'
self._repo._tag = ''
self._repo._url = '/path/to/unknown/repo'
Expand All @@ -491,7 +484,6 @@ def test_sync_branch_on_untracked_local(self):
"""
stat = ExternalStatus()
self._repo._git_remote_verbose = self._git_remote_origin_upstream
self._repo._branch = 'feature3'
self._repo._tag = ''
self._repo._url = '.'
Expand Down

0 comments on commit 4233954

Please sign in to comment.