aboutsummaryrefslogtreecommitdiff
path: root/tests/test_loader.py
diff options
context:
space:
mode:
authorpgjones <philip.graham.jones@googlemail.com>2016-05-21 16:17:21 +0100
committerpgjones <philip.graham.jones@googlemail.com>2016-05-21 16:21:22 +0100
commit1a61008d61cff5b6c95f7b7298e47f2b18685247 (patch)
tree90b5f602c6748c7ba87564a6d4d446fb56d1c5b0 /tests/test_loader.py
parent042dadda53120176100241422f93a42238779d40 (diff)
downloadjinja-1a61008d61cff5b6c95f7b7298e47f2b18685247.tar.gz
Change environment cache key construction
Changing from a tuple of the loader ID and template name to a weakref to the loader and the template name should avoid situations whereby the loader has changed, yet the cached templates are returned. This would occur if the id of the new loader matches the old. A weakref is preferred over a direct reference so that the loader can be garbaged collected.
Diffstat (limited to 'tests/test_loader.py')
-rw-r--r--tests/test_loader.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/tests/test_loader.py b/tests/test_loader.py
index 6b9d9bb4..b916b911 100644
--- a/tests/test_loader.py
+++ b/tests/test_loader.py
@@ -13,6 +13,7 @@ import sys
import tempfile
import shutil
import pytest
+import weakref
from jinja2 import Environment, loaders
from jinja2._compat import PYPY, PY2
@@ -92,9 +93,10 @@ class TestLoaders():
assert t2 is env.get_template('two')
assert t1 is env.get_template('one')
t3 = env.get_template('three')
- assert (id(loader), 'one') in env.cache
- assert (id(loader), 'two') not in env.cache
- assert (id(loader), 'three') in env.cache
+ loader_ref = weakref.ref(loader)
+ assert (loader_ref, 'one') in env.cache
+ assert (loader_ref, 'two') not in env.cache
+ assert (loader_ref, 'three') in env.cache
def test_cache_loader_change(self):
loader1 = loaders.DictLoader({'foo': 'one'})