summaryrefslogtreecommitdiff
path: root/test/test_cache.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_cache.py')
-rw-r--r--test/test_cache.py51
1 files changed, 20 insertions, 31 deletions
diff --git a/test/test_cache.py b/test/test_cache.py
index 60785f2..dd415d4 100644
--- a/test/test_cache.py
+++ b/test/test_cache.py
@@ -1,19 +1,18 @@
import time
-import unittest
from mako import lookup
from mako.cache import CacheImpl
from mako.cache import register_plugin
-from mako.ext import beaker_cache
from mako.lookup import TemplateLookup
from mako.template import Template
-from .util.assertions import eq_
-from .util.fixtures import module_base
-from .util.fixtures import TemplateTest
-from .util.helpers import result_lines
+from mako.testing.assertions import eq_
+from mako.testing.config import config
+from mako.testing.exclusions import requires_beaker
+from mako.testing.exclusions import requires_dogpile_cache
+from mako.testing.helpers import result_lines
-if beaker_cache.has_beaker:
- import beaker
+
+module_base = str(config.module_base)
class SimpleBackend:
@@ -32,9 +31,9 @@ class SimpleBackend:
def get_or_create(self, key, creation_function, **kw):
if key in self.cache:
return self.cache[key]
- else:
- self.cache[key] = value = creation_function()
- return value
+
+ self.cache[key] = value = creation_function()
+ return value
class MockCacheImpl(CacheImpl):
@@ -80,7 +79,7 @@ class MockCacheImpl(CacheImpl):
register_plugin("mock", __name__, "MockCacheImpl")
-class CacheTest(TemplateTest):
+class CacheTest:
real_backend = "simple"
@@ -600,7 +599,7 @@ class CacheTest(TemplateTest):
assert m.kwargs["context"].get("x") == "bar"
-class RealBackendTest:
+class RealBackendMixin:
def test_cache_uses_current_context(self):
t = Template(
"""
@@ -643,19 +642,17 @@ class RealBackendTest:
eq_(r3, ["short term 6", "long term 5", "none 7"])
-class BeakerCacheTest(RealBackendTest, CacheTest):
+@requires_beaker
+class BeakerCacheTest(RealBackendMixin, CacheTest):
real_backend = "beaker"
- def setUp(self):
- if not beaker_cache.has_beaker:
- raise unittest.SkipTest("Beaker is required for these tests.")
-
def _install_mock_cache(self, template, implname=None):
template.cache_args["manager"] = self._regions()
- impl = super()._install_mock_cache(template, implname)
- return impl
+ return super()._install_mock_cache(template, implname)
def _regions(self):
+ import beaker
+
return beaker.cache.CacheManager(
cache_regions={
"short": {"expire": 1, "type": "memory"},
@@ -664,22 +661,14 @@ class BeakerCacheTest(RealBackendTest, CacheTest):
)
-class DogpileCacheTest(RealBackendTest, CacheTest):
+@requires_dogpile_cache
+class DogpileCacheTest(RealBackendMixin, CacheTest):
real_backend = "dogpile.cache"
- def setUp(self):
- try:
- import dogpile.cache # noqa
- except ImportError:
- raise unittest.SkipTest(
- "dogpile.cache is required to run these tests"
- )
-
def _install_mock_cache(self, template, implname=None):
template.cache_args["regions"] = self._regions()
template.cache_args.setdefault("region", "short")
- impl = super()._install_mock_cache(template, implname)
- return impl
+ return super()._install_mock_cache(template, implname)
def _regions(self):
from dogpile.cache import make_region