2018-12-13 08:01:26 +00:00
|
|
|
"""
|
|
|
|
Test argument parsing and r2d construction
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
import logging
|
|
|
|
from repo2docker.__main__ import make_r2d
|
|
|
|
from repo2docker import __version__
|
|
|
|
|
2018-12-14 21:29:14 +00:00
|
|
|
|
|
|
|
def test_version(capsys):
|
2018-12-13 08:01:26 +00:00
|
|
|
"""
|
|
|
|
Test passing '--version' to repo2docker
|
|
|
|
"""
|
2018-12-14 21:29:14 +00:00
|
|
|
with pytest.raises(SystemExit):
|
2019-05-31 09:10:17 +00:00
|
|
|
make_r2d(["--version"])
|
2018-12-18 15:29:28 +00:00
|
|
|
assert capsys.readouterr().out == "{}\n".format(__version__)
|
2018-12-13 08:01:26 +00:00
|
|
|
|
2019-05-31 09:10:17 +00:00
|
|
|
|
2018-12-13 08:01:26 +00:00
|
|
|
def test_simple():
|
|
|
|
"""
|
|
|
|
Test simplest possible invocation to r2d
|
|
|
|
"""
|
2019-05-31 09:10:17 +00:00
|
|
|
r2d = make_r2d(["."])
|
|
|
|
assert r2d.repo == "."
|
|
|
|
|
2018-12-13 08:01:26 +00:00
|
|
|
|
|
|
|
def test_editable():
|
|
|
|
"""
|
|
|
|
Test --editable behavior
|
|
|
|
"""
|
2019-05-31 09:10:17 +00:00
|
|
|
r2d = make_r2d(["--editable", "."])
|
|
|
|
assert r2d.repo == "."
|
|
|
|
assert r2d.volumes[os.getcwd()] == "."
|
|
|
|
|
2018-12-13 08:01:26 +00:00
|
|
|
|
|
|
|
def test_dry_run():
|
|
|
|
"""
|
|
|
|
Test passing --no-build implies --no-run and lack of --push
|
|
|
|
"""
|
2019-05-31 09:10:17 +00:00
|
|
|
r2d = make_r2d(["--no-build", "."])
|
2018-12-13 08:01:26 +00:00
|
|
|
assert r2d.dry_run
|
|
|
|
assert not r2d.run
|
|
|
|
assert not r2d.push
|
|
|
|
|
2019-04-30 17:46:09 +00:00
|
|
|
|
|
|
|
def test_mem_limit():
|
|
|
|
"""
|
|
|
|
Test various ways of passing --build-memory-limit
|
|
|
|
"""
|
2019-05-31 09:10:17 +00:00
|
|
|
r2d = make_r2d(["--build-memory-limit", "1024", "."])
|
2019-04-30 17:46:09 +00:00
|
|
|
assert int(r2d.build_memory_limit) == 1024
|
|
|
|
|
2019-05-31 09:10:17 +00:00
|
|
|
r2d = make_r2d(["--build-memory-limit", "3K", "."])
|
2019-04-30 17:46:09 +00:00
|
|
|
assert int(r2d.build_memory_limit) == 1024 * 3
|
|
|
|
|
2019-05-31 09:10:17 +00:00
|
|
|
|
2018-12-13 08:01:26 +00:00
|
|
|
def test_run_required():
|
|
|
|
"""
|
|
|
|
Test all the things that should fail if we pass in --no-run
|
|
|
|
"""
|
|
|
|
# Can't use volumes without running
|
|
|
|
with pytest.raises(SystemExit):
|
2019-05-31 09:10:17 +00:00
|
|
|
make_r2d(["--no-run", "--editable", "."])
|
2018-12-13 08:01:26 +00:00
|
|
|
|
|
|
|
# Can't publish all ports without running
|
|
|
|
with pytest.raises(SystemExit):
|
2019-05-31 09:10:17 +00:00
|
|
|
make_r2d(["--no-run", "-P", "."])
|
2018-12-13 08:01:26 +00:00
|
|
|
|
|
|
|
# Can't publish any ports without running
|
|
|
|
with pytest.raises(SystemExit):
|
2019-05-31 09:10:17 +00:00
|
|
|
make_r2d(["--no-run", "-p", "8000:8000", "."])
|
2018-12-13 08:01:26 +00:00
|
|
|
|
|
|
|
# Can't publish any ports while running if we don't specify a command explicitly
|
|
|
|
with pytest.raises(SystemExit):
|
2019-05-31 09:10:17 +00:00
|
|
|
make_r2d(["-p", "8000:8000", "."])
|
|
|
|
|
2018-12-13 18:03:55 +00:00
|
|
|
|
|
|
|
def test_clean():
|
|
|
|
"""
|
|
|
|
Test checkout is cleaned appropriately
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Don't clean when repo isn't local and we explicitly ask it to not clean
|
2019-05-31 09:10:17 +00:00
|
|
|
assert not make_r2d(["--no-clean", "https://github.com/blah.git"]).cleanup_checkout
|
2018-12-13 18:03:55 +00:00
|
|
|
# Do clean repo when repo isn't localj
|
2019-05-31 09:10:17 +00:00
|
|
|
assert make_r2d(["https://github.com/blah.git"]).cleanup_checkout
|
2018-12-13 18:03:55 +00:00
|
|
|
|
|
|
|
# Don't clean by default when repo exists locally
|
2019-05-31 09:10:17 +00:00
|
|
|
assert not make_r2d(["."]).cleanup_checkout
|
2018-12-13 18:03:55 +00:00
|
|
|
# Don't clean when repo exists locally and we explicitly ask it to not clean
|
2019-05-31 09:10:17 +00:00
|
|
|
assert not make_r2d(["--no-clean", "."]).cleanup_checkout
|
2018-12-13 22:16:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_image_name():
|
|
|
|
"""
|
|
|
|
Test validating image names
|
|
|
|
"""
|
|
|
|
with pytest.raises(SystemExit):
|
2019-05-31 09:10:17 +00:00
|
|
|
make_r2d(["--image-name", "_invalid", "."])
|