Browse Source

Tweak and test warning shown when version is a dict

Signed-off-by: Aanand Prasad <[email protected]>
Aanand Prasad 9 years ago
parent
commit
1152c5b25b
2 changed files with 15 additions and 10 deletions
  1. 3 3
      compose/config/config.py
  2. 12 7
      tests/unit/config/config_test.py

+ 3 - 3
compose/config/config.py

@@ -138,9 +138,9 @@ class ConfigFile(namedtuple('_ConfigFile', 'filename config')):
         version = self.config['version']
 
         if isinstance(version, dict):
-            log.warn("Unexpected type for field 'version', in file {} assuming "
-                     "version is the name of a service, and defaulting to "
-                     "Compose file version 1".format(self.filename))
+            log.warn('Unexpected type for "version" key in "{}". Assuming '
+                     '"version" is the name of a service, and defaulting to '
+                     'Compose file version 1.'.format(self.filename))
             return V1
 
         if not isinstance(version, six.string_types):

+ 12 - 7
tests/unit/config/config_test.py

@@ -232,13 +232,18 @@ class ConfigTest(unittest.TestCase):
         assert volumes['other'] == {}
 
     def test_load_service_with_name_version(self):
-        config_data = config.load(
-            build_config_details({
-                'version': {
-                    'image': 'busybox'
-                }
-            }, 'working_dir', 'filename.yml')
-        )
+        with mock.patch('compose.config.config.log') as mock_logging:
+            config_data = config.load(
+                build_config_details({
+                    'version': {
+                        'image': 'busybox'
+                    }
+                }, 'working_dir', 'filename.yml')
+            )
+
+        assert 'Unexpected type for "version" key in "filename.yml"' \
+            in mock_logging.warn.call_args[0][0]
+
         service_dicts = config_data.services
         self.assertEqual(
             service_sort(service_dicts),