| 1 |
import pytest |
| 2 |
|
| 3 |
from mako.ext.beaker_cache import has_beaker |
| 4 |
from mako.util import update_wrapper |
| 5 |
|
| 6 |
|
| 7 |
try: |
| 8 |
import babel.messages.extract as babel |
| 9 |
except ImportError: |
| 10 |
babel = None |
| 11 |
|
| 12 |
|
| 13 |
try: |
| 14 |
import lingua |
| 15 |
except ImportError: |
| 16 |
lingua = None |
| 17 |
|
| 18 |
|
| 19 |
try: |
| 20 |
import dogpile.cache # noqa |
| 21 |
except ImportError: |
| 22 |
has_dogpile_cache = False |
| 23 |
else: |
| 24 |
has_dogpile_cache = True |
| 25 |
|
| 26 |
|
| 27 |
requires_beaker = pytest.mark.skipif( |
| 28 |
not has_beaker, reason="Beaker is required for these tests." |
| 29 |
) |
| 30 |
|
| 31 |
|
| 32 |
requires_babel = pytest.mark.skipif( |
| 33 |
babel is None, reason="babel not installed: skipping babelplugin test" |
| 34 |
) |
| 35 |
|
| 36 |
|
| 37 |
requires_lingua = pytest.mark.skipif( |
| 38 |
lingua is None, reason="lingua not installed: skipping linguaplugin test" |
| 39 |
) |
| 40 |
|
| 41 |
|
| 42 |
requires_dogpile_cache = pytest.mark.skipif( |
| 43 |
not has_dogpile_cache, |
| 44 |
reason="dogpile.cache is required to run these tests", |
| 45 |
) |
| 46 |
|
| 47 |
|
| 48 |
def _pygments_version(): |
| 49 |
try: |
| 50 |
import pygments |
| 51 |
|
| 52 |
version = pygments.__version__ |
| 53 |
except: |
| 54 |
version = "0" |
| 55 |
return version |
| 56 |
|
| 57 |
|
| 58 |
requires_pygments_14 = pytest.mark.skipif( |
| 59 |
_pygments_version() < "1.4", reason="Requires pygments 1.4 or greater" |
| 60 |
) |
| 61 |
|
| 62 |
|
| 63 |
# def requires_pygments_14(fn): |
| 64 |
|
| 65 |
# return skip_if( |
| 66 |
# lambda: version < "1.4", "Requires pygments 1.4 or greater" |
| 67 |
# )(fn) |
| 68 |
|
| 69 |
|
| 70 |
def requires_no_pygments_exceptions(fn): |
| 71 |
def go(*arg, **kw): |
| 72 |
from mako import exceptions |
| 73 |
|
| 74 |
exceptions._install_fallback() |
| 75 |
try: |
| 76 |
return fn(*arg, **kw) |
| 77 |
finally: |
| 78 |
exceptions._install_highlighting() |
| 79 |
|
| 80 |
return update_wrapper(go, fn) |