summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2019-10-24 08:00:39 -0700
committerGitHub <noreply@github.com>2019-10-24 08:00:39 -0700
commit9a7dd7b28b50fd8adc019ab2702b50ae5c6ed782 (patch)
tree68d72a47347bddbe5a24f12adf6cef9a8c800462
parent81825095d24f4dbccb40f787fff70db54989b91c (diff)
parent7ca03082c5ba4621113a16178a12cfdad20760bb (diff)
downloadjinja2-9a7dd7b28b50fd8adc019ab2702b50ae5c6ed782.tar.gz
Merge pull request #1090 from pallets/lrucache-copy
LRUCache.copy's queue methods point to the correct queue
-rw-r--r--CHANGES.rst2
-rw-r--r--jinja2/utils.py2
-rw-r--r--tests/test_utils.py16
3 files changed, 17 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index d53a4db..f64047b 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -55,6 +55,8 @@ Unreleased
- :class:`~nativetypes.NativeTemplate` correctly handles quotes
between expressions. ``"'{{ a }}', '{{ b }}'"`` renders as the tuple
``('1', '2')`` rather than the string ``'1, 2'``. :issue:`1020`
+- After calling ``LRUCache.copy()``, the copy's queue methods point to
+ the correct queue. :issue:`843`
Version 2.10.3
diff --git a/jinja2/utils.py b/jinja2/utils.py
index 5518793..d2759e2 100644
--- a/jinja2/utils.py
+++ b/jinja2/utils.py
@@ -340,7 +340,7 @@ class LRUCache(object):
"""Return a shallow copy of the instance."""
rv = self.__class__(self.capacity)
rv._mapping.update(self._mapping)
- rv._queue = deque(self._queue)
+ rv._queue.extend(self._queue)
return rv
def get(self, key, default=None):
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 64c2b3a..7ff39f0 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -10,17 +10,18 @@
"""
from collections import deque
-import gc
+from copy import copy as shallow_copy
import pickle
import random
import pytest
from jinja2._compat import string_types, range_type
-from jinja2.utils import LRUCache, escape, object_type_repr, urlize, \
+from jinja2.utils import LRUCache, object_type_repr, urlize, \
select_autoescape, generate_lorem_ipsum, missing, consume
from markupsafe import Markup
+
@pytest.mark.utils
@pytest.mark.lrucache
class TestLRUCache(object):
@@ -68,6 +69,17 @@ class TestLRUCache(object):
assert copy._mapping == cache._mapping
assert copy._queue == cache._queue
+ @pytest.mark.parametrize("copy_func", [LRUCache.copy, shallow_copy])
+ def test_copy(self, copy_func):
+ cache = LRUCache(2)
+ cache['a'] = 1
+ cache['b'] = 2
+ copy = copy_func(cache)
+ assert copy._queue == cache._queue
+ copy['c'] = 3
+ assert copy._queue != cache._queue
+ assert 'a' not in copy and 'b' in copy and 'c' in copy
+
def test_clear(self):
d = LRUCache(3)
d["a"] = 1