Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tag format as utf-8 instead of byte #164

Merged
merged 3 commits into from Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,3 +1,6 @@
.vscode
**__pycache__**
**.pytest_cache**
*.egg-info
*.pyc
.cache
Expand Down
2 changes: 1 addition & 1 deletion skipper/git.py
Expand Up @@ -16,7 +16,7 @@ def get_hash(short=False):
if uncommitted_changes():
logging.warning("*** Uncommitted changes present - Build container version might be outdated ***")

return subprocess.check_output(git_command).strip()
return subprocess.check_output(git_command).strip().decode('utf-8')


def uncommitted_changes():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Expand Up @@ -1680,7 +1680,7 @@ def test_run_with_defaults_from_config_file_including_workspace(self, skipper_ru
@mock.patch('builtins.open', mock.MagicMock(create=True))
@mock.patch('os.path.exists', mock.MagicMock(autospec=True, return_value=True))
@mock.patch('yaml.safe_load', mock.MagicMock(autospec=True, return_value=SKIPPER_CONF_WITH_GIT_REV))
@mock.patch('subprocess.check_output', mock.MagicMock(autospec=True, return_value='1234567\n'))
@mock.patch('subprocess.check_output', mock.MagicMock(autospec=True, return_value=b'1234567\n'))
@mock.patch('skipper.git.uncommitted_changes', mock.MagicMock(return_value=True))
@mock.patch('skipper.runner.run', autospec=True)
def test_run_with_config_including_git_revision_with_uncommitted_changes(self, skipper_runner_run_mock):
Expand All @@ -1701,7 +1701,7 @@ def test_run_with_config_including_git_revision_with_uncommitted_changes(self, s
@mock.patch('builtins.open', mock.MagicMock(create=True))
@mock.patch('os.path.exists', mock.MagicMock(autospec=True, return_value=True))
@mock.patch('yaml.safe_load', mock.MagicMock(autospec=True, return_value=SKIPPER_CONF_WITH_GIT_REV))
@mock.patch('subprocess.check_output', mock.MagicMock(autospec=True, return_value='1234567\n'))
@mock.patch('subprocess.check_output', mock.MagicMock(autospec=True, return_value=b'1234567\n'))
@mock.patch('skipper.git.uncommitted_changes', mock.MagicMock(return_value=False))
@mock.patch('skipper.runner.run', autospec=True)
def test_run_with_config_including_git_revision_without_uncommitted_changes(self, skipper_runner_run_mock):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_git.py
Expand Up @@ -3,8 +3,8 @@
from skipper import git


GIT_HASH_FULL = '00efe974e3cf18c3493f110f5aeda04ff78b125f'
GIT_HASH_SHORT = '00efe97'
GIT_HASH_FULL = b'00efe974e3cf18c3493f110f5aeda04ff78b125f'
GIT_HASH_SHORT = b'00efe97'


class TestGit(unittest.TestCase):
Expand All @@ -14,23 +14,23 @@ def test_get_hash_with_default_argument(self, exists_mock, check_output_mock):
git_hash = git.get_hash()
exists_mock.assert_called_once_with('.git')
check_output_mock.assert_called_once_with(['git', 'rev-parse', 'HEAD'])
self.assertEqual(git_hash, GIT_HASH_FULL)
self.assertEqual(git_hash, GIT_HASH_FULL.decode('utf-8'))

@mock.patch('subprocess.check_output', return_value=GIT_HASH_FULL)
@mock.patch('os.path.exists', return_value=True)
def test_get_full_hash(self, exists_mock, check_output_mock):
git_hash = git.get_hash(short=False)
exists_mock.assert_called_once_with('.git')
check_output_mock.assert_called_once_with(['git', 'rev-parse', 'HEAD'])
self.assertEqual(git_hash, GIT_HASH_FULL)
self.assertEqual(git_hash, GIT_HASH_FULL.decode('utf-8'))

@mock.patch('subprocess.check_output', return_value=GIT_HASH_SHORT)
@mock.patch('os.path.exists', return_value=True)
def test_get_short_hash(self, exists_mock, check_output_mock):
git_hash = git.get_hash(short=True)
exists_mock.assert_called_once_with('.git')
check_output_mock.assert_called_once_with(['git', 'rev-parse', '--short', 'HEAD'])
self.assertEqual(git_hash, GIT_HASH_SHORT)
self.assertEqual(git_hash, GIT_HASH_SHORT.decode('utf-8'))

@mock.patch('subprocess.check_output')
@mock.patch('os.path.exists', return_value=False)
Expand Down