Include expandvars in File.transform, adjust test

This commit is contained in:
Lamar Pavel 2015-05-27 14:40:07 +02:00
parent cfae36c5c8
commit e12dce9d55
2 changed files with 4 additions and 5 deletions

View File

@ -803,6 +803,7 @@ class File(BaseType):
if not value: if not value:
return None return None
value = os.path.expanduser(value) value = os.path.expanduser(value)
value = os.path.expandvars(value)
if not os.path.isabs(value): if not os.path.isabs(value):
if standarddir.config(): if standarddir.config():
abspath = os.path.join(standarddir.config(), value) abspath = os.path.join(standarddir.config(), value)
@ -818,10 +819,8 @@ class File(BaseType):
raise configexc.ValidationError(value, "may not be empty!") raise configexc.ValidationError(value, "may not be empty!")
value = os.path.expanduser(value) value = os.path.expanduser(value)
try: try:
if not os.path.isabs(value): if os.path.isfile(os.path.join(standarddir.config(), value)):
abspath = os.path.join(standarddir.config(), value) return
if os.path.isfile(abspath):
return
if not os.path.isfile(value): if not os.path.isfile(value):
raise configexc.ValidationError(value, "must be a valid file!") raise configexc.ValidationError(value, "must be a valid file!")
if not os.path.isabs(value): if not os.path.isabs(value):
@ -1166,7 +1165,6 @@ class UserStyleSheet(File):
if not value: if not value:
return None return None
path = super().transform(value) path = super().transform(value)
path = os.path.expandvars(path)
if os.path.isabs(path): if os.path.isabs(path):
return QUrl.fromLocalFile(path) return QUrl.fromLocalFile(path)
else: else:

View File

@ -1398,6 +1398,7 @@ class TestFile:
def test_transform(self, os_path): def test_transform(self, os_path):
"""Test transform.""" """Test transform."""
os_path.expanduser.side_effect = lambda x: x.replace('~', '/home/foo') os_path.expanduser.side_effect = lambda x: x.replace('~', '/home/foo')
os_path.expandvars.side_effect = lambda x: x
assert self.t.transform('~/foobar') == '/home/foo/foobar' assert self.t.transform('~/foobar') == '/home/foo/foobar'
os_path.expanduser.assert_called_once_with('~/foobar') os_path.expanduser.assert_called_once_with('~/foobar')