diff --git a/kibot/dep_downloader.py b/kibot/dep_downloader.py index 23a9efb9..73a68cff 100644 --- a/kibot/dep_downloader.py +++ b/kibot/dep_downloader.py @@ -321,7 +321,7 @@ def git_downloader(dep, system, plat): # Now create the wrapper git_real = dest_bin dest_bin = dest_bin[:-5] - logger.error(f'{dest_bin} -> {git_real}') + logger.debugl(2, '{} -> {}'.format(dest_bin, git_real)) if os.path.isfile(dest_bin): os.remove(dest_bin) with open(dest_bin, 'wt') as f: diff --git a/tests/test_plot/__init__.py b/tests/test_plot/__init__.py index e2c5b0aa..415a1233 100644 --- a/tests/test_plot/__init__.py +++ b/tests/test_plot/__init__.py @@ -8,5 +8,10 @@ if prev_dir not in sys.path: # Utils import from utils import context # noqa: F401 prev_dir = os.path.dirname(prev_dir) -if prev_dir not in sys.path: +# py-test inserts things at the beginning, so we could end loading an installed copy of KiBot +if sys.path[0] != prev_dir: + try: + sys.path.remove(prev_dir) + except ValueError: + pass sys.path.insert(0, prev_dir) diff --git a/tests/test_plot/test_dep_downloader.py b/tests/test_plot/test_dep_downloader.py new file mode 100644 index 00000000..f1fc55cf --- /dev/null +++ b/tests/test_plot/test_dep_downloader.py @@ -0,0 +1,90 @@ +""" +Tests for Dependencies Downloader + +For debug information use: +pytest-3 --log-cli-level debug +""" +import os +import coverage +import yaml +import logging +from importlib import reload +from . import context +from kibot.mcpyrate import activate # noqa: F401 +import kibot.dep_downloader as downloader +import kibot.out_compress as compress +import kibot.log as log + +cov = coverage.Coverage() +bin_dir = os.path.join('.local', 'share', 'kibot', 'bin') +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 try_dependency(ctx, caplog, monkeypatch, docstring, name_dep, downloader_name, b_dir): + with monkeypatch.context() as m: + # Force the downloader to use the output dir instead of HOME + home = os.path.abspath(ctx.output_dir) + m.setenv("HOME", home) + m.setattr("site.USER_BASE", os.path.join(home, '.local')) + # Refresh the module with actual dependencies + mod = reload(downloader) + mod.register_deps('test', yaml.safe_load(docstring)) + # Get the RAR dependency + dep = mod.used_deps['test:'+name_dep] + # Download it + cov.load() + cov.start() + downloader_func = getattr(mod, downloader_name+'_downloader') + res = downloader_func(dep, 'Linux', 'x86_64') + cov.stop() + cov.save() + # We should get the following name: + logging.debug('Result: {}'.format(res)) + assert res == os.path.join(home, b_dir, dep.command) + # 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) + + +# Needs adjusts, pip behaves differently when running as root ... +# 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) + + +def test_dep_rsvg(test_dir, caplog, monkeypatch): + """ Check the rsvg_downloader """ + # Create a context to get an output directory + ctx = context.TestContext(test_dir, 'bom', 'bom') + log.debug_level = 10 + dep = ' - from: RSVG\n role: mandatory\n' + try_dependency(ctx, caplog, monkeypatch, downloader.__doc__+dep, 'rsvg', 'rsvg', bin_dir) + + +def test_dep_git(test_dir, caplog, monkeypatch): + """ Check the git_downloader """ + # Create a context to get an output directory + ctx = context.TestContext(test_dir, 'bom', 'bom') + log.debug_level = 10 + dep = ' - from: Git\n role: mandatory\n' + try_dependency(ctx, caplog, monkeypatch, downloader.__doc__+dep, 'git', 'git', bin_dir) + + +def test_dep_convert(test_dir, caplog, monkeypatch): + """ Check the convert_downloader """ + # Create a context to get an output directory + ctx = context.TestContext(test_dir, 'bom', 'bom') + log.debug_level = 10 + dep = ' - from: ImageMagick\n role: mandatory\n' + try_dependency(ctx, caplog, monkeypatch, downloader.__doc__+dep, 'imagemagick', 'convert', bin_dir) diff --git a/tests/utils/context.py b/tests/utils/context.py index bbc35320..d76cc3a6 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -11,7 +11,12 @@ from glob import glob from pty import openpty import xml.etree.ElementTree as ET prev_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -if prev_dir not in sys.path: +# py-test inserts things at the beginning, so we could end loading an installed copy of KiBot +if sys.path[0] != prev_dir: + try: + sys.path.remove(prev_dir) + except ValueError: + pass sys.path.insert(0, prev_dir) from kibot.misc import (error_level_to_name)