Skip to content
Myr

Add test for greater/less than (#624)

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

It can be helpful to have a test for values that are greater or less than another value, especially when looping over lists and using `select()` or `selectattr()` filters. This patch adds tests that allow a developer to check if a value is greater or less than another value. For example, if I have a list of vehicles and I want to find the motorcycles: vehicles | selectattr('wheels', 'lessthan', 3) Or, if I want to find large trucks: vehicles | selectattr('wheels', 'greaterthan', 4) Tests are included.

authored by Major Hayden · committed by David Lord · parent ebed13e · Browse files · 2 files+23 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

2 files+23 added−1 removed

  • tests:+10 added−0 removed
  • other:+13 added−1 removed

2 files+23 added−1 removed

modified:jinja2/tests.py+13 added-1 removed
150 unmodified lines
151 """Check if the value is escaped."""152 return hasattr(value, '__html__')153154155def test_greaterthan(value, other):156 """Check if value is greater than other."""157 return value > other158159160def test_lessthan(value, other):161 """Check if value is less than other."""162 return value < other163164165TESTS = {166 'odd': test_odd,167 'even': test_even,168 'divisibleby': test_divisibleby,
9 unmodified lines
178 'iterable': test_iterable,179 'callable': test_callable,180 'sameas': test_sameas,181 'equalto': test_equalto,172 'escaped': test_escaped182 'escaped': test_escaped,183 'greaterthan': test_greaterthan,184 'lessthan': test_lessthan185}
modified:tests/test_tests.py+10 added
100 unmodified lines
101 def test_escaped(self, env):102 env = Environment(autoescape=True)103 tmpl = env.from_string('{{ x is escaped }}|{{ y is escaped }}')104 assert tmpl.render(x='foo', y=Markup('foo')) == 'False|True'105106 def test_greaterthan(self, env):107 tmpl = env.from_string('{{ 1 is greaterthan 0 }}|'108 '{{ 0 is greaterthan 1 }}')109 assert tmpl.render() == 'True|False'110111 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'