s3:ntlm_auth: make logs more consistent with length check
[Samba.git] / python / samba / subunit / __init__.py
blobdab522e160bb4d4da7c39ef8a0398f36350addc4
1 # Subunit handling
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."""
20 import unittest
23 PROGRESS_SET = 0
24 PROGRESS_CUR = 1
25 PROGRESS_PUSH = 2
26 PROGRESS_POP = 3
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
40 actions.
41 """
43 def __eq__(self, other):
44 try:
45 return self.__description == other.__description
46 except AttributeError:
47 return False
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." %
55 label)
57 def setUp(self):
58 self.error("setUp")
60 def tearDown(self):
61 self.error("tearDown")
63 def shortDescription(self):
64 return self.__description
66 def id(self):
67 return "%s" % (self.__description,)
69 def __str__(self):
70 return "%s (%s)" % (self.__description, self._strclass())
72 def __repr__(self):
73 return "<%s description='%s'>" % \
74 (self._strclass(), self.__description)
76 def run(self, result=None):
77 if result is None:
78 result = self.defaultTestResult()
79 result.startTest(self)
80 result.addError(self, RemoteError("Cannot run RemotedTestCases.\n"))
81 result.stopTest(self)
83 def _strclass(self):
84 cls = self.__class__
85 return "%s.%s" % (cls.__module__, cls.__name__)