From 892677a9d3dc3d6fb3b425d2ebd7c19e7f729879 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Thu, 9 Jan 2014 15:30:36 +0000 Subject: [PATCH] Very basic CLI smoke test See #8. --- fig/cli/command.py | 7 +++++-- tests/cli_test.py | 12 ++++++++++++ tests/fixtures/simple-figfile/fig.yml | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/cli_test.py create mode 100644 tests/fixtures/simple-figfile/fig.yml diff --git a/fig/cli/command.py b/fig/cli/command.py index fb0adaf0..4e0705a9 100644 --- a/fig/cli/command.py +++ b/fig/cli/command.py @@ -15,6 +15,8 @@ from .utils import cached_property, docker_url log = logging.getLogger(__name__) class Command(DocoptCommand): + base_dir = '.' + @cached_property def client(self): return Client(docker_url()) @@ -22,10 +24,11 @@ class Command(DocoptCommand): @cached_property def project(self): try: - config = yaml.load(open('fig.yml')) + yaml_path = os.path.join(self.base_dir, 'fig.yml') + config = yaml.load(open(yaml_path)) except IOError as e: if e.errno == errno.ENOENT: - log.error("Can't find %s. Are you in the right directory?", e.filename) + log.error("Can't find %s. Are you in the right directory?", os.path.basename(e.filename)) else: log.error(e) diff --git a/tests/cli_test.py b/tests/cli_test.py new file mode 100644 index 00000000..ffd7fd41 --- /dev/null +++ b/tests/cli_test.py @@ -0,0 +1,12 @@ +from __future__ import unicode_literals +from __future__ import absolute_import +from . import unittest +from fig.cli.main import TopLevelCommand + +class CLITestCase(unittest.TestCase): + def setUp(self): + self.command = TopLevelCommand() + self.command.base_dir = 'tests/fixtures/simple-figfile' + + def test_help(self): + self.assertRaises(SystemExit, lambda: self.command.dispatch(['-h'], None)) diff --git a/tests/fixtures/simple-figfile/fig.yml b/tests/fixtures/simple-figfile/fig.yml new file mode 100644 index 00000000..aef2d39b --- /dev/null +++ b/tests/fixtures/simple-figfile/fig.yml @@ -0,0 +1,2 @@ +simple: + image: ubuntu