Ticket #3908: testable-examples-6362-1.patch

File testable-examples-6362-1.patch, 2.2 KB (added by Richard Wall, 7 years ago)

This is the patch where I pass the reactor through

  • doc/names/examples/testdns.py

     
    7777        raise SystemExit(1)
    7878
    7979    domainname = options['domainname']
    80     r = client.Resolver('/etc/resolv.conf')
     80    r = client.Resolver('/etc/resolv.conf', reactor=reactor)
    8181    d = defer.gatherResults([
    8282            r.lookupAddress(domainname).addCallback(
    8383                formatRecords, 'Addresses'),
  • twisted/names/client.py

     
    209209        Return a new L{DNSDatagramProtocol} bound to a randomly selected port
    210210        number.
    211211        """
    212         proto = dns.DNSDatagramProtocol(self)
     212        proto = dns.DNSDatagramProtocol(self, reactor=self._reactor)
    213213        while True:
    214214            try:
    215215                self._reactor.listenUDP(dns.randomSource(), proto)
  • twisted/names/test/test_examples.py

     
    1111from twisted.names import client, error
    1212from twisted.test.testutils import StandardExecutableExampleTestBase
    1313from twisted.trial.unittest import TestCase
     14from twisted.names.test.test_rootresolve import MemoryReactor
    1415
    1516
    16 
    17 
    1817class TestDnsTests(StandardExecutableExampleTestBase, TestCase):
    1918    """
    2019    Test the testdns.py example script.
     
    2423    positionalArgCount = 1
    2524
    2625
     26    def test_mainReturnsDeferred(self):
     27        """
     28        L{testdns.main} when called with valid arguments, returns a
     29        deferred which is important for compatibility with
     30        L{twisted.internet.task.react}.
     31        """
    2732
     33        # DelayedCall.debug = True
     34        d = self.example.main(MemoryReactor(), 'foo.bar.example.com')
     35        self.assertIsInstance(d, defer.Deferred)
     36
     37
     38
    2839class GetHostByNameTests(StandardExecutableExampleTestBase, TestCase):
    2940    """
    3041    Test the gethostbyname.py example script.