2018-09-26 17:01:58 +00:00
|
|
|
"""
|
2018-09-27 16:07:27 +00:00
|
|
|
Test if the subdirectory is correctly navigated to
|
2018-09-26 17:01:58 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from repo2docker.app import Repo2Docker
|
|
|
|
|
2018-10-16 06:22:19 +00:00
|
|
|
TEST_REPO = "https://github.com/binderhub-ci-repos/repo2docker-subdir-support"
|
2018-09-26 17:01:58 +00:00
|
|
|
|
2018-09-26 22:33:52 +00:00
|
|
|
|
|
|
|
def test_subdir(run_repo2docker):
|
2018-10-16 06:22:19 +00:00
|
|
|
# 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]
|
2018-09-26 22:33:52 +00:00
|
|
|
run_repo2docker(argv)
|
|
|
|
|
2018-09-26 17:01:58 +00:00
|
|
|
|
|
|
|
def test_subdir_invalid(caplog):
|
2018-10-16 06:22:19 +00:00
|
|
|
# test an error is raised when requesting a non existent subdir
|
|
|
|
caplog.set_level(logging.INFO)
|
2018-09-26 17:01:58 +00:00
|
|
|
|
|
|
|
app = Repo2Docker()
|
2018-10-16 06:22:19 +00:00
|
|
|
argv = ['--subdir', 'invalid-sub-dir', TEST_REPO]
|
2018-09-26 17:01:58 +00:00
|
|
|
app.initialize(argv)
|
|
|
|
app.debug = True
|
2018-10-16 06:22:19 +00:00
|
|
|
# no build implies no run
|
|
|
|
app.build = False
|
2018-10-15 17:58:00 +00:00
|
|
|
with pytest.raises(SystemExit) as excinfo:
|
2018-09-26 17:01:58 +00:00
|
|
|
app.start() # Just build the image and do not run it.
|
|
|
|
|
2018-10-15 17:58:00 +00:00
|
|
|
# The build should fail
|
|
|
|
assert excinfo.value.code == 1
|
|
|
|
|
2018-09-26 17:01:58 +00:00
|
|
|
# Can't get this to record the logs?
|
2018-10-16 06:22:19 +00:00
|
|
|
assert caplog.text == "Subdirectory tests/conda/invalid does not exist"
|