Add _FILE handling

This commit is contained in:
Thomas Adamcik 2010-10-31 23:33:04 +01:00
parent e8371129f7
commit 3661800563
2 changed files with 21 additions and 3 deletions

View File

@ -51,7 +51,7 @@ 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'):
if attr.endswith('_PATH') or attr.endswith('_FILE'):
value = os.path.expanduser(value)
value = os.path.abspath(value)
return value

View File

@ -73,12 +73,30 @@ class SettingsProxyTest(unittest.TestCase):
expected = os.path.expanduser('~/test')
self.assertEqual(acctual, expected)
def test_value_not_ending_in_path_is_not_expanded(self):
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)
def test_value_ending_in_file_is_expanded(self):
self.settings.TEST_FILE = '~/test'
acctual = self.settings.TEST_FILE
expected = os.path.expanduser('~/test')
self.assertEqual(acctual, expected)
def test_value_ending_in_file_is_absolute(self):
self.settings.TEST_FILE = './test'
acctual = self.settings.TEST_FILE
expected = os.path.abspath('./test')
self.assertEqual(acctual, expected)
def test_value_not_ending_in_path_or_file_is_not_expanded(self):
self.settings.TEST = '~/test'
acctual = self.settings.TEST
self.assertEqual(acctual, '~/test')
def test_value_not_ending_in_path_is_not_absolute(self):
def test_value_not_ending_in_path_or_file_is_not_absolute(self):
self.settings.TEST = './test'
acctual = self.settings.TEST
self.assertEqual(acctual, './test')