Ticket #8113: memory-reactory-interface.patch

File memory-reactory-interface.patch, 3.6 KB (added by Reuben, 6 years ago)

Adds IReactorCore interface to MemoryReactor

  • twisted/test/proto_helpers.py

    diff --git twisted/test/proto_helpers.py twisted/test/proto_helpers.py
    index 3b0d27f..517ec17 100644
    from twisted.python import failure 
    1818from twisted.python.compat import unicode
    1919from twisted.internet.interfaces import (
    2020    ITransport, IConsumer, IPushProducer, IConnector, IReactorTCP, IReactorSSL,
    21     IReactorUNIX, IReactorSocket, IListeningPort, IReactorFDSet
     21    IReactorUNIX, IReactorSocket, IListeningPort, IReactorFDSet, IReactorCore
    2222)
    2323from twisted.internet.abstract import isIPv6Address
    2424from twisted.internet.error import UnsupportedAddressFamily
    class _FakeConnector(object): 
    370370
    371371
    372372@implementer(
    373     IReactorTCP, IReactorSSL, IReactorUNIX, IReactorSocket, IReactorFDSet
     373    IReactorTCP, IReactorSSL, IReactorUNIX, IReactorSocket, IReactorFDSet,
     374    IReactorCore
    374375)
    375376class MemoryReactor(object):
    376377    """
    class MemoryReactor(object): 
    425426
    426427        self.readers = set()
    427428        self.writers = set()
     429        self.running = False
    428430
    429431
    430432    def adoptStreamPort(self, fileno, addressFamily, factory):
    class MemoryReactor(object): 
    602604        self.readers.clear()
    603605        self.writers.clear()
    604606
     607    def resolve(*args, **kw):
     608        """
     609        Return a L{twisted.internet.defer.Deferred} that will resolve a hostname.
     610        """
     611
     612    def run():
     613        """
     614        Fake L{IReactorCore.run}.
     615        """
     616        self.running = True
     617
     618    def stop():
     619        """
     620        Fake L{IReactorCore.stop}.
     621        """
     622        self.running = False
     623
     624    def crash():
     625        """
     626        Fake L{IReactorCore.crash}.
     627        """
     628        self.running = False
     629
     630    def iterate(*args, **kw):
     631        """
     632        Fake L{IReactorCore.iterate}.
     633        """
     634        pass
     635
     636    def fireSystemEvent(*args, **kw):
     637        """
     638        Fake L{IReactorCore.fireSystemEvent}.
     639        """
     640        pass
     641
     642    def addSystemEventTrigger(*args, **kw):
     643        """
     644        Fake L{IReactorCore.addSystemEventTrigger}.
     645        """
     646        pass
     647
     648    def removeSystemEventTrigger(*args, **kw):
     649        """
     650        Fake L{IReactorCore.removeSystemEventTrigger}.
     651        """
     652        pass
     653
     654    def callWhenRunning(*args, **kw):
     655        """
     656        Fake L{IReactorCore.callWhenRunning}.
     657        """
     658        pass
    605659
    606660for iface in implementedBy(MemoryReactor):
    607661    verifyClass(iface, MemoryReactor)
  • twisted/test/test_protocols.py

    diff --git twisted/test/test_protocols.py twisted/test/test_protocols.py
    index 4e10b48..51126a4 100644
     
    55Test cases for twisted.protocols package.
    66"""
    77
     8import sys
     9
    810from twisted.trial import unittest
    911from twisted.protocols import wire, portforward
    10 from twisted.internet import reactor, defer, address, protocol
     12from twisted.internet import reactor, defer, address, protocol, fdesc, abstract
    1113from twisted.test import proto_helpers
    1214
    1315
    class StringTransportTests(unittest.TestCase): 
    234236        """
    235237        s = proto_helpers.StringTransport()
    236238        self.assertRaises(TypeError, s.write, u'foo')
     239
     240
     241class MemoryReactorTests(unittest.TestCase):
     242    """
     243    Test L{proto_helpers.MemoryReactor} helper behaviour.
     244    """
     245
     246    def test_fdesc(self):
     247        """
     248        Test that L{proto_helpers.MemoryReactor} can be used with fdesc.
     249        """
     250        reactor = proto_helpers.MemoryReactor()
     251        f = abstract.FileDescriptor(reactor)
     252        f.fileno = sys.__stdout__.fileno
     253        fd = f.fileno()
     254        fdesc.setNonBlocking(fd)
     255        fdesc.readFromFD(fd, self.assertTrue)