def test_foundOnLaterObject(self): """ The same as L{test_foundOnEarlierObject}, but for the case where the 2nd element in the object list has the attribute and the first does not. """ self.value = value = object() self.assertTrue(value is acquireAttribute([object(), self], "value"))
def getTimeout(self): """ Determine how long to run the test before considering it failed. @return: A C{int} or C{float} giving a number of seconds. """ return acquireAttribute(self._parents, 'timeout', DEFAULT_TIMEOUT_DURATION)
def setUp(self): # Scale time if configured scale = util.acquireAttribute(self._parents, "timescale", None) if scale is not None: time.scale(scale) else: time.reset() self.info("Test running with timescale: %r", time._get_scale())
def getSlow(self): """ Return whether this test has been marked as slow. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a C{slow} attribute, returns that. Returns C{False} if it cannot find anything. """ return util.acquireAttribute(self._parents, 'slow', False)
def test_foundOnEarlierObject(self): """ The value returned by L{acquireAttribute} is the value of the requested attribute on the first object in the list passed in which has that attribute. """ self.value = value = object() self.assertTrue(value is acquireAttribute([self, object()], "value"))
def test_notFoundDefault(self): """ If none of the objects passed in the list to L{acquireAttribute} have the requested attribute and a default value is given, the default value is returned. """ default = object() self.assertTrue(default is acquireAttribute([object()], "foo", default))
def _getSuppress(self): """ Returns any warning suppressions set for this test. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a C{suppress} attribute, returns that. Returns any empty list (i.e. suppress no warnings) if it cannot find anything. See L{TestCase} docstring for more details. """ return util.acquireAttribute(self._parents, 'suppress', [])
def getSkip(self): """ Return the skip reason set on this test, if any is set. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a C{skip} attribute, returns that. Returns L{None} if it cannot find anything. See L{TestCase} docstring for more details. """ return util.acquireAttribute(self._parents, 'skip', None)
def getSkip(self): """ Return the skip reason set on this test, if any is set. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a C{skip} attribute, returns that. Returns C{None} if it cannot find anything. See L{TestCase} docstring for more details. """ return util.acquireAttribute(self._parents, 'skip', None)
def setUp(self): log.test_reset() self.assert_not_skipped() # Scale time if configured scale = util.acquireAttribute(self._parents, 'timescale', None) if scale is not None: time.scale(scale) else: time.reset() self.info("Test running with timescale: %r", time._get_scale())
def getTimeout(self): timeout = util.acquireAttribute(self._parents, "timeout", util.DEFAULT_TIMEOUT_DURATION) try: return float(timeout) except (ValueError, TypeError): # XXX -- this is here because sometimes people will have methods # called 'timeout', or set timeout to 'orange', or something # Particularly, test_news.NewsTestCase and ReactorCoreTestCase # both do this. warnings.warn("'timeout' attribute needs to be a number.", category=DeprecationWarning) return util.DEFAULT_TIMEOUT_DURATION
def getTodo(self): """ Return a L{Todo} object if the test is marked todo. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a C{todo} attribute, returns that. Returns C{None} if it cannot find anything. See L{TestCase} docstring for more details. """ todo = util.acquireAttribute(self._parents, 'todo', None) if todo is None: return None return makeTodo(todo)
def getTimeout(self): timeout = util.acquireAttribute(self._parents, 'timeout', util.DEFAULT_TIMEOUT_DURATION) try: return float(timeout) except (ValueError, TypeError): # XXX -- this is here because sometimes people will have methods # called 'timeout', or set timeout to 'orange', or something # Particularly, test_news.NewsTestCase and ReactorCoreTestCase # both do this. warnings.warn("'timeout' attribute needs to be a number.", category=DeprecationWarning) return util.DEFAULT_TIMEOUT_DURATION
def __init__(self, methodName=' impossible-name '): log_keeper = log.get_default() or log.FluLogKeeper() log.LogProxy.__init__(self, log_keeper) log.Logger.__init__(self, self) # Twisted changed the TestCase.__init__ signature several # times. # # In versions older than 2.1.0 there was no __init__ method. # # In versions 2.1.0 up to 2.4.0 there is a __init__ method # with a methodName kwarg that has a default value of None. # # In version 2.5.0 the default value of the kwarg was changed # to "runTest". # # In versions above 2.5.0 God only knows what's the default # value, as we do not currently support them. import inspect if not inspect.ismethod(unittest.TestCase.__init__): # it's Twisted < 2.1.0 unittest.TestCase.__init__(self) else: # it's Twisted >= 2.1.0 if methodName == ' impossible-name ': # we've been called with no parameters, use the # default parameter value from the superclass defaults = inspect.getargspec(unittest.TestCase.__init__)[3] methodName = defaults[0] unittest.TestCase.__init__(self, methodName=methodName) self.log_name = self.id() # Skip slow tests if '--skip-slow' option is enabled if _getConfig().get('skip-slow'): if self.getSlow() and not self.getSkip(): self.skip = 'slow test' # Handle configurable attributes for attr in self.configurable_attributes: value = util.acquireAttribute(self._parents, attr, None) if value is not None: setattr(self, attr, value)
def getSkip(self) -> Tuple[bool, Optional[str]]: """ Return the skip reason set on this test, if any is set. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a C{skip} attribute, returns that in a tuple (L{True}, L{str}). If the C{skip} attribute does not exist, look for C{__unittest_skip__} and C{__unittest_skip_why__} attributes which are set by the standard library L{unittest.skip} function. Returns (L{False}, L{None}) if it cannot find anything. See L{TestCase} docstring for more details. """ skipReason = util.acquireAttribute(self._parents, 'skip', None) doSkip = skipReason is not None if skipReason is None: doSkip = getattr(self, "__unittest_skip__", False) if doSkip: skipReason = getattr(self, "__unittest_skip_why__", "") return (doSkip, skipReason)
def getTimeout(self): """ Returns the timeout value set on this test. Checks on the instance first, then the class, then the module, then packages. As soon as it finds something with a C{timeout} attribute, returns that. Returns L{util.DEFAULT_TIMEOUT_DURATION} if it cannot find anything. See L{TestCase} docstring for more details. """ timeout = util.acquireAttribute(self._parents, 'timeout', util.DEFAULT_TIMEOUT_DURATION) try: return float(timeout) except (ValueError, TypeError): # XXX -- this is here because sometimes people will have methods # called 'timeout', or set timeout to 'orange', or something # Particularly, test_news.NewsTestCase and ReactorCoreTestCase # both do this. warnings.warn("'timeout' attribute needs to be a number.", category=DeprecationWarning) return util.DEFAULT_TIMEOUT_DURATION
def getSkip(self): return util.acquireAttribute(self._parents, "skip", None)
def getSuppress(self): return util.acquireAttribute(self._parents, 'suppress', [])
def getTodo(self): todo = util.acquireAttribute(self._parents, 'todo', None) if todo is None: return None return makeTodo(todo)
def getSuppress(self): return util.acquireAttribute(self._parents, "suppress", [])
def getSkip(self): return util.acquireAttribute(self._parents, 'skip', None)
def getTodo(self): todo = util.acquireAttribute(self._parents, "todo", None) if todo is None: return None return makeTodo(todo)