1 # Copyright (C) 2013-2022 Free Software Foundation, Inc.
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.
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.
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/>.
17 class TestResult(object):
18 """Base class to record and report test results.
20 Method record is to record the results of test case, and report
21 method is to report the recorded results by a given reporter.
24 def record(self, parameter, result):
25 raise NotImplementedError("Abstract Method:record.")
27 def report(self, reporter, name):
28 """Report the test results by reporter."""
29 raise NotImplementedError("Abstract Method:report.")
32 class SingleStatisticTestResult(TestResult):
33 """Test results for the test case with a single statistic."""
36 super(SingleStatisticTestResult, self).__init__()
39 def record(self, parameter, result):
40 if parameter in self.results:
41 self.results[parameter].append(result)
43 self.results[parameter] = [result]
45 def report(self, reporter, name):
47 for key in sorted(self.results.keys()):
48 reporter.report(name, key, self.results[key])
52 class ResultFactory(object):
53 """A factory to create an instance of TestResult."""
55 def create_result(self):
56 """Create an instance of TestResult."""
57 raise NotImplementedError("Abstract Method:create_result.")
60 class SingleStatisticResultFactory(ResultFactory):
61 """A factory to create an instance of SingleStatisticTestResult."""
63 def create_result(self):
64 return SingleStatisticTestResult()