Added pytool_downloader test
This commit is contained in:
parent
941185d635
commit
069d9ba690
|
|
@ -7,36 +7,57 @@ pytest-3 --log-cli-level debug
|
||||||
import os
|
import os
|
||||||
import coverage
|
import coverage
|
||||||
import yaml
|
import yaml
|
||||||
|
import logging
|
||||||
from importlib import reload
|
from importlib import reload
|
||||||
from . import context
|
from . import context
|
||||||
from kibot.mcpyrate import activate # noqa: F401
|
from kibot.mcpyrate import activate # noqa: F401
|
||||||
import kibot.dep_downloader as downloader
|
import kibot.dep_downloader as downloader
|
||||||
import kibot.out_compress as compress
|
import kibot.out_compress as compress
|
||||||
|
import kibot.out_kibom as kibom
|
||||||
|
import kibot.log as log
|
||||||
|
|
||||||
cov = coverage.Coverage()
|
cov = coverage.Coverage()
|
||||||
bin_dir = os.path.join('.local', 'share', 'kibot', 'bin')
|
bin_dir = os.path.join('.local', 'share', 'kibot', 'bin')
|
||||||
DEPS = {'Dependencies': [{'from': 'RAR', 'role': 'mandatory'}]}
|
bin_dir_py = os.path.join('.local', 'bin')
|
||||||
|
# DEPS = {'Dependencies':
|
||||||
|
# [{'from': 'RAR', 'role': 'mandatory'},
|
||||||
|
# {'name': 'KiBoM', 'role': 'mandatory', 'github': 'INTI-CMNB/KiBoM', 'command': 'KiBOM_CLI.py', 'version': '1.8.0'}]}
|
||||||
|
|
||||||
|
|
||||||
def test_dep_rar(test_dir, caplog, monkeypatch):
|
def try_dependency(ctx, caplog, monkeypatch, docstring, name_dep, downloader_name, b_dir):
|
||||||
""" Check missing rar_downloader """
|
|
||||||
# Create a context to get an output directory
|
|
||||||
ctx = context.TestContext(test_dir, 'bom', 'bom')
|
|
||||||
with monkeypatch.context() as m:
|
with monkeypatch.context() as m:
|
||||||
# Force the downloader to use the output dir
|
# Force the downloader to use the output dir instead of HOME
|
||||||
home = os.path.abspath(ctx.output_dir)
|
home = os.path.abspath(ctx.output_dir)
|
||||||
m.setenv("HOME", home)
|
m.setenv("HOME", home)
|
||||||
|
m.setattr("site.USER_BASE", os.path.join(home, '.local'))
|
||||||
# Refresh the module with actual dependencies
|
# Refresh the module with actual dependencies
|
||||||
mod = reload(downloader)
|
mod = reload(downloader)
|
||||||
mod.register_deps('test', yaml.safe_load(compress.__doc__))
|
mod.register_deps('test', yaml.safe_load(docstring))
|
||||||
# Get the RAR dependency
|
# Get the RAR dependency
|
||||||
dep = mod.used_deps['test:rar']
|
dep = mod.used_deps['test:'+name_dep]
|
||||||
# Download it
|
# Download it
|
||||||
cov.load()
|
cov.load()
|
||||||
cov.start()
|
cov.start()
|
||||||
res = mod.rar_downloader(dep, 'Linux', 'x86_64')
|
downloader_func = getattr(mod, downloader_name+'_downloader')
|
||||||
|
res = downloader_func(dep, 'Linux', 'x86_64')
|
||||||
cov.stop()
|
cov.stop()
|
||||||
cov.save()
|
cov.save()
|
||||||
# We should get the following name:
|
# We should get the following name:
|
||||||
assert res == os.path.join(home, bin_dir, 'rar')
|
logging.debug('Result: {}'.format(res))
|
||||||
|
assert res == os.path.join(home, b_dir, dep.command)
|
||||||
# We executed the file
|
# We executed the file
|
||||||
|
|
||||||
|
|
||||||
|
def test_dep_rar(test_dir, caplog, monkeypatch):
|
||||||
|
""" Check the rar_downloader """
|
||||||
|
# Create a context to get an output directory
|
||||||
|
ctx = context.TestContext(test_dir, 'bom', 'bom')
|
||||||
|
try_dependency(ctx, caplog, monkeypatch, compress.__doc__, 'rar', 'rar', bin_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dep_pytool(test_dir, caplog, monkeypatch):
|
||||||
|
""" Check the pytool_downloader """
|
||||||
|
# Create a context to get an output directory
|
||||||
|
ctx = context.TestContext(test_dir, 'bom', 'bom')
|
||||||
|
log.debug_level = 10
|
||||||
|
try_dependency(ctx, caplog, monkeypatch, kibom.__doc__, 'kibom', 'pytool', bin_dir_py)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue