Use an autofixture that monkeypatches read_file for both tests
This commit is contained in:
parent
c3e615dfa3
commit
b18c1254a4
@ -21,30 +21,32 @@
|
||||
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
||||
from qutebrowser.utils import jinja
|
||||
|
||||
|
||||
def _read_file(path):
|
||||
@pytest.fixture(autouse=True)
|
||||
def patch_read_file(monkeypatch):
|
||||
def _read_file(path):
|
||||
"""Mocked utils.read_file."""
|
||||
if path == os.path.join('html', 'test.html'):
|
||||
return """Hello {{var}}"""
|
||||
else:
|
||||
raise ValueError("Invalid path {}!".format(path))
|
||||
|
||||
monkeypatch.setattr('qutebrowser.utils.jinja.utils.read_file', _read_file)
|
||||
|
||||
def test_simple_template(monkeypatch):
|
||||
|
||||
def test_simple_template():
|
||||
"""Test with a simple template."""
|
||||
monkeypatch.setattr(
|
||||
'qutebrowser.utils.jinja.utils.read_file',
|
||||
_read_file
|
||||
)
|
||||
template = jinja.env.get_template('test.html')
|
||||
# https://bitbucket.org/logilab/pylint/issue/490/
|
||||
data = template.render(var='World') # pylint: disable=no-member
|
||||
assert data == "Hello World"
|
||||
|
||||
|
||||
def test_utf8(monkeypatch):
|
||||
def test_utf8():
|
||||
"""Test rendering with an UTF8 template.
|
||||
|
||||
This was an attempt to get a failing test case for #127 but it seems
|
||||
@ -52,10 +54,6 @@ def test_utf8(monkeypatch):
|
||||
|
||||
https://github.com/The-Compiler/qutebrowser/issues/127
|
||||
"""
|
||||
monkeypatch.setattr(
|
||||
'qutebrowser.utils.jinja.utils.read_file',
|
||||
_read_file
|
||||
)
|
||||
template = jinja.env.get_template('test.html')
|
||||
# https://bitbucket.org/logilab/pylint/issue/490/
|
||||
data = template.render(var='\u2603') # pylint: disable=no-member
|
||||
|
Loading…
Reference in New Issue
Block a user