Skip to content

Commit 2f22809

Browse files
committed
Add deepcopy coverage
1 parent a780388 commit 2f22809

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_lru_cache.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
from copy import deepcopy
4+
35
from sentry_sdk._lru_cache import LRUCache
46

57

@@ -58,3 +60,29 @@ def test_cache_get_all():
5860
assert cache.get_all() == [(1, 1), (2, 2), (3, 3)]
5961
cache.get(1)
6062
assert cache.get_all() == [(2, 2), (3, 3), (1, 1)]
63+
64+
65+
def test_cache_copy():
66+
cache = LRUCache(3)
67+
cache.set(0, 0)
68+
cache.set(1, 1)
69+
70+
copied = deepcopy(cache)
71+
cache.set(2, 2)
72+
cache.set(3, 3)
73+
assert copied.get_all() == [(0, 0), (1, 1)]
74+
assert cache.get_all() == [(1, 1), (2, 2), (3, 3)]
75+
76+
copied = deepcopy(cache)
77+
cache.get(1)
78+
assert copied.get_all() == [(1, 1), (2, 2), (3, 3)]
79+
assert cache.get_all() == [(2, 2), (3, 3), (1, 1)]
80+
81+
82+
def test_cache_pollution():
83+
cache1 = LRUCache(max_size=2)
84+
cache1.set(1, True)
85+
cache2 = deepcopy(cache1)
86+
cache2.set(1, False)
87+
assert cache1.get(1) is True
88+
assert cache2.get(1) is False

0 commit comments

Comments
 (0)