Browse Source

Falsy values in COMPOSE_CONVERT_WINDOWS_PATHS are properly recognized

Signed-off-by: Joffrey F <[email protected]>
Joffrey F 8 years ago
parent
commit
de38c023ce
3 changed files with 52 additions and 1 deletions
  1. 1 1
      compose/config/config.py
  2. 11 0
      compose/config/environment.py
  3. 40 0
      tests/unit/config/environment_test.py

+ 1 - 1
compose/config/config.py

@@ -712,7 +712,7 @@ def finalize_service(service_config, service_names, version, environment):
     if 'volumes' in service_dict:
         service_dict['volumes'] = [
             VolumeSpec.parse(
-                v, environment.get('COMPOSE_CONVERT_WINDOWS_PATHS')
+                v, environment.get_boolean('COMPOSE_CONVERT_WINDOWS_PATHS')
             ) for v in service_dict['volumes']
         ]
 

+ 11 - 0
compose/config/environment.py

@@ -105,3 +105,14 @@ class Environment(dict):
                 super(Environment, self).get(key.upper(), *args, **kwargs)
             )
         return super(Environment, self).get(key, *args, **kwargs)
+
+    def get_boolean(self, key):
+        # Convert a value to a boolean using "common sense" rules.
+        # Unset, empty, "0" and "false" (i-case) yield False.
+        # All other values yield True.
+        value = self.get(key)
+        if not value:
+            return False
+        if value.lower() in ['0', 'false']:
+            return False
+        return True

+ 40 - 0
tests/unit/config/environment_test.py

@@ -0,0 +1,40 @@
+# encoding: utf-8
+from __future__ import absolute_import
+from __future__ import print_function
+from __future__ import unicode_literals
+
+from compose.config.environment import Environment
+from tests import unittest
+
+
+class EnvironmentTest(unittest.TestCase):
+    def test_get_simple(self):
+        env = Environment({
+            'FOO': 'bar',
+            'BAR': '1',
+            'BAZ': ''
+        })
+
+        assert env.get('FOO') == 'bar'
+        assert env.get('BAR') == '1'
+        assert env.get('BAZ') == ''
+
+    def test_get_undefined(self):
+        env = Environment({
+            'FOO': 'bar'
+        })
+        assert env.get('FOOBAR') is None
+
+    def test_get_boolean(self):
+        env = Environment({
+            'FOO': '',
+            'BAR': '0',
+            'BAZ': 'FALSE',
+            'FOOBAR': 'true',
+        })
+
+        assert env.get_boolean('FOO') is False
+        assert env.get_boolean('BAR') is False
+        assert env.get_boolean('BAZ') is False
+        assert env.get_boolean('FOOBAR') is True
+        assert env.get_boolean('UNDEFINED') is False