Add some type hints to tests files (#12833)

Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
pull/12842/head
Dirk Klimpel 2022-05-23 13:23:26 +02:00 committed by GitHub
parent 438925c422
commit 444588c5fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 23 deletions

1
changelog.d/12833.misc Normal file
View File

@ -0,0 +1 @@
Add some type hints to test files.

View File

@ -41,16 +41,11 @@ exclude = (?x)
|tests/events/test_utils.py |tests/events/test_utils.py
|tests/federation/test_federation_catch_up.py |tests/federation/test_federation_catch_up.py
|tests/federation/test_federation_sender.py |tests/federation/test_federation_sender.py
|tests/federation/test_federation_server.py
|tests/federation/transport/test_knocking.py |tests/federation/transport/test_knocking.py
|tests/federation/transport/test_server.py
|tests/handlers/test_typing.py |tests/handlers/test_typing.py
|tests/http/federation/test_matrix_federation_agent.py |tests/http/federation/test_matrix_federation_agent.py
|tests/http/federation/test_srv_resolver.py |tests/http/federation/test_srv_resolver.py
|tests/http/test_fedclient.py
|tests/http/test_proxyagent.py |tests/http/test_proxyagent.py
|tests/http/test_servlet.py
|tests/http/test_site.py
|tests/logging/__init__.py |tests/logging/__init__.py
|tests/logging/test_terse_json.py |tests/logging/test_terse_json.py
|tests/module_api/test_api.py |tests/module_api/test_api.py
@ -59,12 +54,9 @@ exclude = (?x)
|tests/push/test_push_rule_evaluator.py |tests/push/test_push_rule_evaluator.py
|tests/rest/client/test_transactions.py |tests/rest/client/test_transactions.py
|tests/rest/media/v1/test_media_storage.py |tests/rest/media/v1/test_media_storage.py
|tests/scripts/test_new_matrix_user.py
|tests/server.py |tests/server.py
|tests/server_notices/test_resource_limits_server_notices.py |tests/server_notices/test_resource_limits_server_notices.py
|tests/state/test_v2.py |tests/state/test_v2.py
|tests/storage/test_base.py
|tests/storage/test_roommember.py
|tests/test_metrics.py |tests/test_metrics.py
|tests/test_server.py |tests/test_server.py
|tests/test_state.py |tests/test_state.py

View File

@ -49,19 +49,21 @@ class TestServletUtils(unittest.TestCase):
"""Basic tests for parse_json_value_from_request.""" """Basic tests for parse_json_value_from_request."""
# Test round-tripping. # Test round-tripping.
obj = {"foo": 1} obj = {"foo": 1}
result = parse_json_value_from_request(make_request(obj)) result1 = parse_json_value_from_request(make_request(obj))
self.assertEqual(result, obj) self.assertEqual(result1, obj)
# Results don't have to be objects. # Results don't have to be objects.
result = parse_json_value_from_request(make_request(b'["foo"]')) result2 = parse_json_value_from_request(make_request(b'["foo"]'))
self.assertEqual(result, ["foo"]) self.assertEqual(result2, ["foo"])
# Test empty. # Test empty.
with self.assertRaises(SynapseError): with self.assertRaises(SynapseError):
parse_json_value_from_request(make_request(b"")) parse_json_value_from_request(make_request(b""))
result = parse_json_value_from_request(make_request(b""), allow_empty_body=True) result3 = parse_json_value_from_request(
self.assertIsNone(result) make_request(b""), allow_empty_body=True
)
self.assertIsNone(result3)
# Invalid UTF-8. # Invalid UTF-8.
with self.assertRaises(SynapseError): with self.assertRaises(SynapseError):

View File

@ -36,7 +36,7 @@ class SynapseRequestTestCase(HomeserverTestCase):
# as a control case, first send a regular request. # as a control case, first send a regular request.
# complete the connection and wire it up to a fake transport # complete the connection and wire it up to a fake transport
client_address = IPv6Address("TCP", "::1", "2345") client_address = IPv6Address("TCP", "::1", 2345)
protocol = factory.buildProtocol(client_address) protocol = factory.buildProtocol(client_address)
transport = StringTransport() transport = StringTransport()
protocol.makeConnection(transport) protocol.makeConnection(transport)

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from typing import List
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
from synapse._scripts.register_new_matrix_user import request_registration from synapse._scripts.register_new_matrix_user import request_registration
@ -49,8 +50,8 @@ class RegisterTestCase(TestCase):
requests.post = post requests.post = post
# The fake stdout will be written here # The fake stdout will be written here
out = [] out: List[str] = []
err_code = [] err_code: List[int] = []
with patch("synapse._scripts.register_new_matrix_user.requests", requests): with patch("synapse._scripts.register_new_matrix_user.requests", requests):
request_registration( request_registration(
@ -85,8 +86,8 @@ class RegisterTestCase(TestCase):
requests.get = get requests.get = get
# The fake stdout will be written here # The fake stdout will be written here
out = [] out: List[str] = []
err_code = [] err_code: List[int] = []
with patch("synapse._scripts.register_new_matrix_user.requests", requests): with patch("synapse._scripts.register_new_matrix_user.requests", requests):
request_registration( request_registration(
@ -137,8 +138,8 @@ class RegisterTestCase(TestCase):
requests.post = post requests.post = post
# The fake stdout will be written here # The fake stdout will be written here
out = [] out: List[str] = []
err_code = [] err_code: List[int] = []
with patch("synapse._scripts.register_new_matrix_user.requests", requests): with patch("synapse._scripts.register_new_matrix_user.requests", requests):
request_registration( request_registration(

View File

@ -60,7 +60,7 @@ class SQLBaseStoreTestCase(unittest.TestCase):
db = DatabasePool(Mock(), Mock(config=sqlite_config), fake_engine) db = DatabasePool(Mock(), Mock(config=sqlite_config), fake_engine)
db._db_pool = self.db_pool db._db_pool = self.db_pool
self.datastore = SQLBaseStore(db, None, hs) self.datastore = SQLBaseStore(db, None, hs) # type: ignore[arg-type]
@defer.inlineCallbacks @defer.inlineCallbacks
def test_insert_1col(self): def test_insert_1col(self):

View File

@ -34,7 +34,7 @@ class RoomMemberStoreTestCase(unittest.HomeserverTestCase):
room.register_servlets, room.register_servlets,
] ]
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: TestHomeServer) -> None: def prepare(self, reactor: MemoryReactor, clock: Clock, hs: TestHomeServer) -> None: # type: ignore[override]
# We can't test the RoomMemberStore on its own without the other event # We can't test the RoomMemberStore on its own without the other event
# storage logic # storage logic