PEP8: fix E211: whitespace before '('
[metze/samba/wip.git] / python / samba / subunit / __init__.py
1 # Subunit handling
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2014
3 #
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.
8 #
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.
13 #
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/>.
16 #
17
18 """Subunit test protocol."""
19
20 import samba
21
22 samba.ensure_third_party_module("iso8601", "pyiso8601")
23 import iso8601
24
25 import unittest
26
27
28 PROGRESS_SET = 0
29 PROGRESS_CUR = 1
30 PROGRESS_PUSH = 2
31 PROGRESS_POP = 3
32
33
34 def RemoteError(description=""):
35     return (Exception, Exception(description), None)
36
37
38 class RemotedTestCase(unittest.TestCase):
39     """A class to represent test cases run in child processes.
40
41     Instances of this class are used to provide the Python test API a TestCase
42     that can be printed to the screen, introspected for metadata and so on.
43     However, as they are a simply a memoisation of a test that was actually
44     run in the past by a separate process, they cannot perform any interactive
45     actions.
46     """
47
48     def __eq__(self, other):
49         try:
50             return self.__description == other.__description
51         except AttributeError:
52             return False
53
54     def __init__(self, description):
55         """Create a psuedo test case with description description."""
56         self.__description = description
57
58     def error(self, label):
59         raise NotImplementedError("%s on RemotedTestCases is not permitted." %
60                                   label)
61
62     def setUp(self):
63         self.error("setUp")
64
65     def tearDown(self):
66         self.error("tearDown")
67
68     def shortDescription(self):
69         return self.__description
70
71     def id(self):
72         return "%s" % (self.__description,)
73
74     def __str__(self):
75         return "%s (%s)" % (self.__description, self._strclass())
76
77     def __repr__(self):
78         return "<%s description='%s'>" % \
79                (self._strclass(), self.__description)
80
81     def run(self, result=None):
82         if result is None: result = self.defaultTestResult()
83         result.startTest(self)
84         result.addError(self, RemoteError("Cannot run RemotedTestCases.\n"))
85         result.stopTest(self)
86
87     def _strclass(self):
88         cls = self.__class__
89         return "%s.%s" % (cls.__module__, cls.__name__)