Skip to content
Myr

Merge pull request #1071 from btharper/pytest-raises

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

Eliminate dead code by using pytests.raises instead of try/except/else

authored by David Lord · committed by GitHub · parents 3ea88fe, 051b521 · Browse files · 2 files+3 added−15 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+3 added−15 removed

  • tests:+3 added−15 removed

2 files+3 added−15 removed

modified:tests/test_api.py+1 added-5 removed
221 unmodified lines
222 t = Template('A{{ test().missingattribute }}B')223 pytest.raises(UndefinedError, t.render, test=test)224225 def test_undefined_and_special_attributes(self):226 try:226 with pytest.raises(AttributeError):227 Undefined('Foo').__dict__228 except AttributeError:229 pass230 else:231 assert False, "Expected actual attribute error"228229 def test_logging_undefined(self):230 _messages = []231
154 unmodified lines
modified:tests/test_security.py+2 added-10 removed
138 unmodified lines
139 t = env.from_string('{{ %s }}' % expr)140 assert t.render(ctx) == rv141 env.intercepted_binops = frozenset(['+'])142 t = env.from_string('{{ %s }}' % expr)143 try:143 with pytest.raises(TemplateRuntimeError):144 t.render(ctx)145 except TemplateRuntimeError as e:146 pass147 else:148 assert False, 'expected runtime error'145146 def test_unary_operator_intercepting(self, env):147 def disable_op(arg):148 raise TemplateRuntimeError('that operator so does not work')
3 unmodified lines
152 t = env.from_string('{{ %s }}' % expr)153 assert t.render(ctx) == rv154 env.intercepted_unops = frozenset(['-'])155 t = env.from_string('{{ %s }}' % expr)160 try:156 with pytest.raises(TemplateRuntimeError):157 t.render(ctx)162 except TemplateRuntimeError as e:163 pass164 else:165 assert False, 'expected runtime error'158159160@pytest.mark.sandbox161class TestStringFormat(object):
39 unmodified lines