Skip to content
Myr

Change grouping behavior of tests. This fixes #401

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 028f058 · Browse files · 3 files+20 added−1 removed
This commit

State

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

Diff stats

3 files+20 added−1 removed

  • tests:+14 added−0 removed
  • other:+6 added−1 removed

3 files+20 added−1 removed

modified:jinja2/parser.py+1 added-1 removed
804 unmodified lines
805 self.stream.current.test_any('name:else', 'name:or',806 'name:and')):807 if self.stream.current.test('name:is'):808 self.fail('You cannot chain multiple tests with is')809 args = [self.parse_expression()]809 args = [self.parse_primary()]810 else:811 args = []812 node = nodes.Test(node, name, args, kwargs, dyn_args,813 dyn_kwargs, lineno=token.lineno)
57 unmodified lines
modified:tests/test_tests.py+14 added
110 unmodified lines
111 def test_lessthan(self, env):112 tmpl = env.from_string('{{ 0 is lessthan 1 }}|'113 '{{ 1 is lessthan 0 }}')114 assert tmpl.render() == 'True|False'115116 def test_multiple_tests(self):117 items = []118 def matching(x, y):119 items.append((x, y))120 return False121 env = Environment()122 env.tests['matching'] = matching123 tmpl = env.from_string("{{ 'us-west-1' is matching "124 "'(us-east-1|ap-northeast-1)' "125 "or 'stage' is matching '(dev|stage)' }}")126 assert tmpl.render() == 'False'127 assert items == [('us-west-1', '(us-east-1|ap-northeast-1)'),128 ('stage', '(dev|stage)')]
modified:CHANGES+5 added
28 unmodified lines
29 and hooked it up with the new policy framework.30- Block sets are now marked `safe` by default.31- On Python 2 the asciification of ASCII strings can now be disabled with32 the `compiler.ascii_str` policy.33- Tests now no longer accept an arbitrary expression as first argument but34 a restricted one. This means that you can now properly use multiple35 tests in one expression without extra parentheses. In particular you can36 now write ``foo is divisibleby 2 or foo is divisibleby 3``37 as you would expect.3839Version 2.8.240-------------41
381 unmodified lines