2018-10-12 14:45:07 +00:00
|
|
|
import os
|
|
|
|
from tempfile import TemporaryDirectory, NamedTemporaryFile
|
|
|
|
|
|
|
|
from repo2docker.contentproviders import Local
|
|
|
|
|
|
|
|
|
|
|
|
def test_detect_local_dir():
|
|
|
|
with TemporaryDirectory() as d:
|
|
|
|
local = Local()
|
|
|
|
spec = local.detect(d)
|
|
|
|
|
|
|
|
# should accept a local directory
|
|
|
|
assert spec is not None, spec
|
2019-05-31 09:10:17 +00:00
|
|
|
assert "path" in spec, spec
|
|
|
|
assert spec["path"] == d
|
2018-10-12 14:45:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_not_detect_local_file():
|
|
|
|
with NamedTemporaryFile() as f:
|
|
|
|
local = Local()
|
|
|
|
spec = local.detect(f.name)
|
|
|
|
|
|
|
|
# should NOT accept a local file
|
|
|
|
assert spec is None, spec
|
|
|
|
|
|
|
|
|
2018-12-17 08:18:30 +00:00
|
|
|
def test_content_id_is_None():
|
|
|
|
# content_id property should always be None for local content provider
|
|
|
|
# as we rely on the caching done by docker
|
|
|
|
local = Local()
|
|
|
|
assert local.content_id is None
|
|
|
|
|
|
|
|
|
2018-10-12 14:45:07 +00:00
|
|
|
def test_content_available():
|
|
|
|
# create a directory with files, check they are available in the output
|
|
|
|
# directory
|
|
|
|
with TemporaryDirectory() as d:
|
2019-05-31 09:10:17 +00:00
|
|
|
with open(os.path.join(d, "test"), "w") as f:
|
2018-10-12 14:45:07 +00:00
|
|
|
f.write("Hello")
|
|
|
|
|
2018-12-17 08:18:30 +00:00
|
|
|
local = Local()
|
2019-05-31 09:10:17 +00:00
|
|
|
spec = {"path": d}
|
2018-12-17 08:18:30 +00:00
|
|
|
for _ in local.fetch(spec, d):
|
2018-10-12 14:45:07 +00:00
|
|
|
pass
|
2019-05-31 09:10:17 +00:00
|
|
|
assert os.path.exists(os.path.join(d, "test"))
|
2018-12-17 08:18:30 +00:00
|
|
|
# content_id property should always be None for local content provider
|
|
|
|
# as we rely on the caching done by docker
|
|
|
|
assert local.content_id is None
|