1
1
from mako.template import Template
4
from mako.compat import py3k, py26, py25
5
from mako.util import function_named
4
from mako.compat import py3k, py26, py33
5
from mako import compat
6
from mako.util import update_wrapper
7
8
from mako.cache import CacheImpl, register_plugin
8
9
from nose import SkipTest
11
12
template_base = os.path.join(os.path.dirname(__file__), 'templates')
12
13
module_base = os.path.join(template_base, 'modules')
62
63
shutil.rmtree(module_base, True)
64
def assert_raises(except_cls, callable_, *args, **kw):
66
from unittest import mock
70
@contextlib.contextmanager
71
def raises(except_cls, message=None):
66
callable_(*args, **kw)
75
except except_cls as e:
77
assert re.search(message, compat.text_type(e), re.UNICODE), \
78
"%r !~ %s" % (message, e)
79
print(compat.text_type(e).encode('utf-8'))
71
82
# assert outside the block so it works for AssertionError too !
72
83
assert success, "Callable did not raise an exception"
86
def assert_raises(except_cls, callable_, *args, **kw):
87
with raises(except_cls):
88
return callable_(*args, **kw)
74
90
def assert_raises_message(except_cls, msg, callable_, *args, **kwargs):
76
callable_(*args, **kwargs)
77
assert False, "Callable did not raise an exception"
80
assert re.search(msg, str(e)), "%r !~ %s" % (msg, e)
91
with raises(except_cls, msg):
92
return callable_(*args, **kwargs)
83
94
def skip_if(predicate, reason=None):
84
95
"""Skip a test if predicate is true."""
93
104
raise SkipTest(msg)
95
106
return fn(*args, **kw)
96
return function_named(maybe, fn_name)
107
return update_wrapper(maybe, fn)
110
def requires_python_3(fn):
111
return skip_if(lambda: not py3k, "Requires Python 3.xx")(fn)
99
113
def requires_python_2(fn):
100
114
return skip_if(lambda: py3k, "Requires Python 2.xx")(fn)
102
116
def requires_python_26_or_greater(fn):
103
117
return skip_if(lambda: not py26, "Requires Python 2.6 or greater")(fn)
105
def requires_python_25_or_greater(fn):
106
return skip_if(lambda: not py25, "Requires Python 2.5 or greater")(fn)
108
119
def requires_pygments_14(fn):
121
132
return fn(*arg, **kw)
123
134
exceptions._install_highlighting()
124
return function_named(go, fn.__name__)
135
return update_wrapper(go, fn)
126
137
class PlainCacheImpl(CacheImpl):
127
138
"""Simple memory cache impl so that tests which