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

Add missing types to tests.util. #14597

Merged
merged 16 commits into from
Dec 2, 2022
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
29 changes: 1 addition & 28 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,7 @@ disallow_untyped_defs = True
[mypy-tests.util.caches.test_descriptors]
disallow_untyped_defs = False

[mypy-tests.util.test_async_helpers]
disallow_untyped_defs = True

[mypy-tests.util.test_batching_queue]
disallow_untyped_defs = True

[mypy-tests.util.test_dict_cache]
disallow_untyped_defs = True

[mypy-tests.util.test_expiring_cache]
disallow_untyped_defs = True

[mypy-tests.util.test_file_consumer]
disallow_untyped_defs = True

[mypy-tests.util.test_linearizer]
disallow_untyped_defs = True

[mypy-tests.util.test_logcontext]
disallow_untyped_defs = True

[mypy-tests.util.test_lrucache]
disallow_untyped_defs = True

[mypy-tests.util.test_rwlock]
disallow_untyped_defs = True

[mypy-tests.util.test_wheel_timer]
[mypy-tests.util.*]
disallow_untyped_defs = True

[mypy-tests.utils]
Expand Down
29 changes: 22 additions & 7 deletions tests/util/test_check_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Copyright 2022 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from contextlib import contextmanager
from typing import Generator, Optional
from os import PathLike
from typing import Generator, Optional, Union
from unittest.mock import patch

from synapse.util.check_dependencies import (
Expand All @@ -12,25 +27,25 @@


class DummyDistribution(metadata.Distribution):
def __init__(self, version: object):
def __init__(self, version: str):
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
self._version = version

@property
def version(self):
def version(self) -> str:
return self._version

def locate_file(self, path):
def locate_file(self, path: Union[str, PathLike[str]]) -> PathLike[str]:
raise NotImplementedError()

def read_text(self, filename):
def read_text(self, filename: str) -> None:
raise NotImplementedError()


old = DummyDistribution("0.1.2")
old_release_candidate = DummyDistribution("0.1.2rc3")
new = DummyDistribution("1.2.3")
new_release_candidate = DummyDistribution("1.2.3rc4")
distribution_with_no_version = DummyDistribution(None)
distribution_with_no_version = DummyDistribution(None) # type: ignore[arg-type]

# could probably use stdlib TestCase --- no need for twisted here

Expand All @@ -45,7 +60,7 @@ def mock_installed_package(
If `distribution = None`, we pretend that the package is not installed.
"""

def mock_distribution(name: str):
def mock_distribution(name: str) -> DummyDistribution:
if distribution is None:
raise metadata.PackageNotFoundError
else:
Expand Down