diff options
author | Thomas Wood <thomas.wood@intel.com> | 2014-03-27 15:52:48 +0000 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2014-04-02 10:20:50 -0700 |
commit | db1acd6d7b62df34aee21117db766443173736d2 (patch) | |
tree | caadcc825b8c1fb2e8450e679a58125b6a4e6305 | |
parent | 1f5e984746a23c5dc8b2f270547cc3728bf39fa8 (diff) |
framework: print a summary line after a run has finished
v2: split output writing into a private method (Dylan Baker)
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
Reviewed-by: Dylan Baker <baker.dylan.c@gmail.com>
-rw-r--r-- | framework/core.py | 2 | ||||
-rw-r--r-- | framework/log.py | 44 |
2 files changed, 29 insertions, 17 deletions
diff --git a/framework/core.py b/framework/core.py index 5f5cf8687..391fa5e2e 100644 --- a/framework/core.py +++ b/framework/core.py @@ -598,6 +598,8 @@ class TestProfile(object): multi.join() single.join() + log.summary() + def filter_tests(self, function): """Filter out tests that return false from the supplied function diff --git a/framework/log.py b/framework/log.py index f6e46b957..d045847ff 100644 --- a/framework/log.py +++ b/framework/log.py @@ -47,6 +47,24 @@ class Log(object): if verbose: self.__output = "{result} :: {name}\n" + self.__output + self.__summary_output = "[{percent}] {summary}\n" + + def _write_output(self, output): + """ write the output to stdout, ensuring any previous line is cleared """ + + length = len(output) + if self.__lastlength > length: + output = "{0}{1}{2}".format(output[:-1], + " " * (self.__lastlength - length), + output[-1]) + + self.__lastlength = length + + sys.stdout.write(output) + + # Need to flush explicitly, otherwise it all gets buffered without a + # newline. + sys.stdout.flush() def _summary(self): """ return a summary of the statuses """ @@ -65,23 +83,11 @@ class Log(object): def __print(self, name, result): """ Do the actual printing """ - output = self.__output.format(**{'percent': self._percent(), - 'running': self._running(), - 'summary': self._summary(), - 'name': name, - 'result': result}) - length = len(output) - if self.__lastlength > length: - output = "{0}{1}\r".format(output[:-1], - " " * (self.__lastlength - length)) - - self.__lastlength = length - - sys.stdout.write(output) - - # Need to flush explicitly, otherwise it all gets buffered without a - # newline. - sys.stdout.flush() + self._write_output(self.__output.format(**{'percent': self._percent(), + 'running': self._running(), + 'summary': self._summary(), + 'name': name, + 'result': result})) @synchronized_self def post_log(self, value, result): @@ -131,3 +137,7 @@ class Log(object): x = self.__generator.next() self.__running.append(x) return x + + def summary(self): + self._write_output(self.__summary_output.format(**{'percent': self._percent(), + 'summary': self._summary()})) |