Add special casing of _PATH settings

This commit is contained in:
Thomas Adamcik 2010-10-31 20:58:58 +01:00
parent 91f9180c39
commit 70fe571b05
2 changed files with 16 additions and 0 deletions

View File

@ -51,6 +51,9 @@ class SettingsProxy(object):
value = self.current[attr]
if type(value) != bool and not value:
raise SettingsError(u'Setting "%s" is empty.' % attr)
if attr.endswith('_PATH'):
value = os.path.expanduser(value)
value = os.path.abspath(value)
return value
def __setattr__(self, attr, value):

View File

@ -1,3 +1,4 @@
import os
import unittest
from mopidy import settings as default_settings_module
@ -65,3 +66,15 @@ class SettingsProxyTest(unittest.TestCase):
def test_runtime_value_included_in_current(self):
self.settings.TEST = 'test'
self.assertEqual(self.settings.current['TEST'], 'test')
def test_value_ending_in_path_is_expanded(self):
self.settings.TEST_PATH = '~/test'
acctual = self.settings.TEST_PATH
expected = os.path.expanduser('~/test')
self.assertEqual(acctual, expected)
def test_value_ending_in_path_is_absolute(self):
self.settings.TEST_PATH = './test'
acctual = self.settings.TEST_PATH
expected = os.path.abspath('./test')
self.assertEqual(acctual, expected)