diff options
author | David Robertson <davidr@element.io> | 2023-03-23 13:46:23 +0000 |
---|---|---|
committer | David Robertson <davidr@element.io> | 2023-03-23 13:54:19 +0000 |
commit | 024c8df0132777013c9cfb910710dfbac0f52c0d (patch) | |
tree | b87576c86fccd0fa72847543ee2406eee1e6ac5b | |
parent | Try the mypy-zope branch (diff) | |
download | synapse-024c8df0132777013c9cfb910710dfbac0f52c0d.tar.xz |
Revert checked_cast changes
-rw-r--r-- | tests/http/federation/test_matrix_federation_agent.py | 10 | ||||
-rw-r--r-- | tests/http/test_proxyagent.py | 22 | ||||
-rw-r--r-- | tests/logging/test_remote_handler.py | 13 | ||||
-rw-r--r-- | tests/unittest.py | 6 |
4 files changed, 31 insertions, 20 deletions
diff --git a/tests/http/federation/test_matrix_federation_agent.py b/tests/http/federation/test_matrix_federation_agent.py index eb7f53fee5..c4e07efb03 100644 --- a/tests/http/federation/test_matrix_federation_agent.py +++ b/tests/http/federation/test_matrix_federation_agent.py @@ -63,7 +63,7 @@ from tests.http import ( get_test_ca_cert_file, ) from tests.server import FakeTransport, ThreadedMemoryReactorClock -from tests.utils import checked_cast, default_config +from tests.utils import default_config logger = logging.getLogger(__name__) @@ -147,9 +147,8 @@ class MatrixFederationAgentTests(unittest.TestCase): # Normally this would be done by the TCP socket code in Twisted, but we are # stubbing that out here. # NB: we use a checked_cast here to workaround https://github.com/Shoobx/mypy-zope/issues/91) - client_protocol = checked_cast( - _WrappingProtocol, client_factory.buildProtocol(dummy_address) - ) + client_protocol = client_factory.buildProtocol(dummy_address) + assert isinstance(client_protocol, _WrappingProtocol) client_protocol.makeConnection( FakeTransport(server_protocol, self.reactor, client_protocol) ) @@ -467,7 +466,8 @@ class MatrixFederationAgentTests(unittest.TestCase): assert isinstance(proxy_server_transport, FakeTransport) client_protocol = proxy_server_transport.other assert isinstance(client_protocol, Protocol) - c2s_transport = checked_cast(FakeTransport, client_protocol.transport) + c2s_transport = client_protocol.transport + assert isinstance(c2s_transport, FakeTransport) c2s_transport.other = server_ssl_protocol self.reactor.advance(0) diff --git a/tests/http/test_proxyagent.py b/tests/http/test_proxyagent.py index cc175052ac..744eda9adb 100644 --- a/tests/http/test_proxyagent.py +++ b/tests/http/test_proxyagent.py @@ -43,7 +43,6 @@ from tests.http import ( ) from tests.server import FakeTransport, ThreadedMemoryReactorClock from tests.unittest import TestCase -from tests.utils import checked_cast logger = logging.getLogger(__name__) @@ -645,7 +644,8 @@ class MatrixFederationAgentTests(TestCase): assert isinstance(proxy_server_transport, FakeTransport) client_protocol = proxy_server_transport.other assert isinstance(client_protocol, Protocol) - c2s_transport = checked_cast(FakeTransport, client_protocol.transport) + c2s_transport = client_protocol.transport + assert isinstance(c2s_transport, FakeTransport) c2s_transport.other = server_ssl_protocol self.reactor.advance(0) @@ -763,9 +763,12 @@ class MatrixFederationAgentTests(TestCase): # https://github.com/Shoobx/mypy-zope/issues/91 . # We also double-checked these casts at runtime (test-time) because I found it # quite confusing to deduce these types in the first place! - s2c_transport = checked_cast(FakeTransport, proxy_server.transport) - client_protocol = checked_cast(_WrappingProtocol, s2c_transport.other) - c2s_transport = checked_cast(FakeTransport, client_protocol.transport) + s2c_transport = proxy_server.transport + assert isinstance(s2c_transport, FakeTransport) + client_protocol = s2c_transport.other + assert isinstance(client_protocol, _WrappingProtocol) + c2s_transport = client_protocol.transport + assert isinstance(c2s_transport, FakeTransport) # the FakeTransport is async, so we need to pump the reactor self.reactor.advance(0) @@ -825,7 +828,8 @@ class MatrixFederationAgentTests(TestCase): @patch.dict(os.environ, {"http_proxy": "proxy.com:8888"}) def test_proxy_with_no_scheme(self) -> None: http_proxy_agent = ProxyAgent(self.reactor, use_proxy=True) - proxy_ep = checked_cast(HostnameEndpoint, http_proxy_agent.http_proxy_endpoint) + proxy_ep = http_proxy_agent.http_proxy_endpoint + assert isinstance(proxy_ep, HostnameEndpoint) self.assertEqual(proxy_ep._hostStr, "proxy.com") self.assertEqual(proxy_ep._port, 8888) @@ -837,14 +841,16 @@ class MatrixFederationAgentTests(TestCase): @patch.dict(os.environ, {"http_proxy": "http://proxy.com:8888"}) def test_proxy_with_http_scheme(self) -> None: http_proxy_agent = ProxyAgent(self.reactor, use_proxy=True) - proxy_ep = checked_cast(HostnameEndpoint, http_proxy_agent.http_proxy_endpoint) + proxy_ep = http_proxy_agent.http_proxy_endpoint + assert isinstance(proxy_ep, HostnameEndpoint) self.assertEqual(proxy_ep._hostStr, "proxy.com") self.assertEqual(proxy_ep._port, 8888) @patch.dict(os.environ, {"http_proxy": "https://proxy.com:8888"}) def test_proxy_with_https_scheme(self) -> None: https_proxy_agent = ProxyAgent(self.reactor, use_proxy=True) - proxy_ep = checked_cast(_WrapperEndpoint, https_proxy_agent.http_proxy_endpoint) + proxy_ep = https_proxy_agent.http_proxy_endpoint + assert isinstance(proxy_ep, _WrapperEndpoint) self.assertEqual(proxy_ep._wrappedEndpoint._hostStr, "proxy.com") self.assertEqual(proxy_ep._wrappedEndpoint._port, 8888) diff --git a/tests/logging/test_remote_handler.py b/tests/logging/test_remote_handler.py index 5191e31a8a..0c83fc97fd 100644 --- a/tests/logging/test_remote_handler.py +++ b/tests/logging/test_remote_handler.py @@ -21,7 +21,6 @@ from synapse.logging import RemoteHandler from tests.logging import LoggerCleanupMixin from tests.server import FakeTransport, get_clock from tests.unittest import TestCase -from tests.utils import checked_cast def connect_logging_client( @@ -57,7 +56,8 @@ class RemoteHandlerTestCase(LoggerCleanupMixin, TestCase): client, server = connect_logging_client(self.reactor, 0) # Trigger data being sent - client_transport = checked_cast(FakeTransport, client.transport) + client_transport = client.transport + assert isinstance(client_transport, FakeTransport) client_transport.flush() # One log message, with a single trailing newline @@ -90,7 +90,8 @@ class RemoteHandlerTestCase(LoggerCleanupMixin, TestCase): # Allow the reconnection client, server = connect_logging_client(self.reactor, 0) - client_transport = checked_cast(FakeTransport, client.transport) + client_transport = client.transport + assert isinstance(client_transport, FakeTransport) client_transport.flush() # Only the 7 infos made it through, the debugs were elided @@ -124,7 +125,8 @@ class RemoteHandlerTestCase(LoggerCleanupMixin, TestCase): # Allow the reconnection client, server = connect_logging_client(self.reactor, 0) - client_transport = checked_cast(FakeTransport, client.transport) + client_transport = client.transport + assert isinstance(client_transport, FakeTransport) client_transport.flush() # The 10 warnings made it through, the debugs and infos were elided @@ -149,7 +151,8 @@ class RemoteHandlerTestCase(LoggerCleanupMixin, TestCase): # Allow the reconnection client, server = connect_logging_client(self.reactor, 0) - client_transport = checked_cast(FakeTransport, client.transport) + client_transport = client.transport + assert isinstance(client_transport, FakeTransport) client_transport.flush() # The first five and last five warnings made it through, the debugs and diff --git a/tests/unittest.py b/tests/unittest.py index f9160faa1d..b9701b3c1d 100644 --- a/tests/unittest.py +++ b/tests/unittest.py @@ -82,7 +82,7 @@ from tests.server import ( ) from tests.test_utils import event_injection, setup_awaitable_errors from tests.test_utils.logging_setup import setup_logging -from tests.utils import checked_cast, default_config, setupdb +from tests.utils import default_config, setupdb setupdb() setup_logging() @@ -296,9 +296,11 @@ class HomeserverTestCase(TestCase): from tests.rest.client.utils import RestHelper + reactor = self.hs.get_reactor() + assert isinstance(reactor, MemoryReactorClock) self.helper = RestHelper( self.hs, - checked_cast(MemoryReactorClock, self.hs.get_reactor()), + reactor, self.site, getattr(self, "user_id", None), ) |