From 00949db2cfd07c7fc181bc3fc1089908401ca680 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 2 Oct 2014 06:22:06 +0200 Subject: [PATCH] Add testcases for jinja. This was an attempt to get a breaking test for #127 but it seems jinja isn't actually the issue. --- qutebrowser/test/utils/test_jinja.py | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 qutebrowser/test/utils/test_jinja.py diff --git a/qutebrowser/test/utils/test_jinja.py b/qutebrowser/test/utils/test_jinja.py new file mode 100644 index 000000000..4452ae893 --- /dev/null +++ b/qutebrowser/test/utils/test_jinja.py @@ -0,0 +1,61 @@ +# Copyright 2014 Florian Bruhin (The Compiler) +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""Tests for qutebrowser.utils.jinja.""" + +import unittest +import unittest.mock + +from qutebrowser.utils import jinja + + +def _read_file(path): + """Mocked utils.read_file.""" + if path == 'html/test.html': + return """Hello {{var}}""" + else: + raise ValueError("Invalid path {}!".format(path)) + + +@unittest.mock.patch('qutebrowser.utils.jinja.utils.read_file') +class JinjaTests(unittest.TestCase): + + """Tests for getting template via jinja.""" + + def test_simple_template(self, readfile_mock): + """Test with a simple template.""" + readfile_mock.side_effect = _read_file + template = jinja.env.get_template('test.html') + self.assertEqual(template.render(var='World'), "Hello World") + + def test_utf8(self, readfile_mock): + """Test rendering with an UTF8 template. + + This was an attempt to get a failing test case for #127 but it seems + the issue is elsewhere. + + https://github.com/The-Compiler/qutebrowser/issues/127 + """ + readfile_mock.side_effect = _read_file + template = jinja.env.get_template('test.html') + self.assertEqual(template.render(var='\u2603'), "Hello \u2603") + + +if __name__ == '__main__': + unittest.main()