return False
-def pytest_configure(config):
- """Register custom marks for test categories."""
- custom_markers = [
- "api",
- "byte_code_cache",
- "core_tags",
- "debug",
- "escapeUrlizeTarget",
- "ext",
- "extended",
- "filesystemloader",
- "filter",
- "for_loop",
- "helpers",
- "if_condition",
- "imports",
- "includes",
- "inheritance",
- "lexer",
- "lexnparse",
- "loaders",
- "loremIpsum",
- "lowlevel",
- "lrucache",
- "lstripblocks",
- "macros",
- "meta",
- "moduleloader",
- "parser",
- "regression",
- "sandbox",
- "set",
- "streaming",
- "syntax",
- "test_tests",
- "tokenstream",
- "undefined",
- "utils",
- "with_",
- ]
- for mark in custom_markers:
- config.addinivalue_line("markers", mark + ": test category")
-
-
@pytest.fixture
def env():
"""returns a new environment."""
from jinja2.utils import evalcontextfunction
-@pytest.mark.api
-@pytest.mark.extended
class TestExtendedAPI(object):
def test_item_and_attribute(self, env):
from jinja2.sandbox import SandboxedEnvironment
t.render(total=MAX_RANGE + 1)
-@pytest.mark.api
-@pytest.mark.meta
class TestMeta(object):
def test_find_undeclared_variables(self, env):
ast = env.parse("{% set foo = 42 %}{{ bar + foo }}")
assert list(i) == ["foo.html", "bar.html", None]
-@pytest.mark.api
-@pytest.mark.streaming
class TestStreaming(object):
def test_basic_streaming(self, env):
t = env.from_string(
shutil.rmtree(tmp)
-@pytest.mark.api
-@pytest.mark.undefined
class TestUndefined(object):
def test_stopiteration_is_undefined(self):
def test():
Undefined(obj=42, name="upper")()
-@pytest.mark.api
-@pytest.mark.lowlevel
class TestLowLevel(object):
def test_custom_code_generator(self):
class CustomCodeGenerator(CodeGenerator):
return env
-@pytest.mark.imports
class TestAsyncImports(object):
def test_context_imports(self, test_env_async):
t = test_env_async.from_string('{% import "module" as m %}{{ m.test() }}')
assert not hasattr(m, "notthere")
-@pytest.mark.imports
-@pytest.mark.includes
class TestAsyncIncludes(object):
def test_context_include(self, test_env_async):
t = test_env_async.from_string('{% include "header" %}')
assert t.render().strip() == "(FOO)"
-@pytest.mark.core_tags
-@pytest.mark.for_loop
class TestAsyncForLoop(object):
def test_simple(self, test_env_async):
tmpl = test_env_async.from_string("{% for item in seq %}{{ item }}{% endfor %}")
return Environment(loader=package_loader, bytecode_cache=bytecode_cache)
-@pytest.mark.byte_code_cache
class TestByteCodeCache(object):
def test_simple(self, env):
tmpl = env.get_template("test.html")
return Environment(trim_blocks=True)
-@pytest.mark.core_tags
-@pytest.mark.for_loop
class TestForLoop(object):
def test_simple(self, env):
tmpl = env.from_string("{% for item in seq %}{{ item }}{% endfor %}")
assert tmpl.render(x=0, seq=[1, 2, 3]) == "919293"
-@pytest.mark.core_tags
-@pytest.mark.if_condition
class TestIfCondition(object):
def test_simple(self, env):
tmpl = env.from_string("""{% if true %}...{% endif %}""")
assert tmpl.render() == "1"
-@pytest.mark.core_tags
-@pytest.mark.macros
class TestMacros(object):
def test_simple(self, env_trim):
tmpl = env_trim.from_string(
assert tmpl.module.m(1, x=7) == "1|7|7"
-@pytest.mark.core_tags
-@pytest.mark.set
class TestSet(object):
def test_normal(self, env_trim):
tmpl = env_trim.from_string("{% set foo = 1 %}{{ foo }}")
assert tmpl.module.foo == u"11"
-@pytest.mark.core_tags
-@pytest.mark.with_
class TestWith(object):
def test_with(self, env):
tmpl = env.from_string(
return Environment(loader=filesystem_loader)
-@pytest.mark.debug
class TestDebug(object):
def assert_traceback_matches(self, callback, expected_tb):
with pytest.raises(Exception) as exc_info:
yield Token(lineno, "data", token.value[pos:])
-@pytest.mark.ext
class TestExtensions(object):
def test_extend_late(self):
env = Environment()
assert "'{}'".format(value) in out
-@pytest.mark.ext
class TestInternationalization(object):
def test_trans(self):
tmpl = i18n_env.get_template("child.html")
]
-@pytest.mark.ext
class TestScope(object):
def test_basic_scope_behavior(self):
# This is what the old with statement compiled down to
assert tmpl.render(b=3, e=4) == "1|2|2|4|5"
-@pytest.mark.ext
class TestNewstyleInternationalization(object):
def test_trans(self):
tmpl = newstyle_i18n_env.get_template("child.html")
assert t.render() == "%(foo)s"
-@pytest.mark.ext
class TestAutoEscape(object):
def test_scoped_setting(self):
env = Environment(extensions=["jinja2.ext.autoescape"], autoescape=True)
return u"(%s,%s)" % (text_type(self.value1), text_type(self.value2))
-@pytest.mark.filter
class TestFilter(object):
def test_filter_calling(self, env):
rv = env.call_filter("sum", [1, 2, 3])
return env
-@pytest.mark.imports
class TestImports(object):
def test_context_imports(self, test_env):
t = test_env.from_string('{% import "module" as m %}{{ m.test() }}')
assert not hasattr(m, "notthere")
-@pytest.mark.imports
-@pytest.mark.includes
class TestIncludes(object):
def test_context_include(self, test_env):
t = test_env.from_string('{% include "header" %}')
)
-@pytest.mark.inheritance
class TestInheritance(object):
def test_layout(self, env):
tmpl = env.get_template("layout")
assert rv == ["43", "44", "45"]
-@pytest.mark.inheritance
class TestBugFix(object):
def test_fixed_macro_scoping_bug(self, env):
assert (
jinja_string_repr = repr
-@pytest.mark.lexnparse
-@pytest.mark.tokenstream
class TestTokenStream(object):
test_tokens = [
Token(1, TOKEN_BLOCK_BEGIN, ""),
]
-@pytest.mark.lexnparse
-@pytest.mark.lexer
class TestLexer(object):
def test_raw1(self, env):
tmpl = env.from_string(
pytest.raises(TemplateSyntaxError, env.from_string, t)
-@pytest.mark.lexnparse
-@pytest.mark.parser
class TestParser(object):
def test_php_syntax(self, env):
env = Environment("<?", "?>", "<?=", "?>", "<!--", "-->")
assert_error("{% unknown_tag %}", "Encountered unknown tag 'unknown_tag'.")
-@pytest.mark.lexnparse
-@pytest.mark.syntax
class TestSyntax(object):
def test_call(self, env):
env = Environment()
assert tmpl.render(foo={"bar": 42}) == "42"
-@pytest.mark.lexnparse
-@pytest.mark.lstripblocks
class TestLstripBlocks(object):
def test_lstrip(self, env):
env = Environment(lstrip_blocks=True, trim_blocks=False)
from jinja2.loaders import split_template_path
-@pytest.mark.loaders
class TestLoaders(object):
def test_dict_loader(self, dict_loader):
env = Environment(loader=dict_loader)
pytest.raises(TemplateNotFound, split_template_path, "../foo")
-@pytest.mark.loaders
-@pytest.mark.filesystemloader
class TestFileSystemLoader(object):
searchpath = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "res", "templates"
assert t.render() == expect
-@pytest.mark.loaders
-@pytest.mark.moduleloader
class TestModuleLoader(object):
archive = None
from jinja2._compat import text_type
-@pytest.mark.regression
class TestCorner(object):
def test_assigned_scoping(self, env):
t = env.from_string(
assert t.render(wrapper=23) == "[1][2][3][4]23"
-@pytest.mark.regression
class TestBug(object):
def test_keyword_folding(self, env):
env = Environment()
return "PublicStuff"
-@pytest.mark.sandbox
class TestSandbox(object):
def test_unsafe(self, env):
env = SandboxedEnvironment()
t.render(ctx)
-@pytest.mark.sandbox
class TestStringFormat(object):
def test_basic_format_safety(self):
env = SandboxedEnvironment()
assert t.render() == "a42b<foo>"
-@pytest.mark.sandbox
@pytest.mark.skipif(
not hasattr(str, "format_map"), reason="requires str.format_map method"
)
pass
-@pytest.mark.test_tests
class TestTestsCase(object):
def test_defined(self, env):
tmpl = env.from_string("{{ missing is defined }}|{{ true is defined }}")
from jinja2.utils import urlize
-@pytest.mark.utils
-@pytest.mark.lrucache
class TestLRUCache(object):
def test_simple(self):
d = LRUCache(3)
assert len(d) == 2
-@pytest.mark.utils
-@pytest.mark.helpers
class TestHelpers(object):
def test_object_type_repr(self):
class X(object):
assert not func("FOO.TXT")
-@pytest.mark.utils
-@pytest.mark.escapeUrlizeTarget
class TestEscapeUrlizeTarget(object):
def test_escape_urlize_target(self):
url = "http://example.org"
)
-@pytest.mark.utils
-@pytest.mark.loremIpsum
class TestLoremIpsum(object):
def test_lorem_ipsum_markup(self):
"""Test that output of lorem_ipsum is Markup by default."""