From d6aa9b2446bbc859e122f7d716a663eb08b5abd4 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 8 Jul 2022 10:19:34 -0300 Subject: [PATCH] [Test] Added test for python_downloader --- tests/test_plot/test_dep_downloader.py | 37 +++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/test_plot/test_dep_downloader.py b/tests/test_plot/test_dep_downloader.py index f9d35777..17c0abe5 100644 --- a/tests/test_plot/test_dep_downloader.py +++ b/tests/test_plot/test_dep_downloader.py @@ -8,7 +8,7 @@ import os import coverage import yaml import logging -from importlib import reload +import importlib from . import context from kibot.mcpyrate import activate # noqa: F401 import kibot.dep_downloader as downloader @@ -31,9 +31,9 @@ def try_dependency(ctx, caplog, monkeypatch, docstring, name_dep, downloader_nam m.setenv("HOME", home) m.setattr("site.USER_BASE", os.path.join(home, '.local')) # Refresh the module with actual dependencies - mod = reload(downloader) + mod = importlib.reload(downloader) mod.register_deps('test', yaml.safe_load(docstring)) - # Get the RAR dependency + # Get the dependency dep = mod.used_deps['test:'+name_dep] # Download it cov.load() @@ -48,6 +48,28 @@ def try_dependency(ctx, caplog, monkeypatch, docstring, name_dep, downloader_nam # We executed the file +def try_dependency_module(ctx, caplog, monkeypatch, docstring, name_dep, downloader_name): + with monkeypatch.context(): + # Refresh the module with actual dependencies + mod = importlib.reload(downloader) + mod.register_deps('test', yaml.safe_load(docstring)) + # Get the dependency + dep = mod.used_deps['test:'+name_dep] + # Download it + cov.load() + cov.start() + # Python module + downloader_func = getattr(mod, downloader_name) + res = downloader_func(dep, False) + cov.stop() + cov.save() + # We should get the following name: + logging.debug('Result: {}'.format(res)) + assert res is not None + logging.debug(res.__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 @@ -88,3 +110,12 @@ def test_dep_convert(test_dir, caplog, monkeypatch): log.debug_level = 10 dep = ' - from: ImageMagick\n role: mandatory\n' try_dependency(ctx, caplog, monkeypatch, downloader.__doc__+dep, 'imagemagick', 'convert', bin_dir) + + +def test_dep_python(test_dir, caplog, monkeypatch): + """ Check the python_downloader """ + # Create a context to get an output directory + ctx = context.TestContext(test_dir, 'bom', 'bom') + log.debug_level = 10 + dep = 'Dependencies:\n - name: engineering_notation\n role: mandatory\n python_module: true\n' + try_dependency_module(ctx, caplog, monkeypatch, dep, 'engineering_notation', 'check_tool_python')