Refactor test to use mock
MODIFY
repo2docker/app.py
repo2docker/app.py
@@ -744,8 +744,6 @@ class Repo2Docker(Application):
else:
picked_buildpack = self.default_buildpack()
- self._picked_buildpack = picked_buildpack
-
picked_buildpack.appendix = self.appendix
picked_buildpack.labels['repo2docker.version'] = self.version
picked_buildpack.labels['repo2docker.repo'] = self.repo

MODIFY
tests/test_labels.py
tests/test_labels.py
Test if labels are supplied correctly to the container
"""
import time
+from unittest.mock import Mock
from repo2docker.app import Repo2Docker
from repo2docker.buildpacks import BuildPack
from repo2docker import __version__
@@ -19,21 +20,26 @@ def test_buildpack_labels_rendered():
@pytest.mark.parametrize('ref', ['some-branch', None])
def test_labels(ref, tmpdir):
- app = Repo2Docker()
repo = str(tmpdir)
if ref is not None:
argv = ['--ref', ref, repo]
else:
argv = [repo]
+
+ app = Repo2Docker()
+ # Add mock BuildPack to app
+ mock_buildpack = Mock()
+ mock_buildpack.return_value.labels = {}
+ app.buildpacks = [mock_buildpack]
+
app.initialize(argv)
app.build = False
app.run = False
app.start()
- labels = app._picked_buildpack.labels
expected_labels = {
'repo2docker.ref': ref,
'repo2docker.repo': repo,
'repo2docker.version': __version__,
}
- assert labels == expected_labels
+ assert mock_buildpack().labels == expected_labels

Refactor test to use mock