Skip to content

Commit

Permalink
Fix CLI tests to test exit when Python < 2.6
Browse files Browse the repository at this point in the history
This completes the coverage that was lost in recent changes.
  • Loading branch information
sirosen committed Aug 23, 2014
1 parent 91e0134 commit 749caf2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion salve/cli/__init__.py
Expand Up @@ -18,6 +18,6 @@ def main():
import sys

if sys.version_info < (2, 6):
sys.exit(1)
sys.exit('Python Version Too Old! SALVE Requires Python >= 2.6')

run()
8 changes: 4 additions & 4 deletions tests/end2end/cli/common.py
Expand Up @@ -2,14 +2,14 @@

import mock

import tests.utils.scratch
import salve.cli
from tests.utils import scratch
from salve import cli


class RunScratchContainer(tests.utils.scratch.ScratchContainer):
class RunScratchContainer(scratch.ScratchContainer):
def run_on_args(self, argv):
with mock.patch('sys.argv', argv):
return salve.cli.run()
return cli.main()

def run_on_manifest(self, manifest):
man_path = self.get_fullname(manifest)
Expand Down
21 changes: 15 additions & 6 deletions tests/unit/cli/run_test.py
Expand Up @@ -4,6 +4,7 @@
from nose.tools import istest

from salve import cli
from tests.utils.exceptions import ensure_except


@istest
Expand All @@ -15,13 +16,21 @@ def run_on_backup_subcommand():
"""
fake_argv = ['./salve.py', 'backup', '-f', 'a/b/c', '-r']

log = {'main': False}

def fake_main(args):
log['main'] = True
fake_main = mock.Mock()

with mock.patch('sys.argv', fake_argv):
with mock.patch('salve.cli.backup.main', fake_main):
cli.run()
cli.main()

assert fake_main.called

assert log['main']

@istest
def old_python_version_errors():
"""
Unit: Run On Python < 2.5 Exits
Verifies that running on arguments starting with "backup" correctly invokes
the backup main method.
"""
with mock.patch('sys.version_info', (2, 5)):
ensure_except(SystemExit, cli.main)

0 comments on commit 749caf2

Please sign in to comment.