Fix test_not_found

This commit is contained in:
Fritz Reichwald 2016-12-28 22:11:34 +01:00
parent f38dda5f16
commit 0bd3100de8
2 changed files with 12 additions and 6 deletions

View File

@ -58,7 +58,7 @@ html_fallback = """<!DOCTYPE html>
<img style="width: 100%; display: block; max-width: 256px;" src="{{ data_url("img/broken_qutebrowser_logo.png") }}" />
</td>
<td style="padding-left: 40px;">
<p><span style="font-size:120%;color:red">The error.html template could not be found!<br>Please check your qutebrowser installation</span><br>
<p><span style="font-size:120%;color:red">The %FILE% template could not be found!<br>Please check your qutebrowser installation</span><br>
%ERROR%</p>
</td>
</tr>
@ -85,7 +85,9 @@ class Loader(jinja2.BaseLoader):
source = utils.read_file(path)
except OSError as e:
source = html_fallback.replace("%ERROR%", html.escape(str(e)))
log.misc.error("The error.html template could not be found at " + path)
source = source.replace("%FILE%", html.escape(template))
log.misc.error("The {} template could not be found at {}".format(
template, path))
# Currently we don't implement auto-reloading, so we always return True
# for up-to-date.
return source, path, lambda: True

View File

@ -105,11 +105,15 @@ def test_data_url():
assert data == 'data:text/plain;base64,Zm9v' # 'foo'
def test_not_found():
def test_not_found(caplog):
"""Test with a template which does not exist."""
with pytest.raises(jinja2.TemplateNotFound) as excinfo:
jinja.render('does_not_exist.html')
assert str(excinfo.value) == 'does_not_exist.html'
with caplog.at_level(logging.ERROR):
data = jinja.render('does_not_exist.html')
assert "The does_not_exist.html template could not be found!" in data
assert len(caplog.records) == 1
assert caplog.records[0].msg.startswith("The does_not_exist.html template"
" could not be found at")
def test_utf8():