Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright (C) 2013-2016 Free Software Foundation, Inc. |
f27a1236 YQ |
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): | |
af061d3e DE |
38 | if parameter in self.results: |
39 | self.results[parameter].append(result) | |
40 | else: | |
41 | self.results[parameter] = [result] | |
f27a1236 YQ |
42 | |
43 | def report(self, reporter, name): | |
44 | reporter.start() | |
45 | for key in sorted(self.results.iterkeys()): | |
46 | reporter.report(name, key, self.results[key]) | |
47 | reporter.end() | |
48 | ||
49 | class ResultFactory(object): | |
50 | """A factory to create an instance of TestResult.""" | |
51 | ||
52 | def create_result(self): | |
53 | """Create an instance of TestResult.""" | |
54 | raise NotImplementedError("Abstract Method:create_result.") | |
55 | ||
56 | class SingleStatisticResultFactory(ResultFactory): | |
57 | """A factory to create an instance of SingleStatisticTestResult.""" | |
58 | ||
59 | def create_result(self): | |
60 | return SingleStatisticTestResult() |