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

Add some type hints to tests files #12833

Merged
merged 3 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12833.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add some type hints to tests files.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 0 additions & 8 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,11 @@ exclude = (?x)
|tests/events/test_utils.py
|tests/federation/test_federation_catch_up.py
|tests/federation/test_federation_sender.py
|tests/federation/test_federation_server.py
|tests/federation/transport/test_knocking.py
|tests/federation/transport/test_server.py
|tests/handlers/test_typing.py
|tests/http/federation/test_matrix_federation_agent.py
|tests/http/federation/test_srv_resolver.py
|tests/http/test_fedclient.py
|tests/http/test_proxyagent.py
|tests/http/test_servlet.py
|tests/http/test_site.py
|tests/logging/__init__.py
|tests/logging/test_terse_json.py
|tests/module_api/test_api.py
Expand All @@ -59,12 +54,9 @@ exclude = (?x)
|tests/push/test_push_rule_evaluator.py
|tests/rest/client/test_transactions.py
|tests/rest/media/v1/test_media_storage.py
|tests/scripts/test_new_matrix_user.py
|tests/server.py
|tests/server_notices/test_resource_limits_server_notices.py
|tests/state/test_v2.py
|tests/storage/test_base.py
|tests/storage/test_roommember.py
|tests/test_metrics.py
|tests/test_server.py
|tests/test_state.py
Expand Down
14 changes: 8 additions & 6 deletions tests/http/test_servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,21 @@ def test_parse_json_value(self):
"""Basic tests for parse_json_value_from_request."""
# Test round-tripping.
obj = {"foo": 1}
result = parse_json_value_from_request(make_request(obj))
self.assertEqual(result, obj)
result1 = parse_json_value_from_request(make_request(obj))
self.assertEqual(result1, obj)

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

# Test empty.
with self.assertRaises(SynapseError):
parse_json_value_from_request(make_request(b""))

result = parse_json_value_from_request(make_request(b""), allow_empty_body=True)
self.assertIsNone(result)
result3 = parse_json_value_from_request(
make_request(b""), allow_empty_body=True
)
self.assertIsNone(result3)

# Invalid UTF-8.
with self.assertRaises(SynapseError):
Expand Down
2 changes: 1 addition & 1 deletion tests/http/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_large_request(self):
# as a control case, first send a regular request.

# 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)
transport = StringTransport()
protocol.makeConnection(transport)
Expand Down
13 changes: 7 additions & 6 deletions tests/scripts/test_new_matrix_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List
from unittest.mock import Mock, patch

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

# The fake stdout will be written here
out = []
err_code = []
out: List[str] = []
err_code: List[int] = []

with patch("synapse._scripts.register_new_matrix_user.requests", requests):
request_registration(
Expand Down Expand Up @@ -85,8 +86,8 @@ def get(url, verify=None):
requests.get = get

# The fake stdout will be written here
out = []
err_code = []
out: List[str] = []
err_code: List[int] = []

with patch("synapse._scripts.register_new_matrix_user.requests", requests):
request_registration(
Expand Down Expand Up @@ -137,8 +138,8 @@ def post(url, json=None, verify=None):
requests.post = post

# The fake stdout will be written here
out = []
err_code = []
out: List[str] = []
err_code: List[int] = []

with patch("synapse._scripts.register_new_matrix_user.requests", requests):
request_registration(
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def runWithConnection(func, *args, **kwargs):
db = DatabasePool(Mock(), Mock(config=sqlite_config), fake_engine)
db._db_pool = self.db_pool

self.datastore = SQLBaseStore(db, None, hs)
self.datastore = SQLBaseStore(db, None, hs) # type: ignore[arg-type]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error:
tests/storage/test_base.py:63: error: Argument 2 to "SQLBaseStore" has incompatible type "None"; expected "LoggingDatabaseConnection" [arg-type]


@defer.inlineCallbacks
def test_insert_1col(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/test_roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RoomMemberStoreTestCase(unittest.HomeserverTestCase):
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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error:
tests/storage/test_roommember.py:37: error: Argument 3 of "prepare" is incompatible with supertype "HomeserverTestCase"; supertype defines the argument type as "HomeServer" [override]


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