From cf45d970461bd55c1bdfae1f81fbccccbe77faee Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 12 Aug 2015 06:25:05 +0200 Subject: [PATCH] 100% test coverage for utils.jinja. --- scripts/dev/check_coverage.py | 1 + tests/utils/test_jinja.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/dev/check_coverage.py b/scripts/dev/check_coverage.py index 7c9fad45e..ccbcb65ef 100644 --- a/scripts/dev/check_coverage.py +++ b/scripts/dev/check_coverage.py @@ -58,6 +58,7 @@ PERFECT_FILES = [ 'qutebrowser/utils/utils.py', 'qutebrowser/utils/version.py', 'qutebrowser/utils/debug.py', + 'qutebrowser/utils/jinja.py', ] diff --git a/tests/utils/test_jinja.py b/tests/utils/test_jinja.py index 174a44df2..c0b95eacc 100644 --- a/tests/utils/test_jinja.py +++ b/tests/utils/test_jinja.py @@ -22,6 +22,7 @@ import os.path import pytest +import jinja2 from qutebrowser.utils import jinja @@ -34,7 +35,7 @@ def patch_read_file(monkeypatch): if path == os.path.join('html', 'test.html'): return """Hello {{var}}""" else: - raise ValueError("Invalid path {}!".format(path)) + raise IOError("Invalid path {}!".format(path)) monkeypatch.setattr('qutebrowser.utils.jinja.utils.read_file', _read_file) @@ -47,6 +48,13 @@ def test_simple_template(): assert data == "Hello World" +def test_not_found(): + """Test with a template which does not exist.""" + with pytest.raises(jinja2.TemplateNotFound) as excinfo: + jinja.env.get_template('does_not_exist.html') + assert str(excinfo.value) == 'does_not_exist.html' + + def test_utf8(): """Test rendering with an UTF8 template. @@ -59,3 +67,16 @@ def test_utf8(): # https://bitbucket.org/logilab/pylint/issue/490/ data = template.render(var='\u2603') # pylint: disable=no-member assert data == "Hello \u2603" + + +@pytest.mark.parametrize('name, expected', [ + (None, False), + ('foo', False), + ('foo.html', True), + ('foo.htm', True), + ('foo.xml', True), + ('blah/bar/foo.html', True), + ('foo.bar.html', True), +]) +def test_autoescape(name, expected): + assert jinja._guess_autoescape(name) == expected