forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtest_in_memory_cache.py
52 lines (36 loc) · 1.29 KB
/
test_in_memory_cache.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright (c) 2023 - 2024, Owners of https://github.com/autogenhub
#
# SPDX-License-Identifier: Apache-2.0
#
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
# SPDX-License-Identifier: MIT
from autogen.cache.in_memory_cache import InMemoryCache
def test_prefixed_key():
cache = InMemoryCache(seed="test")
assert cache._prefixed_key("key") == "test_key"
def test_get_with_default_value():
cache = InMemoryCache()
assert cache.get("key", "default_value") == "default_value"
def test_get_without_default_value():
cache = InMemoryCache()
assert cache.get("key") is None
def test_get_with_set_value():
cache = InMemoryCache()
cache.set("key", "value")
assert cache.get("key") == "value"
def test_get_with_set_value_and_seed():
cache = InMemoryCache(seed="test")
cache.set("key", "value")
assert cache.get("key") == "value"
def test_set():
cache = InMemoryCache()
cache.set("key", "value")
assert cache._cache["key"] == "value"
def test_set_with_seed():
cache = InMemoryCache(seed="test")
cache.set("key", "value")
assert cache._cache["test_key"] == "value"
def test_context_manager():
with InMemoryCache() as cache:
cache.set("key", "value")
assert cache.get("key") == "value"