]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Merge branch '2.11.x'
authorDavid Lord <davidism@gmail.com>
Thu, 6 Feb 2020 04:39:04 +0000 (20:39 -0800)
committerDavid Lord <davidism@gmail.com>
Thu, 6 Feb 2020 04:39:04 +0000 (20:39 -0800)
16 files changed:
1  2 
tests/conftest.py
tests/test_api.py
tests/test_async.py
tests/test_bytecode_cache.py
tests/test_core_tags.py
tests/test_debug.py
tests/test_ext.py
tests/test_filters.py
tests/test_imports.py
tests/test_inheritance.py
tests/test_lexnparse.py
tests/test_loader.py
tests/test_regression.py
tests/test_security.py
tests/test_tests.py
tests/test_utils.py

Simple merge
index 387fb3f16a6da7ebec854d05df393ebfc6add483,058ec56cb9941dbcc9965dd31bf4b8e798db15b7..0655c479d58732d9a2c8904619a141daff1825b3
@@@ -24,9 -25,7 +24,7 @@@ from jinja2.utils import environmentfun
  from jinja2.utils import evalcontextfunction
  
  
- @pytest.mark.api
- @pytest.mark.extended
 -class TestExtendedAPI(object):
 +class TestExtendedAPI:
      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):
 +class TestMeta:
      def test_find_undeclared_variables(self, env):
          ast = env.parse("{% set foo = 42 %}{{ bar + foo }}")
          x = meta.find_undeclared_variables(ast)
          assert list(i) == ["foo.html", "bar.html", None]
  
  
- @pytest.mark.api
- @pytest.mark.streaming
 -class TestStreaming(object):
 +class TestStreaming:
      def test_basic_streaming(self, env):
          t = env.from_string(
              "<ul>{% for item in seq %}<li>{{ loop.index }} - {{ item }}</li>"
              shutil.rmtree(tmp)
  
  
- @pytest.mark.api
- @pytest.mark.undefined
 -class TestUndefined(object):
 +class TestUndefined:
      def test_stopiteration_is_undefined(self):
          def test():
              raise StopIteration()
              Undefined(obj=42, name="upper")()
  
  
- @pytest.mark.api
- @pytest.mark.lowlevel
 -class TestLowLevel(object):
 +class TestLowLevel:
      def test_custom_code_generator(self):
          class CustomCodeGenerator(CodeGenerator):
              def visit_Const(self, node, frame=None):
index 70f11bec4f5ed8db455f0e8eeec00f89460b94a6,11efd849f062918d8f0b78100f6e51bb0f813e68..45713d5d5fa7c455589a1d9ca23e920ff62a5599
@@@ -130,8 -130,7 +130,7 @@@ def test_env_async()
      return env
  
  
- @pytest.mark.imports
 -class TestAsyncImports(object):
 +class TestAsyncImports:
      def test_context_imports(self, test_env_async):
          t = test_env_async.from_string('{% import "module" as m %}{{ m.test() }}')
          assert t.render(foo=42) == "[|23]"
          assert not hasattr(m, "notthere")
  
  
- @pytest.mark.imports
- @pytest.mark.includes
 -class TestAsyncIncludes(object):
 +class TestAsyncIncludes:
      def test_context_include(self, test_env_async):
          t = test_env_async.from_string('{% include "header" %}')
          assert t.render(foo=42) == "[42|23]"
          assert t.render().strip() == "(FOO)"
  
  
- @pytest.mark.core_tags
- @pytest.mark.for_loop
 -class TestAsyncForLoop(object):
 +class TestAsyncForLoop:
      def test_simple(self, test_env_async):
          tmpl = test_env_async.from_string("{% for item in seq %}{{ item }}{% endfor %}")
          assert tmpl.render(seq=list(range(10))) == "0123456789"
index 8979d159727d0b6b6431db4eb42cb1b643422ca1,c7882b1a2dff063efcdf6b2b89f27e5a6e951051..5b9eb0ff69cf6b51581f98ba14a0cbf1e7f32a22
@@@ -13,8 -14,7 +13,7 @@@ def env(package_loader, tmp_path)
      return Environment(loader=package_loader, bytecode_cache=bytecode_cache)
  
  
- @pytest.mark.byte_code_cache
 -class TestByteCodeCache(object):
 +class TestByteCodeCache:
      def test_simple(self, env):
          tmpl = env.get_template("test.html")
          assert tmpl.render().strip() == "BAR"
index df41348006f33ea5cbaa62206328296fbe416aa5,1bd96c41e98cfd2066c35707f711edd27fe87a9e..4bb95e0240a021845ec3d9431f251bd023c0a1af
@@@ -12,9 -13,7 +12,7 @@@ def env_trim()
      return Environment(trim_blocks=True)
  
  
- @pytest.mark.core_tags
- @pytest.mark.for_loop
 -class TestForLoop(object):
 +class TestForLoop:
      def test_simple(self, env):
          tmpl = env.from_string("{% for item in seq %}{{ item }}{% endfor %}")
          assert tmpl.render(seq=list(range(10))) == "0123456789"
          assert tmpl.render(x=0, seq=[1, 2, 3]) == "919293"
  
  
- @pytest.mark.core_tags
- @pytest.mark.if_condition
 -class TestIfCondition(object):
 +class TestIfCondition:
      def test_simple(self, env):
          tmpl = env.from_string("""{% if true %}...{% endif %}""")
          assert tmpl.render() == "..."
          assert tmpl.render() == "1"
  
  
- @pytest.mark.core_tags
- @pytest.mark.macros
 -class TestMacros(object):
 +class TestMacros:
      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):
 +class TestSet:
      def test_normal(self, env_trim):
          tmpl = env_trim.from_string("{% set foo = 1 %}{{ foo }}")
          assert tmpl.render() == "1"
              "{{ foo }}"
          )
          assert tmpl.render() == "11"
 -        assert tmpl.module.foo == u"11"
 +        assert tmpl.module.foo == "11"
  
  
- @pytest.mark.core_tags
- @pytest.mark.with_
 -class TestWith(object):
 +class TestWith:
      def test_with(self, env):
          tmpl = env.from_string(
              """\
index d3c3ac5c172b7d31d0b11d836f31fe2c3e672fd4,284b9e91a5bd9516982316fadb387c2c58bddd24..0aec78ae48f54a8f8c274df20fd7a2a337ea6cc1
@@@ -16,8 -17,7 +16,7 @@@ def fs_env(filesystem_loader)
      return Environment(loader=filesystem_loader)
  
  
- @pytest.mark.debug
 -class TestDebug(object):
 +class TestDebug:
      def assert_traceback_matches(self, callback, expected_tb):
          with pytest.raises(Exception) as exc_info:
              callback()
index 00656b38d31972b7e8806e3f96bfab8f166e91c3,8e4b411e1bafc070fb8ed1106e3df16523b6991c..94d20bee45a719fb8198b6e7501e14caca58b4d4
@@@ -160,8 -167,7 +160,7 @@@ class StreamFilterExtension(Extension)
              yield Token(lineno, "data", token.value[pos:])
  
  
- @pytest.mark.ext
 -class TestExtensions(object):
 +class TestExtensions:
      def test_extend_late(self):
          env = Environment()
          env.add_extension("jinja2.ext.autoescape")
          out = t.render()
  
          for value in ("context", "cycler", "filters", "abs", "tests", "!="):
 -            assert "'{}'".format(value) in out
 +            assert f"'{value}'" in out
  
  
- @pytest.mark.ext
 -class TestInternationalization(object):
 +class TestInternationalization:
      def test_trans(self):
          tmpl = i18n_env.get_template("child.html")
          assert tmpl.render(LANGUAGE="de") == "<title>fehlend</title>pass auf"
          ]
  
  
- @pytest.mark.ext
 -class TestScope(object):
 +class TestScope:
      def test_basic_scope_behavior(self):
          # This is what the old with statement compiled down to
          class ScopeExt(Extension):
          assert tmpl.render(b=3, e=4) == "1|2|2|4|5"
  
  
- @pytest.mark.ext
 -class TestNewstyleInternationalization(object):
 +class TestNewstyleInternationalization:
      def test_trans(self):
          tmpl = newstyle_i18n_env.get_template("child.html")
          assert tmpl.render(LANGUAGE="de") == "<title>fehlend</title>pass auf"
          assert t.render() == "%(foo)s"
  
  
- @pytest.mark.ext
 -class TestAutoEscape(object):
 +class TestAutoEscape:
      def test_scoped_setting(self):
          env = Environment(extensions=["jinja2.ext.autoescape"], autoescape=True)
          tmpl = env.from_string(
index bda5821fcaa85ca376f7a785e0dd753f0b81c505,37dde44d5c2939289c29bddf6df1674fa6a39021..ab6e93d41c6f51b71e45473c93fecd3c789e6cd6
@@@ -21,11 -26,10 +21,10 @@@ class Magic2
          self.value2 = value2
  
      def __str__(self):
 -        return u"(%s,%s)" % (text_type(self.value1), text_type(self.value2))
 +        return f"({self.value1},{self.value2})"
  
  
- @pytest.mark.filter
 -class TestFilter(object):
 +class TestFilter:
      def test_filter_calling(self, env):
          rv = env.call_filter("sum", [1, 2, 3])
          assert rv == 6
index ca4de705540ba14b0fa2c5b2a5a6635f0a8ab36d,fad2edafb690fa65ba438940273b8944eec67197..7a2bd9428d9990aa8feba1e8a1b887b51edeeefd
@@@ -23,8 -23,7 +23,7 @@@ def test_env()
      return env
  
  
- @pytest.mark.imports
 -class TestImports(object):
 +class TestImports:
      def test_context_imports(self, test_env):
          t = test_env.from_string('{% import "module" as m %}{{ m.test() }}')
          assert t.render(foo=42) == "[|23]"
          assert m.variable == 42
          assert not hasattr(m, "notthere")
  
 +    def test_not_exported(self, test_env):
 +        t = test_env.from_string("{% from 'module' import nothing %}{{ nothing() }}")
  
 -class TestIncludes(object):
 +        with pytest.raises(UndefinedError, match="does not export the requested name"):
 +            t.render()
 +
 +
- @pytest.mark.imports
- @pytest.mark.includes
 +class TestIncludes:
      def test_context_include(self, test_env):
          t = test_env.from_string('{% include "header" %}')
          assert t.render(foo=42) == "[42|23]"
index 331427e5285bb907be55540cf23588c850ae2954,e513d2e3eb3f2baacc1e2b8a64d4f2f6c9165d04..b95c47db747dd87c0a6b4f86f353c7d691f0ae67
@@@ -73,8 -74,7 +73,7 @@@ def env()
      )
  
  
- @pytest.mark.inheritance
 -class TestInheritance(object):
 +class TestInheritance:
      def test_layout(self, env):
          tmpl = env.get_template("layout")
          assert tmpl.render() == (
          assert rv == ["43", "44", "45"]
  
  
- @pytest.mark.inheritance
 -class TestBugFix(object):
 +class TestBugFix:
      def test_fixed_macro_scoping_bug(self, env):
          assert (
              Environment(
index fabbd36ee9c51982420d256bd738576dfaef70cf,e799acdcbadeb310d5bf50e4d9faee7becd58f82..d14a6ccba6663da5d3a5bb3c68b6cf5f839308e2
@@@ -12,9 -16,18 +12,7 @@@ from jinja2.lexer import TOKEN_EO
  from jinja2.lexer import TokenStream
  
  
- @pytest.mark.lexnparse
- @pytest.mark.tokenstream
 -# how does a string look like in jinja syntax?
 -if PY2:
 -
 -    def jinja_string_repr(string):
 -        return repr(string)[1:]
 -
 -
 -else:
 -    jinja_string_repr = repr
 -
 -
 -class TestTokenStream(object):
 +class TestTokenStream:
      test_tokens = [
          Token(1, TOKEN_BLOCK_BEGIN, ""),
          Token(2, TOKEN_BLOCK_END, ""),
@@@ -42,9 -55,7 +40,7 @@@
          ]
  
  
- @pytest.mark.lexnparse
- @pytest.mark.lexer
 -class TestLexer(object):
 +class TestLexer:
      def test_raw1(self, env):
          tmpl = env.from_string(
              "{% raw %}foo{% endraw %}|"
              pytest.raises(TemplateSyntaxError, env.from_string, t)
  
  
- @pytest.mark.lexnparse
- @pytest.mark.parser
 -class TestParser(object):
 +class TestParser:
      def test_php_syntax(self, env):
          env = Environment("<?", "?>", "<?=", "?>", "<!--", "-->")
          tmpl = env.from_string(
@@@ -303,9 -312,7 +297,7 @@@ and bar comment #
          assert_error("{% unknown_tag %}", "Encountered unknown tag 'unknown_tag'.")
  
  
- @pytest.mark.lexnparse
- @pytest.mark.syntax
 -class TestSyntax(object):
 +class TestSyntax:
      def test_call(self, env):
          env = Environment()
          env.globals["foo"] = lambda a, b, c, e, g: a + b + c + e + g
          assert tmpl.render(foo={"bar": 42}) == "42"
  
  
- @pytest.mark.lexnparse
- @pytest.mark.lstripblocks
 -class TestLstripBlocks(object):
 +class TestLstripBlocks:
      def test_lstrip(self, env):
          env = Environment(lstrip_blocks=True, trim_blocks=False)
          tmpl = env.from_string("""    {% if True %}\n    {% endif %}""")
index 0ad95383bfb7f21bf034224b0fd81d72e85280b8,71e00b253f041496dbb3c9338fd794ef18758319..1e081334bb30c8c278b476ee1b40132ec1c041e5
@@@ -15,8 -17,7 +15,7 @@@ from jinja2.exceptions import TemplateN
  from jinja2.loaders import split_template_path
  
  
- @pytest.mark.loaders
 -class TestLoaders(object):
 +class TestLoaders:
      def test_dict_loader(self, dict_loader):
          env = Environment(loader=dict_loader)
          tmpl = env.get_template("justdict.html")
          pytest.raises(TemplateNotFound, split_template_path, "../foo")
  
  
- @pytest.mark.loaders
- @pytest.mark.filesystemloader
 -class TestFileSystemLoader(object):
 +class TestFileSystemLoader:
      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):
 +class TestModuleLoader:
      archive = None
  
 -    def compile_down(self, prefix_loader, zip="deflated", py_compile=False):
 +    def compile_down(self, prefix_loader, zip="deflated"):
          log = []
          self.reg_env = Environment(loader=prefix_loader)
          if zip is not None:
index 7205bde71a98ff53fdf74981968319dec221f8e5,c5a0d680684852240d3769b3bfe9e277e13a7c9a..65ace87f5bf9e483d92e4f866bc83834186624a0
@@@ -7,10 -10,10 +7,9 @@@ from jinja2 import Templat
  from jinja2 import TemplateAssertionError
  from jinja2 import TemplateNotFound
  from jinja2 import TemplateSyntaxError
 -from jinja2._compat import text_type
  
  
- @pytest.mark.regression
 -class TestCorner(object):
 +class TestCorner:
      def test_assigned_scoping(self, env):
          t = env.from_string(
              """
@@@ -81,8 -84,7 +80,7 @@@
          assert t.render(wrapper=23) == "[1][2][3][4]23"
  
  
- @pytest.mark.regression
 -class TestBug(object):
 +class TestBug:
      def test_keyword_folding(self, env):
          env = Environment()
          env.filters["testing"] = lambda value, some: value + some
index c3b3f9c15188b623b953ada117d9ecd0c9022321,7e8974c891b51289f06f97428d8b38b411c4ee41..44ac47ab5efa1680b31714ad0912e21edcfb902a
@@@ -34,8 -37,7 +34,7 @@@ class PublicStuff
          return "PublicStuff"
  
  
- @pytest.mark.sandbox
 -class TestSandbox(object):
 +class TestSandbox:
      def test_unsafe(self, env):
          env = SandboxedEnvironment()
          pytest.raises(
                  t.render(ctx)
  
  
- @pytest.mark.sandbox
 -class TestStringFormat(object):
 +class TestStringFormat:
      def test_basic_format_safety(self):
          env = SandboxedEnvironment()
          t = env.from_string('{{ "a{0.__class__}b".format(42) }}')
          assert t.render() == "a42b&lt;foo&gt;"
  
  
- @pytest.mark.sandbox
 -@pytest.mark.skipif(
 -    not hasattr(str, "format_map"), reason="requires str.format_map method"
 -)
 -class TestStringFormatMap(object):
 +class TestStringFormatMap:
      def test_basic_format_safety(self):
          env = SandboxedEnvironment()
          t = env.from_string('{{ "a{x.__class__}b".format_map({"x":42}) }}')
index dbf6e6013ae221620cfbe1dccda7f4544bbf8107,b903e3b1e2f98666a11bf5ea883355b913402c05..d363653d336d24865afc15c7d60e40718d23640b
@@@ -8,8 -9,7 +8,7 @@@ class MyDict(dict)
      pass
  
  
- @pytest.mark.test_tests
 -class TestTestsCase(object):
 +class TestTestsCase:
      def test_defined(self, env):
          tmpl = env.from_string("{{ missing is defined }}|{{ true is defined }}")
          assert tmpl.render() == "False|True"
index 750002f6c1ef15000b869c013bdf6fe5c0eda4b9,b379a97ac641f3a0eec92aa0db4c71a6b66aff81..3e24166c24a2ff9c4488dfbb9f19f4541f5f78ee
@@@ -15,9 -18,7 +15,7 @@@ from jinja2.utils import select_autoesc
  from jinja2.utils import urlize
  
  
- @pytest.mark.utils
- @pytest.mark.lrucache
 -class TestLRUCache(object):
 +class TestLRUCache:
      def test_simple(self):
          d = LRUCache(3)
          d["a"] = 1
          assert len(d) == 2
  
  
- @pytest.mark.utils
- @pytest.mark.helpers
 -class TestHelpers(object):
 +class TestHelpers:
      def test_object_type_repr(self):
 -        class X(object):
 +        class X:
              pass
  
          assert object_type_repr(42) == "int object"
          assert not func("FOO.TXT")
  
  
- @pytest.mark.utils
- @pytest.mark.escapeUrlizeTarget
 -class TestEscapeUrlizeTarget(object):
 +class TestEscapeUrlizeTarget:
      def test_escape_urlize_target(self):
          url = "http://example.org"
          target = "<script>"
          )
  
  
- @pytest.mark.utils
- @pytest.mark.loremIpsum
 -class TestLoremIpsum(object):
 +class TestLoremIpsum:
      def test_lorem_ipsum_markup(self):
          """Test that output of lorem_ipsum is Markup by default."""
          assert isinstance(generate_lorem_ipsum(), Markup)