OLD | NEW |
(Empty) | |
| 1 # Copyright (C) 2013 Free Software Foundation, Inc. |
| 2 |
| 3 # This program is free software; you can redistribute it and/or modify |
| 4 # it under the terms of the GNU General Public License as published by |
| 5 # the Free Software Foundation; either version 3 of the License, or |
| 6 # (at your option) any later version. |
| 7 # |
| 8 # This program is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. |
| 12 # |
| 13 # You should have received a copy of the GNU General Public License |
| 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
| 16 class TestResult(object): |
| 17 """Base class to record and report test results. |
| 18 |
| 19 Method record is to record the results of test case, and report |
| 20 method is to report the recorded results by a given reporter. |
| 21 """ |
| 22 |
| 23 def record(self, parameter, result): |
| 24 raise NotImplementedError("Abstract Method:record.") |
| 25 |
| 26 def report(self, reporter, name): |
| 27 """Report the test results by reporter.""" |
| 28 raise NotImplementedError("Abstract Method:report.") |
| 29 |
| 30 class SingleStatisticTestResult(TestResult): |
| 31 """Test results for the test case with a single statistic.""" |
| 32 |
| 33 def __init__(self): |
| 34 super (SingleStatisticTestResult, self).__init__ () |
| 35 self.results = dict () |
| 36 |
| 37 def record(self, parameter, result): |
| 38 self.results[parameter] = result |
| 39 |
| 40 def report(self, reporter, name): |
| 41 reporter.start() |
| 42 for key in sorted(self.results.iterkeys()): |
| 43 reporter.report(name, key, self.results[key]) |
| 44 reporter.end() |
| 45 |
| 46 class ResultFactory(object): |
| 47 """A factory to create an instance of TestResult.""" |
| 48 |
| 49 def create_result(self): |
| 50 """Create an instance of TestResult.""" |
| 51 raise NotImplementedError("Abstract Method:create_result.") |
| 52 |
| 53 class SingleStatisticResultFactory(ResultFactory): |
| 54 """A factory to create an instance of SingleStatisticTestResult.""" |
| 55 |
| 56 def create_result(self): |
| 57 return SingleStatisticTestResult() |
OLD | NEW |