mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-06-12 21:22:51 -04:00
Add missing types to tests.util. (#14597)
Removes files under tests.util from the ignored by list, then fully types all tests/util/*.py files.
This commit is contained in:
parent
fac8a38525
commit
acea4d7a2f
21 changed files with 361 additions and 276 deletions
|
@ -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
|
||||
|
@ -21,17 +23,21 @@ from .. import unittest
|
|||
|
||||
|
||||
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"
|
||||
|
@ -43,9 +49,11 @@ class ExpiringCacheTestCase(unittest.HomeserverTestCase):
|
|||
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]
|
||||
|
@ -61,9 +69,11 @@ class ExpiringCacheTestCase(unittest.HomeserverTestCase):
|
|||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue