diff --git a/tests/unit/browser/network/test_filescheme.py b/tests/unit/browser/network/test_filescheme.py index 126f81df5..1507d9a00 100644 --- a/tests/unit/browser/network/test_filescheme.py +++ b/tests/unit/browser/network/test_filescheme.py @@ -28,6 +28,7 @@ from PyQt5.QtCore import QUrl from PyQt5.QtNetwork import QNetworkRequest from qutebrowser.browser.network import filescheme +from qutebrowser.utils import jinja @pytest.mark.parametrize('create_file, create_dir, filterfunc, expected', [ @@ -76,6 +77,15 @@ class TestIsRoot: assert filescheme.is_root(directory) == is_root +def _file_url(path): + """Return a file:// url (as string) for the given LocalPath. + + Arguments: + path: The filepath as LocalPath (as handled by py.path) + """ + return jinja.file_url(str(path)) + + class TestDirbrowserHtml: Parsed = collections.namedtuple('Parsed', 'parent, folders, files') @@ -149,8 +159,8 @@ class TestDirbrowserHtml: parsed = parser(str(tmpdir)) assert parsed.parent assert not parsed.folders - foo_item = self.Item('file://' + str(foo_file), foo_file.relto(tmpdir)) - bar_item = self.Item('file://' + str(bar_file), bar_file.relto(tmpdir)) + foo_item = self.Item(_file_url(foo_file), foo_file.relto(tmpdir)) + bar_item = self.Item(_file_url(bar_file), bar_file.relto(tmpdir)) assert parsed.files == [bar_item, foo_item] def test_html_special_chars(self, tmpdir, parser): @@ -158,8 +168,7 @@ class TestDirbrowserHtml: special_file.ensure() parsed = parser(str(tmpdir)) - item = self.Item('file://' + str(special_file), - special_file.relto(tmpdir)) + item = self.Item(_file_url(special_file), special_file.relto(tmpdir)) assert parsed.files == [item] def test_dirs(self, tmpdir, parser): @@ -171,8 +180,8 @@ class TestDirbrowserHtml: parsed = parser(str(tmpdir)) assert parsed.parent assert not parsed.files - foo_item = self.Item('file://' + str(foo_dir), foo_dir.relto(tmpdir)) - bar_item = self.Item('file://' + str(bar_dir), bar_dir.relto(tmpdir)) + foo_item = self.Item(_file_url(foo_dir), foo_dir.relto(tmpdir)) + bar_item = self.Item(_file_url(bar_dir), bar_dir.relto(tmpdir)) assert parsed.folders == [bar_item, foo_item] def test_mixed(self, tmpdir, parser): @@ -182,8 +191,8 @@ class TestDirbrowserHtml: bar_dir.ensure(dir=True) parsed = parser(str(tmpdir)) - foo_item = self.Item('file://' + str(foo_file), foo_file.relto(tmpdir)) - bar_item = self.Item('file://' + str(bar_dir), bar_dir.relto(tmpdir)) + foo_item = self.Item(_file_url(foo_file), foo_file.relto(tmpdir)) + bar_item = self.Item(_file_url(bar_dir), bar_dir.relto(tmpdir)) assert parsed.parent assert parsed.files == [foo_item] assert parsed.folders == [bar_item]