Skip to content
Myr

Merge branch '2.11.x'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parents 1164cc3, dd5a050 · Browse files · 16 files+0 added−111 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

16 files+0 added−111 removed

  • tests:+0 added−111 removed

16 files+0 added−111 removed

modified:tests/conftest.py-44 removed
11 unmodified lines
12 return True13 return False141516def pytest_configure(config):17 """Register custom marks for test categories."""18 custom_markers = [19 "api",20 "byte_code_cache",21 "core_tags",22 "debug",23 "escapeUrlizeTarget",24 "ext",25 "extended",26 "filesystemloader",27 "filter",28 "for_loop",29 "helpers",30 "if_condition",31 "imports",32 "includes",33 "inheritance",34 "lexer",35 "lexnparse",36 "loaders",37 "loremIpsum",38 "lowlevel",39 "lrucache",40 "lstripblocks",41 "macros",42 "meta",43 "moduleloader",44 "parser",45 "regression",46 "sandbox",47 "set",48 "streaming",49 "syntax",50 "test_tests",51 "tokenstream",52 "undefined",53 "utils",54 "with_",55 ]56 for mark in custom_markers:57 config.addinivalue_line("markers", mark + ": test category")585916@pytest.fixture17def env():18 """returns a new environment."""19 return Environment()
37 unmodified lines
modified:tests/test_api.py-10 removed
22 unmodified lines
23from jinja2.utils import environmentfunction24from jinja2.utils import evalcontextfunction252627@pytest.mark.api28@pytest.mark.extended27class TestExtendedAPI:28 def test_item_and_attribute(self, env):29 from jinja2.sandbox import SandboxedEnvironment30
127 unmodified lines
158 with pytest.raises(OverflowError):159 t.render(total=MAX_RANGE + 1)160161164@pytest.mark.api165@pytest.mark.meta162class TestMeta:163 def test_find_undeclared_variables(self, env):164 ast = env.parse("{% set foo = 42 %}{{ bar + foo }}")165 x = meta.find_undeclared_variables(ast)
45 unmodified lines
211 i = meta.find_referenced_templates(ast)212 assert list(i) == ["foo.html", "bar.html", None]213214219@pytest.mark.api220@pytest.mark.streaming215class TestStreaming:216 def test_basic_streaming(self, env):217 t = env.from_string(218 "<ul>{% for item in seq %}<li>{{ loop.index }} - {{ item }}</li>"
33 unmodified lines
252 finally:253 shutil.rmtree(tmp)254255262@pytest.mark.api263@pytest.mark.undefined256class TestUndefined:257 def test_stopiteration_is_undefined(self):258 def test():259 raise StopIteration()
127 unmodified lines
387 ):388 Undefined(obj=42, name="upper")()389390399@pytest.mark.api400@pytest.mark.lowlevel391class TestLowLevel:392 def test_custom_code_generator(self):393 class CustomCodeGenerator(CodeGenerator):394 def visit_Const(self, node, frame=None):
24 unmodified lines
modified:tests/test_async.py-5 removed
128 unmodified lines
129 env.globals["bar"] = 23130 return env131132133@pytest.mark.imports133class TestAsyncImports:134 def test_context_imports(self, test_env_async):135 t = test_env_async.from_string('{% import "module" as m %}{{ m.test() }}')136 assert t.render(foo=42) == "[|23]"
41 unmodified lines
178 assert m.variable == 42179 assert not hasattr(m, "notthere")180181183@pytest.mark.imports184@pytest.mark.includes182class TestAsyncIncludes:183 def test_context_include(self, test_env_async):184 t = test_env_async.from_string('{% include "header" %}')185 assert t.render(foo=42) == "[42|23]"
89 unmodified lines
275 )276 assert t.render().strip() == "(FOO)"277278282@pytest.mark.core_tags283@pytest.mark.for_loop279class TestAsyncForLoop:280 def test_simple(self, test_env_async):281 tmpl = test_env_async.from_string("{% for item in seq %}{{ item }}{% endfor %}")282 assert tmpl.render(seq=list(range(10))) == "0123456789"
297 unmodified lines
modified:tests/test_bytecode_cache.py-1 removed
11 unmodified lines
12 bytecode_cache = FileSystemBytecodeCache(str(tmp_path))13 return Environment(loader=package_loader, bytecode_cache=bytecode_cache)141516@pytest.mark.byte_code_cache16class TestByteCodeCache:17 def test_simple(self, env):18 tmpl = env.get_template("test.html")19 assert tmpl.render().strip() == "BAR"
58 unmodified lines
modified:tests/test_core_tags.py-10 removed
10 unmodified lines
11def env_trim():12 return Environment(trim_blocks=True)131415@pytest.mark.core_tags16@pytest.mark.for_loop15class TestForLoop:16 def test_simple(self, env):17 tmpl = env.from_string("{% for item in seq %}{{ item }}{% endfor %}")18 assert tmpl.render(seq=list(range(10))) == "0123456789"
278 unmodified lines
297 )298 assert tmpl.render(x=0, seq=[1, 2, 3]) == "919293"299300303@pytest.mark.core_tags304@pytest.mark.if_condition301class TestIfCondition:302 def test_simple(self, env):303 tmpl = env.from_string("""{% if true %}...{% endif %}""")304 assert tmpl.render() == "..."
32 unmodified lines
337 tmpl = env.from_string("{% if true %}{% set foo = 1 %}{% endif %}{{ foo }}")338 assert tmpl.render() == "1"339340345@pytest.mark.core_tags346@pytest.mark.macros341class TestMacros:342 def test_simple(self, env_trim):343 tmpl = env_trim.from_string(344 """\
116 unmodified lines
461 assert tmpl.module.m(1, 2, 3) == "1|2|3"462 assert tmpl.module.m(1, x=7) == "1|7|7"463464471@pytest.mark.core_tags472@pytest.mark.set465class TestSet:466 def test_normal(self, env_trim):467 tmpl = env_trim.from_string("{% set foo = 1 %}{{ foo }}")468 assert tmpl.render() == "1"
99 unmodified lines
568 assert tmpl.render() == "11"569 assert tmpl.module.foo == "11"570571580@pytest.mark.core_tags581@pytest.mark.with_572class TestWith:573 def test_with(self, env):574 tmpl = env.from_string(575 """\
20 unmodified lines
modified:tests/test_debug.py-1 removed
14 unmodified lines
15 """returns a new environment."""16 return Environment(loader=filesystem_loader)171819@pytest.mark.debug19class TestDebug:20 def assert_traceback_matches(self, callback, expected_tb):21 with pytest.raises(Exception) as exc_info:22 callback()
92 unmodified lines
modified:tests/test_ext.py-5 removed
158 unmodified lines
159 if pos < end:160 yield Token(lineno, "data", token.value[pos:])161162163@pytest.mark.ext163class TestExtensions:164 def test_extend_late(self):165 env = Environment()166 env.add_extension("jinja2.ext.autoescape")
91 unmodified lines
258 for value in ("context", "cycler", "filters", "abs", "tests", "!="):259 assert f"'{value}'" in out260261263@pytest.mark.ext262class TestInternationalization:263 def test_trans(self):264 tmpl = i18n_env.get_template("child.html")265 assert tmpl.render(LANGUAGE="de") == "<title>fehlend</title>pass auf"
134 unmodified lines
400 (6, "ngettext", ("%(users)s user", "%(users)s users", None), ["third"]),401 ]402403406@pytest.mark.ext404class TestScope:405 def test_basic_scope_behavior(self):406 # This is what the old with statement compiled down to407 class ScopeExt(Extension):
25 unmodified lines
433 )434 assert tmpl.render(b=3, e=4) == "1|2|2|4|5"435436440@pytest.mark.ext437class TestNewstyleInternationalization:438 def test_trans(self):439 tmpl = newstyle_i18n_env.get_template("child.html")440 assert tmpl.render(LANGUAGE="de") == "<title>fehlend</title>pass auf"
83 unmodified lines
524 t = newstyle_i18n_env.get_template("explicitvars.html")525 assert t.render() == "%(foo)s"526527532@pytest.mark.ext528class TestAutoEscape:529 def test_scoped_setting(self):530 env = Environment(extensions=["jinja2.ext.autoescape"], autoescape=True)531 tmpl = env.from_string(
109 unmodified lines
modified:tests/test_filters.py-1 removed
22 unmodified lines
23 def __str__(self):24 return f"({self.value1},{self.value2})"252627@pytest.mark.filter27class TestFilter:28 def test_filter_calling(self, env):29 rv = env.call_filter("sum", [1, 2, 3])30 assert rv == 6
708 unmodified lines
modified:tests/test_imports.py-3 removed
21 unmodified lines
22 env.globals["bar"] = 2323 return env242526@pytest.mark.imports26class TestImports:27 def test_context_imports(self, test_env):28 t = test_env.from_string('{% import "module" as m %}{{ m.test() }}')29 assert t.render(foo=42) == "[|23]"
68 unmodified lines
98 with pytest.raises(UndefinedError, match="does not export the requested name"):99 t.render()100101103@pytest.mark.imports104@pytest.mark.includes102class TestIncludes:103 def test_context_include(self, test_env):104 t = test_env.from_string('{% include "header" %}')105 assert t.render(foo=42) == "[42|23]"
77 unmodified lines
modified:tests/test_inheritance.py-2 removed
71 unmodified lines
72 trim_blocks=True,73 )747576@pytest.mark.inheritance76class TestInheritance:77 def test_layout(self, env):78 tmpl = env.get_template("layout")79 assert tmpl.render() == (
150 unmodified lines
230 rv = env.get_template("index.html").render(the_foo=42).split()231 assert rv == ["43", "44", "45"]232233235@pytest.mark.inheritance234class TestBugFix:235 def test_fixed_macro_scoping_bug(self, env):236 assert (237 Environment(
47 unmodified lines
modified:tests/test_lexnparse.py-10 removed
10 unmodified lines
11from jinja2.lexer import TOKEN_EOF12from jinja2.lexer import TokenStream131415@pytest.mark.lexnparse16@pytest.mark.tokenstream15class TestTokenStream:16 test_tokens = [17 Token(1, TOKEN_BLOCK_BEGIN, ""),18 Token(2, TOKEN_BLOCK_END, ""),
20 unmodified lines
39 "block_end",40 ]414245@pytest.mark.lexnparse46@pytest.mark.lexer43class TestLexer:44 def test_raw1(self, env):45 tmpl = env.from_string(46 "{% raw %}foo{% endraw %}|"
116 unmodified lines
163 else:164 pytest.raises(TemplateSyntaxError, env.from_string, t)165166171@pytest.mark.lexnparse172@pytest.mark.parser167class TestParser:168 def test_php_syntax(self, env):169 env = Environment("<?", "?>", "<?=", "?>", "<!--", "-->")170 tmpl = env.from_string(
125 unmodified lines
296 )297 assert_error("{% unknown_tag %}", "Encountered unknown tag 'unknown_tag'.")298299306@pytest.mark.lexnparse307@pytest.mark.syntax300class TestSyntax:301 def test_call(self, env):302 env = Environment()303 env.globals["foo"] = lambda a, b, c, e, g: a + b + c + e + g
246 unmodified lines
550 tmpl = env.from_string('{{ -foo["bar"]|abs }}')551 assert tmpl.render(foo={"bar": 42}) == "42"552553562@pytest.mark.lexnparse563@pytest.mark.lstripblocks554class TestLstripBlocks:555 def test_lstrip(self, env):556 env = Environment(lstrip_blocks=True, trim_blocks=False)557 tmpl = env.from_string(""" {% if True %}\n {% endif %}""")
238 unmodified lines
modified:tests/test_loader.py-5 removed
13 unmodified lines
14from jinja2.exceptions import TemplateNotFound15from jinja2.loaders import split_template_path161718@pytest.mark.loaders18class TestLoaders:19 def test_dict_loader(self, dict_loader):20 env = Environment(loader=dict_loader)21 tmpl = env.get_template("justdict.html")
91 unmodified lines
113 assert split_template_path("./foo/bar") == ["foo", "bar"]114 pytest.raises(TemplateNotFound, split_template_path, "../foo")115116118@pytest.mark.loaders119@pytest.mark.filesystemloader117class TestFileSystemLoader:118 searchpath = os.path.join(119 os.path.dirname(os.path.abspath(__file__)), "res", "templates"120 )
53 unmodified lines
174 t = e.get_template("mojibake.txt")175 assert t.render() == expect176177181@pytest.mark.loaders182@pytest.mark.moduleloader178class TestModuleLoader:179 archive = None180181 def compile_down(self, prefix_loader, zip="deflated"):
168 unmodified lines
modified:tests/test_regression.py-2 removed
7 unmodified lines
8from jinja2 import TemplateNotFound9from jinja2 import TemplateSyntaxError101112@pytest.mark.regression12class TestCorner:13 def test_assigned_scoping(self, env):14 t = env.from_string(15 """
63 unmodified lines
79 )80 assert t.render(wrapper=23) == "[1][2][3][4]23"818284@pytest.mark.regression83class TestBug:84 def test_keyword_folding(self, env):85 env = Environment()86 env.filters["testing"] = lambda value, some: value + some
527 unmodified lines
modified:tests/test_security.py-3 removed
32 unmodified lines
33 def __repr__(self):34 return "PublicStuff"353637@pytest.mark.sandbox37class TestSandbox:38 def test_unsafe(self, env):39 env = SandboxedEnvironment()40 pytest.raises(
83 unmodified lines
124 with pytest.raises(TemplateRuntimeError):125 t.render(ctx)126127129@pytest.mark.sandbox128class TestStringFormat:129 def test_basic_format_safety(self):130 env = SandboxedEnvironment()131 t = env.from_string('{{ "a{0.__class__}b".format(42) }}')
14 unmodified lines
146 t = env.from_string('{{ ("a{0.foo}b{1}"|safe).format({"foo": 42}, "<foo>") }}')147 assert t.render() == "a42b&lt;foo&gt;"148149152@pytest.mark.sandbox150class TestStringFormatMap:151 def test_basic_format_safety(self):152 env = SandboxedEnvironment()153 t = env.from_string('{{ "a{x.__class__}b".format_map({"x":42}) }}')
13 unmodified lines
modified:tests/test_tests.py-1 removed
6 unmodified lines
7class MyDict(dict):8 pass91011@pytest.mark.test_tests11class TestTestsCase:12 def test_defined(self, env):13 tmpl = env.from_string("{{ missing is defined }}|{{ true is defined }}")14 assert tmpl.render() == "False|True"
194 unmodified lines
modified:tests/test_utils.py-8 removed
13 unmodified lines
14from jinja2.utils import select_autoescape15from jinja2.utils import urlize161718@pytest.mark.utils19@pytest.mark.lrucache18class TestLRUCache:19 def test_simple(self):20 d = LRUCache(3)21 d["a"] = 1
85 unmodified lines
107 assert d.setdefault("b", 2) == 2108 assert len(d) == 2109110113@pytest.mark.utils114@pytest.mark.helpers111class TestHelpers:112 def test_object_type_repr(self):113 class X:114 pass
20 unmodified lines
135 assert func("FOO.HTML")136 assert not func("FOO.TXT")137138143@pytest.mark.utils144@pytest.mark.escapeUrlizeTarget139class TestEscapeUrlizeTarget:140 def test_escape_urlize_target(self):141 url = "http://example.org"142 target = "<script>"
3 unmodified lines
146 "http://example.org</a>"147 )148149156@pytest.mark.utils157@pytest.mark.loremIpsum150class TestLoremIpsum:151 def test_lorem_ipsum_markup(self):152 """Test that output of lorem_ipsum is Markup by default."""153 assert isinstance(generate_lorem_ipsum(), Markup)
37 unmodified lines