# Path: wokkel/compat.py
# class IQ(xmlstream.IQ):
#     def __init__(self, *args, **kwargs):
#         # Make sure we have a reactor parameter
#         try:
#             reactor = kwargs['reactor']
#         except KeyError:
#             from twisted.internet import reactor
#         kwargs['reactor'] = reactor
# 
#         # Check if IQ's init accepts the reactor parameter
#         try:
#             xmlstream.IQ.__init__(self, *args, **kwargs)
#         except TypeError:
#             # Guess not. Remove the reactor parameter and try again.
#             del kwargs['reactor']
#             xmlstream.IQ.__init__(self, *args, **kwargs)
# 
#             # Patch the XmlStream instance so that it has a _callLater
#             self._xmlstream._callLater = reactor.callLater


from zope.interface import implementer
from twisted.internet import task
from twisted.internet.interfaces import IReactorTime
from twisted.trial import unittest
from twisted.words.protocols.jabber import xmlstream
from wokkel.compat import IQ
        from twisted.words.xish import utility


@implementer(IReactorTime)
class FakeReactor(object):

    def __init__(self):
        self.clock = task.Clock()
        self.callLater = self.clock.callLater
        self.getDelayedCalls = self.clock.getDelayedCalls



class IQTest(unittest.TestCase):
    """
    Tests for L{IQ}.
    """

    def setUp(self):
        self.reactor = FakeReactor()
        self.clock = self.reactor.clock


    def testRequestTimingOutEventDispatcher(self):
        """
        Test that an iq request with a defined timeout times out.
        """
        output = []
        xs = utility.EventDispatcher()
        xs.send = output.append


# Path: wokkel/compat.py
# class IQ(xmlstream.IQ):
#     def __init__(self, *args, **kwargs):
#         # Make sure we have a reactor parameter
#         try:
#             reactor = kwargs['reactor']
#         except KeyError:
#             from twisted.internet import reactor
#         kwargs['reactor'] = reactor
# 
#         # Check if IQ's init accepts the reactor parameter
#         try:
#             xmlstream.IQ.__init__(self, *args, **kwargs)
#         except TypeError:
#             # Guess not. Remove the reactor parameter and try again.
#             del kwargs['reactor']
#             xmlstream.IQ.__init__(self, *args, **kwargs)
# 
#             # Patch the XmlStream instance so that it has a _callLater
#             self._xmlstream._callLater = reactor.callLater


# Path: wokkel/test/test_compat.py
from zope.interface import implementer
from twisted.internet import task
from twisted.internet.interfaces import IReactorTime
from twisted.trial import unittest
from twisted.words.protocols.jabber import xmlstream
from wokkel.compat import IQ
        from twisted.words.xish import utility



@implementer(IReactorTime)
class FakeReactor(object):

    def __init__(self):
        self.clock = task.Clock()
        self.callLater = self.clock.callLater
        self.getDelayedCalls = self.clock.getDelayedCalls



class IQTest(unittest.TestCase):
    """
    Tests for L{IQ}.
    """

    def setUp(self):
        self.reactor = FakeReactor()
        self.clock = self.reactor.clock


    def testRequestTimingOutEventDispatcher(self):
        """
        Test that an iq request with a defined timeout times out.
        """
        output = []
        xs = utility.EventDispatcher()
        xs.send = output.append


        self.iq = IQ(xs, reactor=self.reactor)