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
Provenance
- Commit
e08dadd- Tree
b6c8ae7- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
1164cc3- Parent 2
dd5a050
16 files changed+0 added−111 removed
modified:tests/conftest.py-44 removed
11 unmodified lines12 return True13 return False14 15 16-def 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")58-59-16 @pytest.fixture17 def env():18 """returns a new environment."""19 return Environment()37 unmodified linesmodified:tests/test_api.py-10 removed
22 unmodified lines23 from jinja2.utils import environmentfunction24 from jinja2.utils import evalcontextfunction25 26 27-@pytest.mark.api28-@pytest.mark.extended27 class TestExtendedAPI:28 def test_item_and_attribute(self, env):29 from jinja2.sandbox import SandboxedEnvironment30 127 unmodified lines158 with pytest.raises(OverflowError):159 t.render(total=MAX_RANGE + 1)160 161 164-@pytest.mark.api165-@pytest.mark.meta162 class 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 lines211 i = meta.find_referenced_templates(ast)212 assert list(i) == ["foo.html", "bar.html", None]213 214 219-@pytest.mark.api220-@pytest.mark.streaming215 class 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 lines252 finally:253 shutil.rmtree(tmp)254 255 262-@pytest.mark.api263-@pytest.mark.undefined256 class TestUndefined:257 def test_stopiteration_is_undefined(self):258 def test():259 raise StopIteration()127 unmodified lines387 ):388 Undefined(obj=42, name="upper")()389 390 399-@pytest.mark.api400-@pytest.mark.lowlevel391 class TestLowLevel:392 def test_custom_code_generator(self):393 class CustomCodeGenerator(CodeGenerator):394 def visit_Const(self, node, frame=None):24 unmodified linesmodified:tests/test_async.py-5 removed
128 unmodified lines129 env.globals["bar"] = 23130 return env131 132 133-@pytest.mark.imports133 class 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 lines178 assert m.variable == 42179 assert not hasattr(m, "notthere")180 181 183-@pytest.mark.imports184-@pytest.mark.includes182 class 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 lines275 )276 assert t.render().strip() == "(FOO)"277 278 282-@pytest.mark.core_tags283-@pytest.mark.for_loop279 class 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 linesmodified:tests/test_bytecode_cache.py-1 removed
11 unmodified lines12 bytecode_cache = FileSystemBytecodeCache(str(tmp_path))13 return Environment(loader=package_loader, bytecode_cache=bytecode_cache)14 15 16-@pytest.mark.byte_code_cache16 class TestByteCodeCache:17 def test_simple(self, env):18 tmpl = env.get_template("test.html")19 assert tmpl.render().strip() == "BAR"58 unmodified linesmodified:tests/test_core_tags.py-10 removed
10 unmodified lines11 def env_trim():12 return Environment(trim_blocks=True)13 14 15-@pytest.mark.core_tags16-@pytest.mark.for_loop15 class 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 lines297 )298 assert tmpl.render(x=0, seq=[1, 2, 3]) == "919293"299 300 303-@pytest.mark.core_tags304-@pytest.mark.if_condition301 class TestIfCondition:302 def test_simple(self, env):303 tmpl = env.from_string("""{% if true %}...{% endif %}""")304 assert tmpl.render() == "..."32 unmodified lines337 tmpl = env.from_string("{% if true %}{% set foo = 1 %}{% endif %}{{ foo }}")338 assert tmpl.render() == "1"339 340 345-@pytest.mark.core_tags346-@pytest.mark.macros341 class TestMacros:342 def test_simple(self, env_trim):343 tmpl = env_trim.from_string(344 """\116 unmodified lines461 assert tmpl.module.m(1, 2, 3) == "1|2|3"462 assert tmpl.module.m(1, x=7) == "1|7|7"463 464 471-@pytest.mark.core_tags472-@pytest.mark.set465 class 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 lines568 assert tmpl.render() == "11"569 assert tmpl.module.foo == "11"570 571 580-@pytest.mark.core_tags581-@pytest.mark.with_572 class TestWith:573 def test_with(self, env):574 tmpl = env.from_string(575 """\20 unmodified linesmodified:tests/test_debug.py-1 removed
14 unmodified lines15 """returns a new environment."""16 return Environment(loader=filesystem_loader)17 18 19-@pytest.mark.debug19 class TestDebug:20 def assert_traceback_matches(self, callback, expected_tb):21 with pytest.raises(Exception) as exc_info:22 callback()92 unmodified linesmodified:tests/test_ext.py-5 removed
158 unmodified lines159 if pos < end:160 yield Token(lineno, "data", token.value[pos:])161 162 163-@pytest.mark.ext163 class TestExtensions:164 def test_extend_late(self):165 env = Environment()166 env.add_extension("jinja2.ext.autoescape")91 unmodified lines258 for value in ("context", "cycler", "filters", "abs", "tests", "!="):259 assert f"'{value}'" in out260 261 263-@pytest.mark.ext262 class 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 lines400 (6, "ngettext", ("%(users)s user", "%(users)s users", None), ["third"]),401 ]402 403 406-@pytest.mark.ext404 class TestScope:405 def test_basic_scope_behavior(self):406 # This is what the old with statement compiled down to407 class ScopeExt(Extension):25 unmodified lines433 )434 assert tmpl.render(b=3, e=4) == "1|2|2|4|5"435 436 440-@pytest.mark.ext437 class 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 lines524 t = newstyle_i18n_env.get_template("explicitvars.html")525 assert t.render() == "%(foo)s"526 527 532-@pytest.mark.ext528 class TestAutoEscape:529 def test_scoped_setting(self):530 env = Environment(extensions=["jinja2.ext.autoescape"], autoescape=True)531 tmpl = env.from_string(109 unmodified linesmodified:tests/test_filters.py-1 removed
22 unmodified lines23 def __str__(self):24 return f"({self.value1},{self.value2})"25 26 27-@pytest.mark.filter27 class TestFilter:28 def test_filter_calling(self, env):29 rv = env.call_filter("sum", [1, 2, 3])30 assert rv == 6708 unmodified linesmodified:tests/test_imports.py-3 removed
21 unmodified lines22 env.globals["bar"] = 2323 return env24 25 26-@pytest.mark.imports26 class 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 lines98 with pytest.raises(UndefinedError, match="does not export the requested name"):99 t.render()100 101 103-@pytest.mark.imports104-@pytest.mark.includes102 class 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 linesmodified:tests/test_inheritance.py-2 removed
71 unmodified lines72 trim_blocks=True,73 )74 75 76-@pytest.mark.inheritance76 class TestInheritance:77 def test_layout(self, env):78 tmpl = env.get_template("layout")79 assert tmpl.render() == (150 unmodified lines230 rv = env.get_template("index.html").render(the_foo=42).split()231 assert rv == ["43", "44", "45"]232 233 235-@pytest.mark.inheritance234 class TestBugFix:235 def test_fixed_macro_scoping_bug(self, env):236 assert (237 Environment(47 unmodified linesmodified:tests/test_lexnparse.py-10 removed
10 unmodified lines11 from jinja2.lexer import TOKEN_EOF12 from jinja2.lexer import TokenStream13 14 15-@pytest.mark.lexnparse16-@pytest.mark.tokenstream15 class TestTokenStream:16 test_tokens = [17 Token(1, TOKEN_BLOCK_BEGIN, ""),18 Token(2, TOKEN_BLOCK_END, ""),20 unmodified lines39 "block_end",40 ]41 42 45-@pytest.mark.lexnparse46-@pytest.mark.lexer43 class TestLexer:44 def test_raw1(self, env):45 tmpl = env.from_string(46 "{% raw %}foo{% endraw %}|"116 unmodified lines163 else:164 pytest.raises(TemplateSyntaxError, env.from_string, t)165 166 171-@pytest.mark.lexnparse172-@pytest.mark.parser167 class TestParser:168 def test_php_syntax(self, env):169 env = Environment("<?", "?>", "<?=", "?>", "<!--", "-->")170 tmpl = env.from_string(125 unmodified lines296 )297 assert_error("{% unknown_tag %}", "Encountered unknown tag 'unknown_tag'.")298 299 306-@pytest.mark.lexnparse307-@pytest.mark.syntax300 class TestSyntax:301 def test_call(self, env):302 env = Environment()303 env.globals["foo"] = lambda a, b, c, e, g: a + b + c + e + g246 unmodified lines550 tmpl = env.from_string('{{ -foo["bar"]|abs }}')551 assert tmpl.render(foo={"bar": 42}) == "42"552 553 562-@pytest.mark.lexnparse563-@pytest.mark.lstripblocks554 class 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 linesmodified:tests/test_loader.py-5 removed
13 unmodified lines14 from jinja2.exceptions import TemplateNotFound15 from jinja2.loaders import split_template_path16 17 18-@pytest.mark.loaders18 class TestLoaders:19 def test_dict_loader(self, dict_loader):20 env = Environment(loader=dict_loader)21 tmpl = env.get_template("justdict.html")91 unmodified lines113 assert split_template_path("./foo/bar") == ["foo", "bar"]114 pytest.raises(TemplateNotFound, split_template_path, "../foo")115 116 118-@pytest.mark.loaders119-@pytest.mark.filesystemloader117 class TestFileSystemLoader:118 searchpath = os.path.join(119 os.path.dirname(os.path.abspath(__file__)), "res", "templates"120 )53 unmodified lines174 t = e.get_template("mojibake.txt")175 assert t.render() == expect176 177 181-@pytest.mark.loaders182-@pytest.mark.moduleloader178 class TestModuleLoader:179 archive = None180 181 def compile_down(self, prefix_loader, zip="deflated"):168 unmodified linesmodified:tests/test_regression.py-2 removed
7 unmodified lines8 from jinja2 import TemplateNotFound9 from jinja2 import TemplateSyntaxError10 11 12-@pytest.mark.regression12 class TestCorner:13 def test_assigned_scoping(self, env):14 t = env.from_string(15 """63 unmodified lines79 )80 assert t.render(wrapper=23) == "[1][2][3][4]23"81 82 84-@pytest.mark.regression83 class TestBug:84 def test_keyword_folding(self, env):85 env = Environment()86 env.filters["testing"] = lambda value, some: value + some527 unmodified linesmodified:tests/test_security.py-3 removed
32 unmodified lines33 def __repr__(self):34 return "PublicStuff"35 36 37-@pytest.mark.sandbox37 class TestSandbox:38 def test_unsafe(self, env):39 env = SandboxedEnvironment()40 pytest.raises(83 unmodified lines124 with pytest.raises(TemplateRuntimeError):125 t.render(ctx)126 127 129-@pytest.mark.sandbox128 class TestStringFormat:129 def test_basic_format_safety(self):130 env = SandboxedEnvironment()131 t = env.from_string('{{ "a{0.__class__}b".format(42) }}')14 unmodified lines146 t = env.from_string('{{ ("a{0.foo}b{1}"|safe).format({"foo": 42}, "<foo>") }}')147 assert t.render() == "a42b<foo>"148 149 152-@pytest.mark.sandbox150 class 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 linesmodified:tests/test_tests.py-1 removed
6 unmodified lines7 class MyDict(dict):8 pass9 10 11-@pytest.mark.test_tests11 class 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 linesmodified:tests/test_utils.py-8 removed
13 unmodified lines14 from jinja2.utils import select_autoescape15 from jinja2.utils import urlize16 17 18-@pytest.mark.utils19-@pytest.mark.lrucache18 class TestLRUCache:19 def test_simple(self):20 d = LRUCache(3)21 d["a"] = 185 unmodified lines107 assert d.setdefault("b", 2) == 2108 assert len(d) == 2109 110 113-@pytest.mark.utils114-@pytest.mark.helpers111 class TestHelpers:112 def test_object_type_repr(self):113 class X:114 pass20 unmodified lines135 assert func("FOO.HTML")136 assert not func("FOO.TXT")137 138 143-@pytest.mark.utils144-@pytest.mark.escapeUrlizeTarget139 class TestEscapeUrlizeTarget:140 def test_escape_urlize_target(self):141 url = "http://example.org"142 target = "<script>"3 unmodified lines146 "http://example.org</a>"147 )148 149 156-@pytest.mark.utils157-@pytest.mark.loremIpsum150 class 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