Replace isabs with exists in transform

In UserStyleSheet.transform os.path.isabs was replaced with os.path.exists, a
more fitting condition. Accordingly two test cases needed to include mocks for
os.path.exists and QUrl.fromLocalFile.
This commit is contained in:
Lamar Pavel 2015-05-27 15:39:58 +02:00
parent e12dce9d55
commit 4851a3d442
2 changed files with 11 additions and 3 deletions

View File

@ -1165,7 +1165,7 @@ class UserStyleSheet(File):
if not value:
return None
path = super().transform(value)
if os.path.isabs(path):
if os.path.exists(path):
return QUrl.fromLocalFile(path)
else:
data = base64.b64encode(value.encode('utf-8')).decode('ascii')

View File

@ -1930,13 +1930,21 @@ class TestUserStyleSheet:
"""Test transform with an empty value."""
assert self.t.transform('') is None
def test_transform_file(self):
def test_transform_file(self, os_path, mocker):
"""Test transform with a filename."""
qurl = mocker.patch('qutebrowser.config.configtypes.QUrl',
autospec=True)
qurl.fromLocalFile.return_value = QUrl("file:///foo/bar")
os_path.exists.return_value = True
path = os.path.join(os.path.sep, 'foo', 'bar')
assert self.t.transform(path) == QUrl("file:///foo/bar")
def test_transform_file_expandvars(self, monkeypatch):
def test_transform_file_expandvars(self, os_path, monkeypatch, mocker):
"""Test transform with a filename (expandvars)."""
qurl = mocker.patch('qutebrowser.config.configtypes.QUrl',
autospec=True)
qurl.fromLocalFile.return_value = QUrl("file:///foo/bar")
os_path.exists.return_value = True
monkeypatch.setenv('FOO', 'foo')
path = os.path.join(os.path.sep, '$FOO', 'bar')
assert self.t.transform(path) == QUrl("file:///foo/bar")