Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error when service is not a dict #128

Merged
merged 1 commit into from
Mar 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fig/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from inspect import getdoc

from .. import __version__
from ..project import NoSuchService, DependencyError
from ..project import NoSuchService, ConfigurationError
from ..service import CannotBeScaledError
from .command import Command
from .formatter import Formatter
Expand Down Expand Up @@ -40,7 +40,7 @@ def main():
except KeyboardInterrupt:
log.error("\nAborting.")
sys.exit(1)
except (UserError, NoSuchService, DependencyError) as e:
except (UserError, NoSuchService, ConfigurationError) as e:
log.error(e.msg)
sys.exit(1)
except NoSuchCommand as e:
Expand Down
8 changes: 7 additions & 1 deletion fig/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def from_dicts(cls, name, service_dicts, client):
def from_config(cls, name, config, client):
dicts = []
for service_name, service in list(config.items()):
if not isinstance(service, dict):
raise ConfigurationError('Service "%s" doesn\'t have any configuration options. All top level keys in your fig.yml must map to a dictionary of configuration options.')
service['name'] = service_name
dicts.append(service)
return cls.from_dicts(name, dicts, client)
Expand Down Expand Up @@ -156,9 +158,13 @@ def __str__(self):
return self.msg


class DependencyError(Exception):
class ConfigurationError(Exception):
def __init__(self, msg):
self.msg = msg

def __str__(self):
return self.msg

class DependencyError(ConfigurationError):
pass

23 changes: 22 additions & 1 deletion tests/project_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import unicode_literals
from fig.project import Project
from fig.project import Project, ConfigurationError
from .testcases import DockerClientTestCase


Expand Down Expand Up @@ -37,6 +37,27 @@ def test_from_dict_sorts_in_dependency_order(self):
self.assertEqual(project.services[0].name, 'db')
self.assertEqual(project.services[1].name, 'web')

def test_from_config(self):
project = Project.from_config('figtest', {
'web': {
'image': 'ubuntu',
},
'db': {
'image': 'ubuntu',
},
}, self.client)
self.assertEqual(len(project.services), 2)
self.assertEqual(project.get_service('web').name, 'web')
self.assertEqual(project.get_service('web').options['image'], 'ubuntu')
self.assertEqual(project.get_service('db').name, 'db')
self.assertEqual(project.get_service('db').options['image'], 'ubuntu')

def test_from_config_throws_error_when_not_dict(self):
with self.assertRaises(ConfigurationError):
project = Project.from_config('figtest', {
'web': 'ubuntu',
}, self.client)

def test_get_service(self):
web = self.create_service('web')
project = Project('test', [web], self.client)
Expand Down