Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albertovara committed Jul 20, 2017
1 parent 08901b1 commit 6b3675f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
7 changes: 5 additions & 2 deletions ardy/core/cmd/main.py
Expand Up @@ -19,6 +19,7 @@ class Command(object):

def __init__(self, *args, **kwargs):
arguments = kwargs.get("arguments", False)
self.exit_at_finish = kwargs.get("exit_at_finish", True)
if not arguments:
arguments = sys.argv[1:]

Expand Down Expand Up @@ -106,11 +107,13 @@ def parse_commandline(self):

def exit_with_error(self, msg=""):
self.print_error(msg)
sys.exit(2)
if self.exit_at_finish:
sys.exit(2)

def exit_ok(self, msg=""):
self.print_ok(msg)
sys.exit(0)
if self.exit_at_finish:
sys.exit(0)

@staticmethod
def print_ok(msg=""):
Expand Down
17 changes: 8 additions & 9 deletions tests/test_cmd.py
Expand Up @@ -39,7 +39,7 @@ def test_base(self):
test_folder = "myexamplelambdaproject_test"
try:
arguments = ["-p", test_folder, "-f", "config.json"]
Command(arguments=arguments)
Command(arguments=arguments, exit_at_finish=False)
self.fail("notexist folder not exists")
except ArdyNoDirError:
pass
Expand All @@ -48,7 +48,7 @@ def test_base(self):

try:
arguments = ["-p", test_folder, "-f", "config.json"]
Command(arguments=arguments)
Command(arguments=arguments, exit_at_finish=False)
self.fail("config.json not exist in myexamplelambdaproject")
except ArdyNoFileError:
pass
Expand All @@ -57,24 +57,23 @@ def test_base(self):

if sys.version_info <= (3, 0):
with self.assertRaises(SystemExit):
Command(arguments=self.base_arguments)
Command(arguments=self.base_arguments, exit_at_finish=False)
else:
with self.assertRaises(SystemExit):
command = Command(arguments=self.base_arguments)
self.assert_base_conf(command)
command = Command(arguments=self.base_arguments, exit_at_finish=False)
self.assert_base_conf(command)

def test_deploy_error(self):
lambda_functions_to_deploy = ["lambda1", "lambda2"]
with self.assertRaises(SystemExit):
Command(arguments=self.base_arguments + ["deploy", ] + lambda_functions_to_deploy)
Command(arguments=self.base_arguments + ["deploy", ] + lambda_functions_to_deploy, exit_at_finish=False)
self.fail("Environment is needed is it's defined in config.json")

@patch.object(Deploy, "run")
def test_deploy(self, deploy_run_mock):
lambda_functions_to_deploy = ["lambda1", "lambda2"]
for environment in self.deploy_environments:
arguments = self.base_arguments + ["deploy", ] + lambda_functions_to_deploy + [environment, ]
deploy = Command(arguments=arguments)
deploy = Command(arguments=arguments, exit_at_finish=False)
self.assertEqual(deploy.args.lambdafunctions, lambda_functions_to_deploy)
self.assertEqual(deploy.args.environment, environment)

Expand All @@ -84,7 +83,7 @@ def test_deploy(self, deploy_run_mock):
@patch.object(Build, "run")
def test_build(self, build_run_mock):
arguments = self.base_arguments + ["build", ]
build = Command(arguments=arguments)
build = Command(arguments=arguments, exit_at_finish=False)
self.assertEqual(build_run_mock.call_count, 1)
self.assert_base_conf(build)

Expand Down

0 comments on commit 6b3675f

Please sign in to comment.