Пример #1
0
 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"))
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
 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"))
Пример #5
0
 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())
Пример #6
0
 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)
Пример #7
0
 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"))
Пример #8
0
 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))
Пример #9
0
 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))
Пример #10
0
 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"))
Пример #11
0
 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', [])
Пример #12
0
 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)
Пример #13
0
 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', [])
Пример #14
0
 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)
Пример #15
0
 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())
Пример #16
0
 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
Пример #17
0
 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)
Пример #18
0
 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
Пример #19
0
    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)
Пример #20
0
 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)
Пример #21
0
 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
Пример #22
0
 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
Пример #23
0
 def getSkip(self):
     return util.acquireAttribute(self._parents, "skip", None)
Пример #24
0
 def getSuppress(self):
     return util.acquireAttribute(self._parents, 'suppress', [])
Пример #25
0
 def getTodo(self):
     todo = util.acquireAttribute(self._parents, 'todo', None)
     if todo is None:
         return None
     return makeTodo(todo)
Пример #26
0
 def getSuppress(self):
     return util.acquireAttribute(self._parents, "suppress", [])
Пример #27
0
 def getSkip(self):
     return util.acquireAttribute(self._parents, 'skip', None)
Пример #28
0
 def getTodo(self):
     todo = util.acquireAttribute(self._parents, "todo", None)
     if todo is None:
         return None
     return makeTodo(todo)