source: wokkel/test/test_compat.py @ 200:ab43d6940b65

Last change on this file since 200:ab43d6940b65 was 200:ab43d6940b65, checked in by Ralph Meijer <ralphm@…>, 6 years ago

imported patch py3-compat.patch

  • Property exe set to *
File size: 1.4 KB
Line 
1# Copyright (c) Twisted Matrix Laboratories.
2# Copyright (c) Ralph Meijer.
3# See LICENSE for details.
4
5"""
6Tests for L{wokkel.compat}.
7"""
8
9from __future__ import division, absolute_import
10
11from zope.interface import implementer
12from twisted.internet import task
13from twisted.internet.interfaces import IReactorTime
14from twisted.trial import unittest
15from twisted.words.protocols.jabber import xmlstream
16
17from wokkel.compat import IQ
18
19@implementer(IReactorTime)
20class FakeReactor(object):
21
22    def __init__(self):
23        self.clock = task.Clock()
24        self.callLater = self.clock.callLater
25        self.getDelayedCalls = self.clock.getDelayedCalls
26
27
28
29class IQTest(unittest.TestCase):
30    """
31    Tests for L{IQ}.
32    """
33
34    def setUp(self):
35        self.reactor = FakeReactor()
36        self.clock = self.reactor.clock
37
38
39    def testRequestTimingOutEventDispatcher(self):
40        """
41        Test that an iq request with a defined timeout times out.
42        """
43        from twisted.words.xish import utility
44        output = []
45        xs = utility.EventDispatcher()
46        xs.send = output.append
47
48        self.iq = IQ(xs, reactor=self.reactor)
49        self.iq.timeout = 60
50        d = self.iq.send()
51        self.assertFailure(d, xmlstream.TimeoutError)
52
53        self.clock.pump([1, 60])
54        self.assertFalse(self.reactor.getDelayedCalls())
55        self.assertFalse(xs.iqDeferreds)
56        return d
Note: See TracBrowser for help on using the repository browser.