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
|
|
|
"""
|
2018-10-16 08:41:06 +00:00
|
|
|
import os
|
2018-12-17 08:18:30 +00:00
|
|
|
|
|
|
|
import escapism
|
2018-09-26 17:01:58 +00:00
|
|
|
|
|
|
|
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
|
2018-10-16 08:41:06 +00:00
|
|
|
cwd = os.getcwd()
|
|
|
|
|
2018-10-16 06:22:19 +00:00
|
|
|
argv = ['--subdir', 'a directory', TEST_REPO]
|
2018-09-26 22:33:52 +00:00
|
|
|
run_repo2docker(argv)
|
|
|
|
|
2018-10-16 08:41:06 +00:00
|
|
|
# check that we restored the current working directory
|
|
|
|
assert cwd == os.getcwd(), "We should be back in %s" % cwd
|
|
|
|
|
2018-09-26 17:01:58 +00:00
|
|
|
|
2018-12-17 08:18:30 +00:00
|
|
|
def test_subdir_in_image_name():
|
|
|
|
app = Repo2Docker(
|
|
|
|
repo=TEST_REPO,
|
|
|
|
subdir='a directory',
|
|
|
|
)
|
|
|
|
app.initialize()
|
|
|
|
app.build()
|
|
|
|
|
|
|
|
escaped_dirname = escapism.escape('a directory', escape_char='-').lower()
|
|
|
|
assert escaped_dirname in app.output_image_spec
|
|
|
|
|
|
|
|
|
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
|
2018-12-17 12:11:45 +00:00
|
|
|
app = Repo2Docker(
|
|
|
|
repo=TEST_REPO,
|
|
|
|
subdir='invalid-sub-dir',
|
|
|
|
)
|
|
|
|
app.initialize()
|
|
|
|
with pytest.raises(FileNotFoundError):
|
|
|
|
app.build() # Just build the image and do not run it.
|