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

Commit 342ebcb

Browse files
committed
Add some type hints to tests files
1 parent 39dee30 commit 342ebcb

8 files changed

Lines changed: 19 additions & 26 deletions

File tree

mypy.ini

Lines changed: 0 additions & 8 deletions
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/crypto/test_event_signing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def setUp(self):
3939
# NB: `signedjson` expects `nacl.signing.SigningKey` instances which have been
4040
# monkeypatched to include new `alg` and `version` attributes. This is captured
4141
# by the `signedjson.types.SigningKey` protocol.
42-
self.signing_key: signedjson.types.SigningKey = nacl.signing.SigningKey( # type: ignore[assignment]
42+
self.signing_key: signedjson.types.SigningKey = nacl.signing.SigningKey(
4343
SIGNING_KEY_SEED
4444
)
4545
self.signing_key.alg = KEY_ALG

tests/http/test_servlet.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ 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(make_request(b""), allow_empty_body=True)
64+
self.assertIsNone(result3)
6565

6666
# Invalid UTF-8.
6767
with self.assertRaises(SynapseError):

tests/http/test_site.py

Lines changed: 1 addition & 1 deletion
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/logging/test_opentracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
try:
3535
import jaeger_client
3636
except ImportError:
37-
jaeger_client = None # type: ignore
37+
jaeger_client = None
3838

3939
from tests.unittest import TestCase
4040

@@ -43,7 +43,7 @@ class LogContextScopeManagerTestCase(TestCase):
4343
if LogContextScopeManager is None:
4444
skip = "Requires opentracing" # type: ignore[unreachable]
4545
if jaeger_client is None:
46-
skip = "Requires jaeger_client" # type: ignore[unreachable]
46+
skip = "Requires jaeger_client"
4747

4848
def setUp(self) -> None:
4949
# since this is a unit test, we don't really want to mess around with the

tests/scripts/test_new_matrix_user.py

Lines changed: 7 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)