Silence improper typing of twisted.internet.reactor in tests.

This commit is contained in:
Andrey Rakhmatullin 2023-01-25 22:15:07 +04:00
parent c0ea7fd4fd
commit 2e33fb812b
4 changed files with 15 additions and 12 deletions

View File

@ -37,11 +37,11 @@ if __name__ == "__main__":
root = Root()
factory = Site(root)
httpPort = reactor.listenTCP(8998, Site(root))
httpPort = reactor.listenTCP(8998, Site(root)) # type: ignore[attr-defined]
def _print_listening():
httpHost = httpPort.getHost()
print(f"Bench server at http://{httpHost.host}:{httpHost.port}")
reactor.callWhenRunning(_print_listening)
reactor.run()
reactor.callWhenRunning(_print_listening) # type: ignore[attr-defined]
reactor.run() # type: ignore[attr-defined]

View File

@ -41,10 +41,10 @@ if __name__ == "__main__":
url = f"http://not.a.real.domain:{port}/echo"
servers = [(mock_dns_server.host, mock_dns_server.port)]
reactor.installResolver(createResolver(servers=servers))
reactor.installResolver(createResolver(servers=servers)) # type: ignore[attr-defined]
configure_logging()
runner = CrawlerRunner()
d = runner.crawl(LocalhostSpider, url=url)
d.addBoth(lambda _: reactor.stop())
reactor.run()
d.addBoth(lambda _: reactor.stop()) # type: ignore[attr-defined]
reactor.run() # type: ignore[attr-defined]

View File

@ -10,6 +10,7 @@ from urllib.parse import urlencode
from OpenSSL import SSL
from twisted.internet import defer, reactor, ssl
from twisted.internet.protocol import ServerFactory
from twisted.internet.task import deferLater
from twisted.names import dns, error
from twisted.names.server import DNSServerFactory
@ -369,12 +370,14 @@ if __name__ == "__main__":
)
args = parser.parse_args()
factory: ServerFactory
if args.type == "http":
root = Root()
factory = Site(root)
httpPort = reactor.listenTCP(0, factory)
httpPort = reactor.listenTCP(0, factory) # type: ignore[attr-defined]
contextFactory = ssl_context_factory()
httpsPort = reactor.listenSSL(0, factory, contextFactory)
httpsPort = reactor.listenSSL(0, factory, contextFactory) # type: ignore[attr-defined]
def print_listening():
httpHost = httpPort.getHost()
@ -388,11 +391,11 @@ if __name__ == "__main__":
clients = [MockDNSResolver()]
factory = DNSServerFactory(clients=clients)
protocol = dns.DNSDatagramProtocol(controller=factory)
listener = reactor.listenUDP(0, protocol)
listener = reactor.listenUDP(0, protocol) # type: ignore[attr-defined]
def print_listening():
host = listener.getHost()
print(f"{host.host}:{host.port}")
reactor.callWhenRunning(print_listening)
reactor.run()
reactor.callWhenRunning(print_listening) # type: ignore[attr-defined]
reactor.run() # type: ignore[attr-defined]

View File

@ -557,4 +557,4 @@ class EngineTest(unittest.TestCase):
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "runserver":
start_test_site(debug=True)
reactor.run()
reactor.run() # type: ignore[attr-defined]