From 0bd3100de81ed122c9afad98bf51e631f5615b5c Mon Sep 17 00:00:00 2001 From: Fritz Reichwald Date: Wed, 28 Dec 2016 22:11:34 +0100 Subject: [PATCH] Fix test_not_found --- qutebrowser/utils/jinja.py | 6 ++++-- tests/unit/utils/test_jinja.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/qutebrowser/utils/jinja.py b/qutebrowser/utils/jinja.py index b3f491ad9..737b4aee1 100644 --- a/qutebrowser/utils/jinja.py +++ b/qutebrowser/utils/jinja.py @@ -58,7 +58,7 @@ html_fallback = """ -

The error.html template could not be found!
Please check your qutebrowser installation

+

The %FILE% template could not be found!
Please check your qutebrowser installation

%ERROR%

@@ -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 diff --git a/tests/unit/utils/test_jinja.py b/tests/unit/utils/test_jinja.py index e951e3994..155de6d78 100644 --- a/tests/unit/utils/test_jinja.py +++ b/tests/unit/utils/test_jinja.py @@ -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():