Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 444588c

Browse files
Add some type hints to tests files (#12833)
Co-authored-by: Andrew Morgan <[email protected]>
1 parent 438925c commit 444588c

File tree

7 files changed

+19
-23
lines changed

7 files changed

+19
-23
lines changed

changelog.d/12833.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add some type hints to test files.

mypy.ini

-8
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,11 @@ exclude = (?x)
4141
|tests/events/test_utils.py
4242
|tests/federation/test_federation_catch_up.py
4343
|tests/federation/test_federation_sender.py
44-
|tests/federation/test_federation_server.py
4544
|tests/federation/transport/test_knocking.py
46-
|tests/federation/transport/test_server.py
4745
|tests/handlers/test_typing.py
4846
|tests/http/federation/test_matrix_federation_agent.py
4947
|tests/http/federation/test_srv_resolver.py
50-
|tests/http/test_fedclient.py
5148
|tests/http/test_proxyagent.py
52-
|tests/http/test_servlet.py
53-
|tests/http/test_site.py
5449
|tests/logging/__init__.py
5550
|tests/logging/test_terse_json.py
5651
|tests/module_api/test_api.py
@@ -59,12 +54,9 @@ exclude = (?x)
5954
|tests/push/test_push_rule_evaluator.py
6055
|tests/rest/client/test_transactions.py
6156
|tests/rest/media/v1/test_media_storage.py
62-
|tests/scripts/test_new_matrix_user.py
6357
|tests/server.py
6458
|tests/server_notices/test_resource_limits_server_notices.py
6559
|tests/state/test_v2.py
66-
|tests/storage/test_base.py
67-
|tests/storage/test_roommember.py
6860
|tests/test_metrics.py
6961
|tests/test_server.py
7062
|tests/test_state.py

tests/http/test_servlet.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,21 @@ def test_parse_json_value(self):
4949
"""Basic tests for parse_json_value_from_request."""
5050
# Test round-tripping.
5151
obj = {"foo": 1}
52-
result = parse_json_value_from_request(make_request(obj))
53-
self.assertEqual(result, obj)
52+
result1 = parse_json_value_from_request(make_request(obj))
53+
self.assertEqual(result1, obj)
5454

5555
# Results don't have to be objects.
56-
result = parse_json_value_from_request(make_request(b'["foo"]'))
57-
self.assertEqual(result, ["foo"])
56+
result2 = parse_json_value_from_request(make_request(b'["foo"]'))
57+
self.assertEqual(result2, ["foo"])
5858

5959
# Test empty.
6060
with self.assertRaises(SynapseError):
6161
parse_json_value_from_request(make_request(b""))
6262

63-
result = parse_json_value_from_request(make_request(b""), allow_empty_body=True)
64-
self.assertIsNone(result)
63+
result3 = parse_json_value_from_request(
64+
make_request(b""), allow_empty_body=True
65+
)
66+
self.assertIsNone(result3)
6567

6668
# Invalid UTF-8.
6769
with self.assertRaises(SynapseError):

tests/http/test_site.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_large_request(self):
3636
# as a control case, first send a regular request.
3737

3838
# complete the connection and wire it up to a fake transport
39-
client_address = IPv6Address("TCP", "::1", "2345")
39+
client_address = IPv6Address("TCP", "::1", 2345)
4040
protocol = factory.buildProtocol(client_address)
4141
transport = StringTransport()
4242
protocol.makeConnection(transport)

tests/scripts/test_new_matrix_user.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from typing import List
1516
from unittest.mock import Mock, patch
1617

1718
from synapse._scripts.register_new_matrix_user import request_registration
@@ -49,8 +50,8 @@ def post(url, json=None, verify=None):
4950
requests.post = post
5051

5152
# The fake stdout will be written here
52-
out = []
53-
err_code = []
53+
out: List[str] = []
54+
err_code: List[int] = []
5455

5556
with patch("synapse._scripts.register_new_matrix_user.requests", requests):
5657
request_registration(
@@ -85,8 +86,8 @@ def get(url, verify=None):
8586
requests.get = get
8687

8788
# The fake stdout will be written here
88-
out = []
89-
err_code = []
89+
out: List[str] = []
90+
err_code: List[int] = []
9091

9192
with patch("synapse._scripts.register_new_matrix_user.requests", requests):
9293
request_registration(
@@ -137,8 +138,8 @@ def post(url, json=None, verify=None):
137138
requests.post = post
138139

139140
# The fake stdout will be written here
140-
out = []
141-
err_code = []
141+
out: List[str] = []
142+
err_code: List[int] = []
142143

143144
with patch("synapse._scripts.register_new_matrix_user.requests", requests):
144145
request_registration(

tests/storage/test_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def runWithConnection(func, *args, **kwargs):
6060
db = DatabasePool(Mock(), Mock(config=sqlite_config), fake_engine)
6161
db._db_pool = self.db_pool
6262

63-
self.datastore = SQLBaseStore(db, None, hs)
63+
self.datastore = SQLBaseStore(db, None, hs) # type: ignore[arg-type]
6464

6565
@defer.inlineCallbacks
6666
def test_insert_1col(self):

tests/storage/test_roommember.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class RoomMemberStoreTestCase(unittest.HomeserverTestCase):
3434
room.register_servlets,
3535
]
3636

37-
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: TestHomeServer) -> None:
37+
def prepare(self, reactor: MemoryReactor, clock: Clock, hs: TestHomeServer) -> None: # type: ignore[override]
3838

3939
# We can't test the RoomMemberStore on its own without the other event
4040
# storage logic

0 commit comments

Comments
 (0)