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
Prev Previous commit
Next Next commit
Add missing types to test_expiring_cache.
  • Loading branch information
clokep committed Dec 2, 2022
commit 24a7e302948d92bc8ea2c0a4e0b57f49cf19de8c
4 changes: 3 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ exclude = (?x)
|tests/server_notices/test_resource_limits_server_notices.py
|tests/test_state.py
|tests/test_terms_auth.py
|tests/util/test_expiring_cache.py
|tests/util/test_file_consumer.py
|tests/util/test_linearizer.py
|tests/util/test_logcontext.py
Expand Down Expand Up @@ -143,6 +142,9 @@ 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.utils]
disallow_untyped_defs = True

Expand Down
26 changes: 18 additions & 8 deletions tests/util/test_expiring_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List, cast

from synapse.util import Clock
from synapse.util.caches.expiringcache import ExpiringCache

from tests.utils import MockClock
Expand All @@ -21,17 +23,21 @@


class ExpiringCacheTestCase(unittest.HomeserverTestCase):
def test_get_set(self):
def test_get_set(self) -> None:
clock = MockClock()
cache = ExpiringCache("test", clock, max_len=1)
cache: ExpiringCache[str, str] = ExpiringCache(
"test", cast(Clock, clock), max_len=1
)

cache["key"] = "value"
self.assertEqual(cache.get("key"), "value")
self.assertEqual(cache["key"], "value")

def test_eviction(self):
def test_eviction(self) -> None:
clock = MockClock()
cache = ExpiringCache("test", clock, max_len=2)
cache: ExpiringCache[str, str] = ExpiringCache(
"test", cast(Clock, clock), max_len=2
)

cache["key"] = "value"
cache["key2"] = "value2"
Expand All @@ -43,9 +49,11 @@ def test_eviction(self):
self.assertEqual(cache.get("key2"), "value2")
self.assertEqual(cache.get("key3"), "value3")

def test_iterable_eviction(self):
def test_iterable_eviction(self) -> None:
clock = MockClock()
cache = ExpiringCache("test", clock, max_len=5, iterable=True)
cache: ExpiringCache[str, List[int]] = ExpiringCache(
"test", cast(Clock, clock), max_len=5, iterable=True
)

cache["key"] = [1]
cache["key2"] = [2, 3]
Expand All @@ -61,9 +69,11 @@ def test_iterable_eviction(self):
self.assertEqual(cache.get("key3"), [4, 5])
self.assertEqual(cache.get("key4"), [6, 7])

def test_time_eviction(self):
def test_time_eviction(self) -> None:
clock = MockClock()
cache = ExpiringCache("test", clock, expiry_ms=1000)
cache: ExpiringCache[str, int] = ExpiringCache(
"test", cast(Clock, clock), expiry_ms=1000
)

cache["key"] = 1
clock.advance_time(0.5)
Expand Down