Skip to content
Myr

Add tests for Undefined classes

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

authored by EtiennePelletier · committed by David Lord · parent 53a5d0a · Browse files · 1 file+15 added−0 removed
This commit

State

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

Diff stats

1 file+15 added−0 removed

  • tests:+15 added−0 removed

1 file+15 added−0 removed

modified:tests/test_api.py+15 added
268 unmodified lines
269 assert env.from_string('{{ foo.missing }}').render(foo=42) == ''270 assert env.from_string('{{ not missing }}').render() == 'True'271 pytest.raises(UndefinedError,272 env.from_string('{{ missing - 1}}').render)273 und1 = Undefined(name='x')274 und2 = Undefined(name='y')275 assert und1 == und2276 assert und1 != 42277 assert hash(und1) == hash(und2) == hash(Undefined())278 with pytest.raises(AttributeError):279 getattr(Undefined, '__slots__')280281 def test_chainable_undefined(self):282 env = Environment(undefined=ChainableUndefined)283 # The following tests are copied from test_default_undefined
4 unmodified lines
288 assert env.from_string('{{ foo.missing }}').render(foo=42) == ''289 assert env.from_string('{{ not missing }}').render() == 'True'290 pytest.raises(UndefinedError,291 env.from_string('{{ missing - 1}}').render)292 with pytest.raises(AttributeError):293 getattr(ChainableUndefined, '__slots__')294295 # The following tests ensure subclass functionality works as expected296 assert env.from_string('{{ missing.bar["baz"] }}').render() == u''297 assert env.from_string('{{ foo.bar["baz"]._undefined_name }}').render() \
13 unmodified lines
311 == 'True'312 assert env.from_string('{{ foo.missing }}').render(foo=42) \313 == u"{{ no such element: int object['missing'] }}"314 assert env.from_string('{{ not missing }}').render() == 'True'315 undefined_hint = 'this is testing undefined hint of DebugUndefined'316 assert str(DebugUndefined(hint=undefined_hint)) == u'{{ undefined value printed: %s }}' % undefined_hint317 with pytest.raises(AttributeError):318 getattr(DebugUndefined, '__slots__')319320 def test_strict_undefined(self):321 env = Environment(undefined=StrictUndefined)322 pytest.raises(UndefinedError, env.from_string('{{ missing }}').render)
8 unmodified lines
331 pytest.raises(UndefinedError,332 env.from_string('{{ not missing }}').render)333 assert env.from_string('{{ missing|default("default", true) }}')\334 .render() == 'default'335 with pytest.raises(AttributeError):336 getattr(StrictUndefined, '__slots__')337338 def test_indexing_gives_undefined(self):339 t = Template("{{ var[42].foo }}")340 pytest.raises(UndefinedError, t.render, var=0)
49 unmodified lines