Chromium Code Reviews| Index: tools/testrunner/local/progress.py |
| diff --git a/tools/testrunner/local/progress.py b/tools/testrunner/local/progress.py |
| index a9519e926d7552418e56aeaf2a7fb764e86bdfbb..9a87b6e440d21377c336b785ff926cc988881e83 100644 |
| --- a/tools/testrunner/local/progress.py |
| +++ b/tools/testrunner/local/progress.py |
| @@ -26,6 +26,7 @@ |
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| +from functools import wraps |
| import json |
| import os |
| import sys |
| @@ -54,6 +55,9 @@ class ProgressIndicator(object): |
| def __init__(self): |
| self.runner = None |
| + def SetRunner(self, runner): |
| + self.runner = runner |
| + |
| def Starting(self): |
| pass |
| @@ -80,6 +84,32 @@ class ProgressIndicator(object): |
| } |
| +class IndicatorNotifier(object): |
| + """Holds a list of progress indicators and notifies them all on events.""" |
| + def __init__(self): |
| + self.indicators = [] |
| + |
| + def Register(self, indicator): |
| + self.indicators.append(indicator) |
| + |
| + |
| +def _Indicator_apply(func): |
|
tandrii(chromium)
2015/06/09 13:24:45
nit: then maybe _IndicatorNotifier_apply, and even
Michael Achenbach
2015/06/09 14:09:27
Done. Even funkier...
|
| + """Generic event dispatcher.""" |
| + @wraps(func) |
| + def functor(self, *args, **kwargs): |
| + for indicator in self.indicators: |
| + getattr(indicator, func.__name__)(*args, **kwargs) |
| + return functor |
| + |
| + |
| +# Forge all generic event-dispatching methods in IndicatorNotifier, which are |
| +# part of the ProgressIndicator interface. |
| +for func_name in ProgressIndicator.__dict__: |
| + func = getattr(ProgressIndicator, func_name) |
| + if not func_name.startswith('_') and callable(func): |
| + setattr(IndicatorNotifier, func_name, _Indicator_apply(func)) |
| + |
| + |
| class SimpleProgressIndicator(ProgressIndicator): |
| """Abstract base class for {Verbose,Dots}ProgressIndicator""" |
| @@ -251,29 +281,19 @@ class MonochromeProgressIndicator(CompactProgressIndicator): |
| class JUnitTestProgressIndicator(ProgressIndicator): |
| - def __init__(self, progress_indicator, junitout, junittestsuite): |
| - self.progress_indicator = progress_indicator |
| + def __init__(self, junitout, junittestsuite): |
| self.outputter = junit_output.JUnitTestOutput(junittestsuite) |
| if junitout: |
| self.outfile = open(junitout, "w") |
| else: |
| self.outfile = sys.stdout |
| - def Starting(self): |
| - self.progress_indicator.runner = self.runner |
| - self.progress_indicator.Starting() |
| - |
| def Done(self): |
| - self.progress_indicator.Done() |
| self.outputter.FinishAndWrite(self.outfile) |
| if self.outfile != sys.stdout: |
| self.outfile.close() |
| - def AboutToRun(self, test): |
| - self.progress_indicator.AboutToRun(test) |
| - |
| def HasRun(self, test, has_unexpected_output): |
| - self.progress_indicator.HasRun(test, has_unexpected_output) |
| fail_text = "" |
| if has_unexpected_output: |
| stdout = test.output.stdout.strip() |
| @@ -292,25 +312,17 @@ class JUnitTestProgressIndicator(ProgressIndicator): |
| test.duration, |
| fail_text) |
| - def Heartbeat(self): |
| - self.progress_indicator.Heartbeat() |
| class JsonTestProgressIndicator(ProgressIndicator): |
| - def __init__(self, progress_indicator, json_test_results, arch, mode): |
| - self.progress_indicator = progress_indicator |
| + def __init__(self, json_test_results, arch, mode): |
| self.json_test_results = json_test_results |
| self.arch = arch |
| self.mode = mode |
| self.results = [] |
| self.tests = [] |
| - def Starting(self): |
| - self.progress_indicator.runner = self.runner |
| - self.progress_indicator.Starting() |
| - |
| def Done(self): |
| - self.progress_indicator.Done() |
| complete_results = [] |
| if os.path.exists(self.json_test_results): |
| with open(self.json_test_results, "r") as f: |
| @@ -340,11 +352,7 @@ class JsonTestProgressIndicator(ProgressIndicator): |
| with open(self.json_test_results, "w") as f: |
| f.write(json.dumps(complete_results)) |
| - def AboutToRun(self, test): |
| - self.progress_indicator.AboutToRun(test) |
| - |
| def HasRun(self, test, has_unexpected_output): |
| - self.progress_indicator.HasRun(test, has_unexpected_output) |
| # Buffer all tests for sorting the durations in the end. |
| self.tests.append(test) |
| if not has_unexpected_output: |
| @@ -366,9 +374,6 @@ class JsonTestProgressIndicator(ProgressIndicator): |
| "duration": test.duration, |
| }) |
| - def Heartbeat(self): |
| - self.progress_indicator.Heartbeat() |
| - |
| PROGRESS_INDICATORS = { |
| 'verbose': VerboseProgressIndicator, |