summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2015-09-09 16:37:50 -0700
committerDylan Baker <baker.dylan.c@gmail.com>2015-09-22 14:45:49 -0700
commit39edc6b8ff25131c601402d7977370a81876493b (patch)
tree89092a11e552a102e41c9bbb5728895fe0a86585
parent337336cb48fa50358093d9eefd6697ed513e17a8 (diff)
framework/summary/html_.py: split the html function
This creates 3 functions, each of which are simpler to understand and do less than the giant function did previously. Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r--framework/summary/html_.py89
-rw-r--r--framework/tests/summary_html_tests.py39
2 files changed, 86 insertions, 42 deletions
diff --git a/framework/summary/html_.py b/framework/summary/html_.py
index d7209efab..0036b839d 100644
--- a/framework/summary/html_.py
+++ b/framework/summary/html_.py
@@ -54,28 +54,19 @@ _TEMPLATES = TemplateLookup(
module_directory=os.path.join(_TEMP_DIR, "html-summary"))
-def html(results, destination, exclude):
- """
- Produce HTML summaries.
-
- Basically all this does is takes the information provided by the
- constructor, and passes it to mako templates to generate HTML files.
- The beauty of this approach is that mako is leveraged to do the
- heavy lifting, this method just passes it a bunch of dicts and lists
- of dicts, which mako turns into pretty HTML.
- """
- results = Results([backends.load(i) for i in results])
-
- # Copy static files
+def _copy_static_files(destination):
+ """Copy static files into the results directory."""
shutil.copy(os.path.join(_TEMPLATE_DIR, "index.css"),
os.path.join(destination, "index.css"))
shutil.copy(os.path.join(_TEMPLATE_DIR, "result.css"),
os.path.join(destination, "result.css"))
+
+def _make_testrun_info(results, destination, exclude):
+ """Create the pages for each results file."""
result_css = os.path.join(destination, "result.css")
index = os.path.join(destination, "index.html")
- # Iterate across the tests creating the various test specific files
for each in results.results:
name = escape_pathname(each.name)
try:
@@ -124,37 +115,51 @@ def html(results, destination, exclude):
css=os.path.relpath(result_css, temp_path),
index=os.path.relpath(index, temp_path)))
- # Finally build the root html files: index, regressions, etc
+
+def _make_comparison_pages(results, destination, exclude):
+ """Create the pages of comparisons."""
pages = frozenset(['changes', 'problems', 'skips', 'fixes',
'regressions', 'enabled', 'disabled'])
# Index.html is a bit of a special case since there is index, all, and
# alltests, where the other pages all use the same name. ie,
# changes.html, changes, and page=changes.
- try:
- with open(os.path.join(destination, "index.html"), 'w') as out:
- out.write(_TEMPLATES.get_template('index.mako').render(
- results=results,
- page='all',
- pages=pages,
- exclude=exclude))
-
- # Generate the rest of the pages
- for page in pages:
- with open(os.path.join(destination, page + '.html'), 'w') as out:
- # If there is information to display display it
- if sum(getattr(results.counts, page)) > 0:
- out.write(_TEMPLATES.get_template('index.mako').render(
- results=results,
- pages=pages,
- page=page,
- exclude=exclude))
- # otherwise provide an empty page
- else:
- out.write(
- _TEMPLATES.get_template('empty_status.mako').render(
- page=page, pages=pages))
- except:
- from mako.exceptions import text_error_template
- print(text_error_template().render())
- exit(1)
+ with open(os.path.join(destination, "index.html"), 'w') as out:
+ out.write(_TEMPLATES.get_template('index.mako').render(
+ results=results,
+ page='all',
+ pages=pages,
+ exclude=exclude))
+
+ # Generate the rest of the pages
+ for page in pages:
+ with open(os.path.join(destination, page + '.html'), 'w') as out:
+ # If there is information to display display it
+ if sum(getattr(results.counts, page)) > 0:
+ out.write(_TEMPLATES.get_template('index.mako').render(
+ results=results,
+ pages=pages,
+ page=page,
+ exclude=exclude))
+ # otherwise provide an empty page
+ else:
+ out.write(
+ _TEMPLATES.get_template('empty_status.mako').render(
+ page=page, pages=pages))
+
+
+def html(results, destination, exclude):
+ """
+ Produce HTML summaries.
+
+ Basically all this does is takes the information provided by the
+ constructor, and passes it to mako templates to generate HTML files.
+ The beauty of this approach is that mako is leveraged to do the
+ heavy lifting, this method just passes it a bunch of dicts and lists
+ of dicts, which mako turns into pretty HTML.
+ """
+ results = Results([backends.load(i) for i in results])
+
+ _copy_static_files(destination)
+ _make_testrun_info(results, destination, exclude)
+ _make_comparison_pages(results, destination, exclude)
diff --git a/framework/tests/summary_html_tests.py b/framework/tests/summary_html_tests.py
new file mode 100644
index 000000000..d654ba04b
--- /dev/null
+++ b/framework/tests/summary_html_tests.py
@@ -0,0 +1,39 @@
+# Copyright (c) 2015 Intel Corporation
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+"""Tests for html summary generation."""
+
+# pylint: disable=protected-access
+
+from __future__ import absolute_import, division, print_function
+import os
+
+import nose.tools as nt
+
+from framework.summary import html_
+from framework.tests import utils
+
+
+@utils.test_in_tempdir
+def test_copy_static():
+ """summary.html_._copy_static: puts status content in correct locations"""
+ html_._copy_static_files(os.getcwd())
+ nt.ok_(os.path.exists('index.css'), msg='index.css not created correctly')
+ nt.ok_(os.path.exists('result.css'), msg='result.css not created correctly')