summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2015-09-01 12:31:55 -0700
committerDylan Baker <baker.dylan.c@gmail.com>2015-09-22 14:45:49 -0700
commit6b52e06acf4c03ee4bc9c0d2ab3c1c33321a0251 (patch)
treef802960895a483858731d5d7cb298962967505f3
parent026d6df25c960053e65df1283ed90579cc1b15a8 (diff)
framework/summary.py: add helper to turn times into time deltas
Gain a little code reuse and unit tests. Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r--framework/summary.py16
-rw-r--r--framework/tests/summary_tests.py14
2 files changed, 23 insertions, 7 deletions
diff --git a/framework/summary.py b/framework/summary.py
index 2c6df6388..4b3be4d1f 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -74,6 +74,13 @@ def normalize_href(href):
return href.replace('\\', '/')
+def time_as_delta(time):
+ """Convert time to a time delta, or return None."""
+ if time is not None:
+ return datetime.timedelta(0, time)
+ return None
+
+
class HTMLIndex(list):
"""
Builds HTML output to be passed to the index mako template, which will be
@@ -346,16 +353,11 @@ def html(results, destination, exclude):
else:
raise e
- if each.time_elapsed is not None:
- time = datetime.timedelta(0, each.time_elapsed)
- else:
- time = None
-
with open(path.join(destination, name, "index.html"), 'w') as out:
out.write(_TEMPLATES.get_template('testrun_info.mako').render(
name=each.name,
totals=each.totals['root'],
- time=time,
+ time=time_as_delta(each.time_elapsed),
options=each.options,
uname=each.uname,
glxinfo=each.glxinfo,
@@ -375,7 +377,7 @@ def html(results, destination, exclude):
os.makedirs(temp_path)
if value.time:
- value.time = datetime.timedelta(0, value.time)
+ value.time = time_as_delta(value.time)
with open(html_path, 'w') as out:
out.write(_TEMPLATES.get_template(
diff --git a/framework/tests/summary_tests.py b/framework/tests/summary_tests.py
index 788761612..9b8c9c8ab 100644
--- a/framework/tests/summary_tests.py
+++ b/framework/tests/summary_tests.py
@@ -22,6 +22,7 @@
""" Module providing tests for the summary module """
from __future__ import print_function, absolute_import
+import datetime
import nose.tools as nt
@@ -340,3 +341,16 @@ def test_Results_get_results_missing_subtest():
nt.eq_(res.get_result(grouptools.join('foo', '1')),
[status.PASS, status.NOTRUN])
+
+
+def test_time_as_delta():
+ """summary.time_as_delta: converts a time into a delta"""
+ input_ = 1.2
+ expected = datetime.timedelta(0, input_)
+
+ nt.eq_(expected, summary.time_as_delta(input_))
+
+
+def test_time_as_delta_none():
+ """summary.time_as_delta: returns None when input is None"""
+ nt.eq_(None, summary.time_as_delta(None))