diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2015-10-07 23:31:44 -0700 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2015-10-08 13:56:44 -0700 |
commit | 878fa4eb89236875cae132d8633aa6245e895cda (patch) | |
tree | dbcf729b2cd49396840222c55aee19f5d8345627 /framework/results.py | |
parent | 53a7f990e1ba5306274a1b458570b67b2ed85445 (diff) |
framework: Add a TimeAttribute class
This class will provide a new interface for time, one that stores the
start and stop times, rather than the total time. It then provides
methods for getting the total and the delta (as used in the summary).
This commit adds the new class and tests for the class, but doesn't
start plugging it in yet.
The goal of this change is to allow post-processing to determine which
tests were running in parallel.
Reviewed-by: Mark Janes <mark.a.janes@intel.com>
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
Diffstat (limited to 'framework/results.py')
-rw-r--r-- | framework/results.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/framework/results.py b/framework/results.py index 26f438066..7eca5bdec 100644 --- a/framework/results.py +++ b/framework/results.py @@ -25,6 +25,7 @@ from __future__ import print_function, absolute_import import collections import copy +import datetime from framework import status, exceptions, grouptools @@ -103,6 +104,43 @@ class StringDescriptor(object): # pylint: disable=too-few-public-methods raise NotImplementedError +class TimeAttribute(object): + """Attribute of TestResult for time. + + This attribute provides a couple of nice helpers. It stores the start and + end time and provides methods for getting the total and delta of the times. + + """ + __slots__ = ['start', 'end'] + + def __init__(self, start=0.0, end=0.0): + self.start = start + self.end = end + + @property + def total(self): + return self.end - self.start + + @property + def delta(self): + return str(datetime.timedelta(seconds=self.total)) + + def to_json(self): + return { + 'start': self.start, + 'end': self.end, + '__type__': 'TimeAttribute', + } + + @classmethod + def from_dict(cls, dict_): + dict_ = copy.copy(dict_) + + if '__type__' in dict_: + del dict_['__type__'] + return cls(**dict_) + + class TestResult(object): """An object represting the result of a single test.""" __slots__ = ['returncode', '_err', '_out', 'time', 'command', 'traceback', |