Allow for user relative paths

'~/' in a path currently doesnt work, you get the following error:

[Errno 2] No such file or directory: u'/home/USER/folder/~/some/path/.yml'

Signed-off-by: Nick H <nick.humrich@gmail.com>
This commit is contained in:
Nick H 2015-09-01 12:40:24 -06:00
parent 83c514f838
commit a372275c6e
2 changed files with 22 additions and 1 deletions

View File

@ -499,7 +499,7 @@ def split_label(label):
def expand_path(working_dir, path):
return os.path.abspath(os.path.join(working_dir, path))
return os.path.abspath(os.path.join(working_dir, os.path.expanduser(path)))
def to_list(value):

View File

@ -950,6 +950,27 @@ class ExtendsTest(unittest.TestCase):
load_from_filename('tests/fixtures/extends/nonexistent-service.yml')
class ExpandPathTest(unittest.TestCase):
working_dir = '/home/user/somedir'
def test_expand_path_normal(self):
result = config.expand_path(self.working_dir, 'myfile')
self.assertEqual(result, self.working_dir + '/' + 'myfile')
def test_expand_path_absolute(self):
abs_path = '/home/user/otherdir/somefile'
result = config.expand_path(self.working_dir, abs_path)
self.assertEqual(result, abs_path)
def test_expand_path_with_tilde(self):
test_path = '~/otherdir/somefile'
with mock.patch.dict(os.environ):
os.environ['HOME'] = user_path = '/home/user/'
result = config.expand_path(self.working_dir, test_path)
self.assertEqual(result, user_path + 'otherdir/somefile')
class BuildPathTest(unittest.TestCase):
def setUp(self):
self.abs_context_path = os.path.join(os.getcwd(), 'tests/fixtures/build-ctx')