Skip to content

Commit

Permalink
Add parameterized tests for command aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelAquilina committed May 8, 2018
1 parent 14a37f3 commit 9bcf34a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion s4/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def main(arguments):

try:
command = None
if args.command == 'version':
if args.command in ('version', 'v'):
print(VERSION)
return
elif args.command in ('sync', 's'):
Expand Down
30 changes: 18 additions & 12 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def test_debug_loglevel(self, basicConfig):
assert basicConfig.call_args[1]['format'].startswith('%(levelname)s:%(module)s')
assert basicConfig.call_args[1]['level'] == 'DEBUG'

def test_version_command(self, capsys):
cli.main(['version'])
@pytest.mark.parametrize('command', ['version', 'v'])
def test_version_command(self, capsys, command):
cli.main([command])
out, err = capsys.readouterr()
assert out == '{}\n'.format(cli.VERSION)

Expand All @@ -36,32 +37,37 @@ def test_ls_command(self, LsCommand):
cli.main(['ls', 'foo'])
assert LsCommand.call_count == 1

@pytest.mark.parametrize('command', ['daemon', 'd'])
@mock.patch('s4.cli.DaemonCommand')
def test_daemon_command(self, DaemonCommand):
cli.main(['daemon'])
def test_daemon_command(self, DaemonCommand, command):
cli.main([command])
assert DaemonCommand.call_count == 1

@pytest.mark.parametrize('command', ['sync', 's'])
@mock.patch('s4.cli.SyncCommand')
def test_sync_command(self, SyncCommand):
cli.main(['sync', 'foo'])
def test_sync_command(self, SyncCommand, command):
cli.main([command, 'foo'])
assert SyncCommand.call_count == 1

@pytest.mark.parametrize('command', ['edit', 'e'])
@mock.patch('s4.cli.EditCommand')
def test_edit_command(self, EditCommand):
cli.main(['edit', 'foo'])
def test_edit_command(self, EditCommand, command):
cli.main([command, 'foo'])
assert EditCommand.call_count == 1

@pytest.mark.parametrize('command', ['targets', 't'])
@mock.patch('s4.cli.TargetsCommand')
def test_targets_command(self, TargetsCommand):
cli.main(['targets'])
def test_targets_command(self, TargetsCommand, command):
cli.main([command])
assert TargetsCommand.call_count == 1

@mock.patch('s4.cli.RmCommand')
def test_rm_command(self, RmCommand):
cli.main(['rm', 'foo'])
assert RmCommand.call_count == 1

@pytest.mark.parametrize('command', ['add', 'a'])
@mock.patch('s4.cli.AddCommand')
def test_add_command(self, AddCommand):
cli.main(['add'])
def test_add_command(self, AddCommand, command):
cli.main([command])
assert AddCommand.call_count == 1

0 comments on commit 9bcf34a

Please sign in to comment.