Switch repository used to test sub-directory support
Using a repository that contains invlid instructions in the root of the
repository so that the test for subdirectory support will fail if
repo2docker doesn't actually switch into the requested sub-directory.
MODIFY
repo2docker/app.py
repo2docker/app.py
@@ -704,9 +704,10 @@ class Repo2Docker(Application):
self.fetch(self.repo, self.ref, checkout_path)
if self.subdir:
- checkout_path = os.path.join(checkout_path, self.subdir).rstrip('/')
- if not os.path.exists(checkout_path):
- self.log.error('Subdirectory %s does not exist', self.subdir, extra=dict(phase='failure'))
+ checkout_path = os.path.join(checkout_path, self.subdir)
+ if not os.path.isdir(checkout_path):
+ self.log.error('Subdirectory %s does not exist',
+ self.subdir, extra=dict(phase='failure'))
sys.exit(1)
os.chdir(checkout_path)

MODIFY
tests/test_subdir.py
tests/test_subdir.py
Test if the subdirectory is correctly navigated to
"""
import logging
-from os.path import abspath, dirname
import pytest
from repo2docker.app import Repo2Docker
-# This is the path to the repo2docker git repository that this file exists in.
-repo_path = dirname(dirname(abspath(__file__)))
+TEST_REPO = "https://github.com/binderhub-ci-repos/repo2docker-subdir-support"
def test_subdir(run_repo2docker):
- argv = ['--subdir', 'tests/conda/simple', repo_path]
+ # Build from a subdirectory
+ # if subdir support is broken this will fail as the instructions in the
+ # root of the test repo are invalid
+ argv = ['--subdir', 'a directory', TEST_REPO]
run_repo2docker(argv)
def test_subdir_invalid(caplog):
- caplog.set_level(logging.INFO, logger='Repo2Docker')
+ # test an error is raised when requesting a non existent subdir
+ caplog.set_level(logging.INFO)
app = Repo2Docker()
- argv = ['--subdir', 'tests/conda/invalid', repo_path]
+ argv = ['--subdir', 'invalid-sub-dir', TEST_REPO]
app.initialize(argv)
app.debug = True
- app.run = False
+ # no build implies no run
+ app.build = False
with pytest.raises(SystemExit) as excinfo:
app.start() # Just build the image and do not run it.
@@ -31,4 +34,4 @@ def test_subdir_invalid(caplog):
assert excinfo.value.code == 1
# Can't get this to record the logs?
- # assert caplog.text == "Subdirectory tests/conda/invalid does not exist"
+ assert caplog.text == "Subdirectory tests/conda/invalid does not exist"

Switch repository used to test sub-directory support

Using a repository that contains invlid instructions in the root of the
repository so that the test for subdirectory support will fail if
repo2docker doesn't actually switch into the requested sub-directory.