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.
pull/443/head
Tim Head 2018-10-16 08:22:19 +02:00
rodzic 4310a39e28
commit 4e1eff5f1b
2 zmienionych plików z 15 dodań i 11 usunięć

Wyświetl plik

@ -704,9 +704,10 @@ class Repo2Docker(Application):
self.fetch(self.repo, self.ref, checkout_path) self.fetch(self.repo, self.ref, checkout_path)
if self.subdir: if self.subdir:
checkout_path = os.path.join(checkout_path, self.subdir).rstrip('/') checkout_path = os.path.join(checkout_path, self.subdir)
if not os.path.exists(checkout_path): if not os.path.isdir(checkout_path):
self.log.error('Subdirectory %s does not exist', self.subdir, extra=dict(phase='failure')) self.log.error('Subdirectory %s does not exist',
self.subdir, extra=dict(phase='failure'))
sys.exit(1) sys.exit(1)
os.chdir(checkout_path) os.chdir(checkout_path)

Wyświetl plik

@ -2,28 +2,31 @@
Test if the subdirectory is correctly navigated to Test if the subdirectory is correctly navigated to
""" """
import logging import logging
from os.path import abspath, dirname
import pytest import pytest
from repo2docker.app import Repo2Docker from repo2docker.app import Repo2Docker
# This is the path to the repo2docker git repository that this file exists in. TEST_REPO = "https://github.com/binderhub-ci-repos/repo2docker-subdir-support"
repo_path = dirname(dirname(abspath(__file__)))
def test_subdir(run_repo2docker): 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) run_repo2docker(argv)
def test_subdir_invalid(caplog): 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() app = Repo2Docker()
argv = ['--subdir', 'tests/conda/invalid', repo_path] argv = ['--subdir', 'invalid-sub-dir', TEST_REPO]
app.initialize(argv) app.initialize(argv)
app.debug = True app.debug = True
app.run = False # no build implies no run
app.build = False
with pytest.raises(SystemExit) as excinfo: with pytest.raises(SystemExit) as excinfo:
app.start() # Just build the image and do not run it. 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 assert excinfo.value.code == 1
# Can't get this to record the logs? # 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"