Skip to content

Commit ed7b9e1

Browse files
eifracheranco74
authored andcommitted
fixing tests due to decoding
1 parent cf2b333 commit ed7b9e1

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.vscode
2+
**__pycache__**
3+
**.pytest_cache**
14
*.egg-info
25
*.pyc
36
.cache

skipper/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def build(ctx, images_to_build, container_context, cache):
106106
continue
107107
valid_images_to_build[image] = valid_images[image]
108108

109-
tag = git.get_hash().decode('utf-8')
109+
tag = git.get_hash()
110110
for image, dockerfile in six.iteritems(valid_images_to_build):
111111
utils.logger.info('Building image: %s', image)
112112

skipper/git.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ def get_hash(short=False):
1616
if uncommitted_changes():
1717
logging.warning("*** Uncommitted changes present - Build container version might be outdated ***")
1818

19-
return subprocess.check_output(git_command).strip()
20-
19+
return subprocess.check_output(git_command).strip().decode('utf-8')
2120

2221
def uncommitted_changes():
2322
"""Return True is there are uncommitted changes."""

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ def test_run_with_defaults_from_config_file_including_workspace(self, skipper_ru
16801680
@mock.patch('builtins.open', mock.MagicMock(create=True))
16811681
@mock.patch('os.path.exists', mock.MagicMock(autospec=True, return_value=True))
16821682
@mock.patch('yaml.safe_load', mock.MagicMock(autospec=True, return_value=SKIPPER_CONF_WITH_GIT_REV))
1683-
@mock.patch('subprocess.check_output', mock.MagicMock(autospec=True, return_value='1234567\n'))
1683+
@mock.patch('subprocess.check_output', mock.MagicMock(autospec=True, return_value=b'1234567\n'))
16841684
@mock.patch('skipper.git.uncommitted_changes', mock.MagicMock(return_value=True))
16851685
@mock.patch('skipper.runner.run', autospec=True)
16861686
def test_run_with_config_including_git_revision_with_uncommitted_changes(self, skipper_runner_run_mock):
@@ -1701,7 +1701,7 @@ def test_run_with_config_including_git_revision_with_uncommitted_changes(self, s
17011701
@mock.patch('builtins.open', mock.MagicMock(create=True))
17021702
@mock.patch('os.path.exists', mock.MagicMock(autospec=True, return_value=True))
17031703
@mock.patch('yaml.safe_load', mock.MagicMock(autospec=True, return_value=SKIPPER_CONF_WITH_GIT_REV))
1704-
@mock.patch('subprocess.check_output', mock.MagicMock(autospec=True, return_value='1234567\n'))
1704+
@mock.patch('subprocess.check_output', mock.MagicMock(autospec=True, return_value=b'1234567\n'))
17051705
@mock.patch('skipper.git.uncommitted_changes', mock.MagicMock(return_value=False))
17061706
@mock.patch('skipper.runner.run', autospec=True)
17071707
def test_run_with_config_including_git_revision_without_uncommitted_changes(self, skipper_runner_run_mock):

tests/test_git.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from skipper import git
44

55

6-
GIT_HASH_FULL = '00efe974e3cf18c3493f110f5aeda04ff78b125f'
7-
GIT_HASH_SHORT = '00efe97'
6+
GIT_HASH_FULL = b'00efe974e3cf18c3493f110f5aeda04ff78b125f'
7+
GIT_HASH_SHORT = b'00efe97'
88

99

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

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

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

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

0 commit comments

Comments
 (0)