Browse Source

Merge pull request #3459 from shin-/2487-split-volume-path

Always use the Windows version of splitdrive when parsing volume mappings
Aanand Prasad 9 years ago
parent
commit
7763122ecb
2 changed files with 11 additions and 4 deletions
  1. 2 1
      compose/config/config.py
  2. 9 3
      tests/unit/config/config_test.py

+ 2 - 1
compose/config/config.py

@@ -3,6 +3,7 @@ from __future__ import unicode_literals
 
 import functools
 import logging
+import ntpath
 import operator
 import os
 import string
@@ -944,7 +945,7 @@ def split_path_mapping(volume_path):
     if volume_path.startswith('.') or volume_path.startswith('~'):
         drive, volume_config = '', volume_path
     else:
-        drive, volume_config = os.path.splitdrive(volume_path)
+        drive, volume_config = ntpath.splitdrive(volume_path)
 
     if ':' in volume_config:
         (host, container) = volume_config.split(':', 1)

+ 9 - 3
tests/unit/config/config_test.py

@@ -2658,15 +2658,21 @@ class ExpandPathTest(unittest.TestCase):
 
 
 class VolumePathTest(unittest.TestCase):
-
-    @pytest.mark.xfail((not IS_WINDOWS_PLATFORM), reason='does not have a drive')
     def test_split_path_mapping_with_windows_path(self):
         host_path = "c:\\Users\\msamblanet\\Documents\\anvil\\connect\\config"
         windows_volume_path = host_path + ":/opt/connect/config:ro"
         expected_mapping = ("/opt/connect/config:ro", host_path)
 
         mapping = config.split_path_mapping(windows_volume_path)
-        self.assertEqual(mapping, expected_mapping)
+        assert mapping == expected_mapping
+
+    def test_split_path_mapping_with_windows_path_in_container(self):
+        host_path = 'c:\\Users\\remilia\\data'
+        container_path = 'c:\\scarletdevil\\data'
+        expected_mapping = (container_path, host_path)
+
+        mapping = config.split_path_mapping('{0}:{1}'.format(host_path, container_path))
+        assert mapping == expected_mapping
 
 
 @pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason='paths use slash')