Skip to content
Myr

Merge pull request #1090 from pallets/lrucache-copy

Before adoption: this commit came in with the history the project adopted, so no landing records it.

LRUCache.copy's queue methods point to the correct queue

authored by David Lord · committed by GitHub · parents 8182509, 7ca0308 · Browse files · 3 files+17 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+17 added−3 removed

  • tests:+14 added−2 removed
  • other:+3 added−1 removed

3 files+17 added−3 removed

modified:jinja2/utils.py+1 added-1 removed
338 unmodified lines
339 def copy(self):340 """Return a shallow copy of the instance."""341 rv = self.__class__(self.capacity)342 rv._mapping.update(self._mapping)343 rv._queue = deque(self._queue)343 rv._queue.extend(self._queue)344 return rv345346 def get(self, key, default=None):347 """Return an item from the cache dict or `default`"""
322 unmodified lines
modified:tests/test_utils.py+14 added-2 removed
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""1112from collections import deque13import gc13from copy import copy as shallow_copy14import pickle15import random1617import pytest1819from jinja2._compat import string_types, range_type20from jinja2.utils import LRUCache, escape, object_type_repr, urlize, \20from jinja2.utils import LRUCache, object_type_repr, urlize, \21 select_autoescape, generate_lorem_ipsum, missing, consume22from markupsafe import Markup232425@pytest.mark.utils26@pytest.mark.lrucache27class TestLRUCache(object):28
39 unmodified lines
68 assert copy.capacity == cache.capacity69 assert copy._mapping == cache._mapping70 assert copy._queue == cache._queue7172 @pytest.mark.parametrize("copy_func", [LRUCache.copy, shallow_copy])73 def test_copy(self, copy_func):74 cache = LRUCache(2)75 cache['a'] = 176 cache['b'] = 277 copy = copy_func(cache)78 assert copy._queue == cache._queue79 copy['c'] = 380 assert copy._queue != cache._queue81 assert 'a' not in copy and 'b' in copy and 'c' in copy8283 def test_clear(self):84 d = LRUCache(3)85 d["a"] = 186 d["b"] = 2
124 unmodified lines
modified:CHANGES.rst+2 added
53 unmodified lines
54 :issue:`870`55- :class:`~nativetypes.NativeTemplate` correctly handles quotes56 between expressions. ``"'{{ a }}', '{{ b }}'"`` renders as the tuple57 ``('1', '2')`` rather than the string ``'1, 2'``. :issue:`1020`58- After calling ``LRUCache.copy()``, the copy's queue methods point to59 the correct queue. :issue:`843`606162Version 2.10.363--------------
629 unmodified lines