From fb5ab5450b5208a9169a7256f49b2edb52ecf534 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Fri, 8 Jan 2016 10:24:59 -0200 Subject: [PATCH] HTML output support: behave when the plugin is not installed We currently only set HTML support as disabled if the `html.py` library fails to import. The truth is that missing files that are intended to be present on the (separately packaged) HTML plugin package can cause other kinds of exceptions. Let's add an extra check, looking if the resource files are present (currently the template file). Note: there's one outstanding bug, for which a fix is being worked on. When Avocado is installed, either from packages or from source code, the HTML plugin entry point is always registered. That means the plugin Python module is always tried to be loaded. If the plugin *package* is not installed, an error message is given on the command line. Signed-off-by: Cleber Rosa --- avocado/core/html.py | 12 ++++++++++++ avocado/core/job.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/avocado/core/html.py b/avocado/core/html.py index 06f50b28..621b8171 100644 --- a/avocado/core/html.py +++ b/avocado/core/html.py @@ -30,6 +30,18 @@ from ..utils import path as utils_path from ..utils import runtime +def check_resource_requirements(): + """ + Checks if necessary resource files to render the report are in place + + Currently, only the template file is looked for + """ + base_path = os.path.dirname(sys.modules[__name__].__file__) + html_resources_path = os.path.join(base_path, 'resources', 'htmlresult') + template = os.path.join(html_resources_path, 'templates', 'report.mustache') + return os.path.exists(template) + + class ReportModel(object): """ diff --git a/avocado/core/job.py b/avocado/core/job.py index 2a8bdaf7..ff44f6bf 100644 --- a/avocado/core/job.py +++ b/avocado/core/job.py @@ -53,7 +53,7 @@ from ..utils import data_structures try: from . import html - HTML_REPORT_SUPPORT = True + HTML_REPORT_SUPPORT = html.check_resource_requirements() except ImportError: HTML_REPORT_SUPPORT = False -- GitLab