Browse Source

Merge pull request #1954 from nhumrich/master

Allow for user relative paths on EXTEND
Aanand Prasad 10 năm trước cách đây
mục cha
commit
87a50317ad
2 tập tin đã thay đổi với 22 bổ sung1 xóa
  1. 1 1
      compose/config/config.py
  2. 21 0
      tests/unit/config_test.py

+ 1 - 1
compose/config/config.py

@@ -516,7 +516,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):

+ 21 - 0
tests/unit/config_test.py

@@ -1032,6 +1032,27 @@ class ExtendsTest(unittest.TestCase):
         self.assertEqual(dicts[0]['environment'], {'FOO': '1'})
 
 
+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')