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

Add missing type hints in tests #14879

Merged
merged 5 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ exclude = (?x)
|tests/http/federation/test_matrix_federation_agent.py
|tests/http/federation/test_srv_resolver.py
|tests/http/test_proxyagent.py
|tests/logging/__init__.py
|tests/logging/test_terse_json.py
|tests/module_api/test_api.py
|tests/rest/client/test_transactions.py
|tests/rest/media/v1/test_media_storage.py
Expand Down
4 changes: 3 additions & 1 deletion tests/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
# limitations under the License.
import logging

from tests.unittest import TestCase

class LoggerCleanupMixin:

class LoggerCleanupMixin(TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the complaint here, OOI?

Copy link
Member Author

Choose a reason for hiding this comment

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

self.addCleanup needs to exist.

def get_logger(self, handler):
"""
Attach a handler to a logger and add clean-ups to remove revert this.
Expand Down
13 changes: 9 additions & 4 deletions tests/logging/test_terse_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@
import json
import logging
from io import BytesIO, StringIO
from typing import cast
from unittest.mock import Mock, patch

from twisted.web.http import HTTPChannel
from twisted.web.server import Request

from synapse.http.site import SynapseRequest
from synapse.logging._terse_json import JsonFormatter, TerseJsonFormatter
from synapse.logging.context import LoggingContext, LoggingContextFilter

from tests.logging import LoggerCleanupMixin
from tests.server import FakeChannel
from tests.server import FakeChannel, get_clock
from tests.unittest import TestCase


class TerseJsonTestCase(LoggerCleanupMixin, TestCase):
def setUp(self):
self.output = StringIO()
self.reactor, _ = get_clock()

def get_log_line(self):
# One log message, with a single trailing newline.
Expand Down Expand Up @@ -154,11 +157,13 @@ def test_with_request_context(self):
site.server_version_string = "Server v1"
site.reactor = Mock()
site.experimental_cors_msc3886 = False
request = SynapseRequest(FakeChannel(site, None), site)
request = SynapseRequest(
cast(HTTPChannel, FakeChannel(site, self.reactor)), site
)
# Call requestReceived to finish instantiating the object.
request.content = BytesIO()
# Partially skip some of the internal processing of SynapseRequest.
request._started_processing = Mock()
# Partially skip some internal processing of SynapseRequest.
request._started_processing = Mock() # type: ignore[assignment]
request.request_metrics = Mock(spec=["name"])
with patch.object(Request, "render"):
request.requestReceived(b"POST", b"/_matrix/client/versions", b"1.1")
Expand Down