2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2014
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Subunit test protocol."""
29 def RemoteError(description
=""):
30 return (Exception, Exception(description
), None)
33 class RemotedTestCase(unittest
.TestCase
):
34 """A class to represent test cases run in child processes.
36 Instances of this class are used to provide the Python test API a TestCase
37 that can be printed to the screen, introspected for metadata and so on.
38 However, as they are a simply a memoisation of a test that was actually
39 run in the past by a separate process, they cannot perform any interactive
43 def __eq__(self
, other
):
45 return self
.__description
== other
.__description
46 except AttributeError:
49 def __init__(self
, description
):
50 """Create a pseudo test case with description description."""
51 self
.__description
= description
53 def error(self
, label
):
54 raise NotImplementedError("%s on RemotedTestCases is not permitted." %
61 self
.error("tearDown")
63 def shortDescription(self
):
64 return self
.__description
67 return "%s" % (self
.__description
,)
70 return "%s (%s)" % (self
.__description
, self
._strclass
())
73 return "<%s description='%s'>" % \
74 (self
._strclass
(), self
.__description
)
76 def run(self
, result
=None):
78 result
= self
.defaultTestResult()
79 result
.startTest(self
)
80 result
.addError(self
, RemoteError("Cannot run RemotedTestCases.\n"))
85 return "%s.%s" % (cls
.__module
__, cls
.__name
__)