summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2013-03-16 13:37:18 -0700
committerDoug Hellmann <doug.hellmann@dreamhost.com>2013-03-16 13:37:18 -0700
commitc56d60512c0504c68124f50a6d0617bf7004c715 (patch)
tree6bbab5c78ce4618712aff5dad016f847c4f42da0
parentc3baaff098e3e43323fd77ccef7c4814f9de2cf5 (diff)
downloadcliff-c56d60512c0504c68124f50a6d0617bf7004c715.tar.gz
add style checks to tests
Change-Id: I34990c619e66df21148f28bc6d6d743332a4fa16 Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
-rw-r--r--tests/test_app.py33
-rw-r--r--tests/test_commandmanager.py6
-rw-r--r--tests/test_help.py2
-rw-r--r--tests/test_lister.py25
-rw-r--r--tox.ini2
5 files changed, 37 insertions, 31 deletions
diff --git a/tests/test_app.py b/tests/test_app.py
index 7ba1588..ce6bf62 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -20,7 +20,9 @@ def make_app():
# Register a command that fails
err_command = mock.Mock(name='err_command', spec=Command)
err_command_inst = mock.Mock(spec=Command)
- err_command_inst.run = mock.Mock(side_effect=RuntimeError('test exception'))
+ err_command_inst.run = mock.Mock(
+ side_effect=RuntimeError('test exception')
+ )
err_command.return_value = err_command_inst
cmd_mgr.add_command('error', err_command)
@@ -41,7 +43,9 @@ def test_no_args_triggers_interactive_mode():
def test_interactive_mode_cmdloop():
app, command = make_app()
- app.interactive_app_factory = mock.MagicMock(name='interactive_app_factory')
+ app.interactive_app_factory = mock.MagicMock(
+ name='interactive_app_factory'
+ )
app.run([])
app.interactive_app_factory.return_value.cmdloop.assert_called_once_with()
@@ -106,7 +110,7 @@ def test_error_handling_clean_up_raises_exception():
app.clean_up = mock.MagicMock(
name='clean_up',
side_effect=RuntimeError('within clean_up'),
- )
+ )
app.run(['error'])
app.clean_up.assert_called_once()
@@ -123,7 +127,7 @@ def test_error_handling_clean_up_raises_exception_debug():
app.clean_up = mock.MagicMock(
name='clean_up',
side_effect=RuntimeError('within clean_up'),
- )
+ )
try:
app.run(['--debug', 'error'])
except RuntimeError as err:
@@ -150,7 +154,7 @@ def test_normal_clean_up_raises_exception():
app.clean_up = mock.MagicMock(
name='clean_up',
side_effect=RuntimeError('within clean_up'),
- )
+ )
app.run(['mock'])
app.clean_up.assert_called_once()
@@ -164,13 +168,14 @@ def test_normal_clean_up_raises_exception_debug():
app.clean_up = mock.MagicMock(
name='clean_up',
side_effect=RuntimeError('within clean_up'),
- )
+ )
app.run(['--debug', 'mock'])
app.clean_up.assert_called_once()
call_args = app.clean_up.call_args_list[0]
assert call_args == mock.call(mock.ANY, 0, None)
+
def test_build_option_parser_conflicting_option_should_throw():
class MyApp(App):
def __init__(self):
@@ -182,12 +187,12 @@ def test_build_option_parser_conflicting_option_should_throw():
def build_option_parser(self, description, version):
parser = super(MyApp, self).build_option_parser(description,
- version)
+ version)
parser.add_argument(
'-h', '--help',
default=self, # tricky
help="show this help message and exit",
- )
+ )
# TODO: tests should really use unittest2.
try:
@@ -197,7 +202,8 @@ def test_build_option_parser_conflicting_option_should_throw():
else:
raise Exception('Exception was not thrown')
-def test_build_option_parser_conflicting_option_custom_arguments_should_not_throw():
+
+def test_option_parser_conflicting_option_custom_arguments_should_not_throw():
class MyApp(App):
def __init__(self):
super(MyApp, self).__init__(
@@ -208,13 +214,14 @@ def test_build_option_parser_conflicting_option_custom_arguments_should_not_thro
def build_option_parser(self, description, version):
argparse_kwargs = {'conflict_handler': 'resolve'}
- parser = super(MyApp, self).build_option_parser(description,
- version,
- argparse_kwargs=argparse_kwargs)
+ parser = super(MyApp, self).build_option_parser(
+ description,
+ version,
+ argparse_kwargs=argparse_kwargs)
parser.add_argument(
'-h', '--help',
default=self, # tricky
help="show this help message and exit",
- )
+ )
MyApp()
diff --git a/tests/test_commandmanager.py b/tests/test_commandmanager.py
index 8924405..9a50a5e 100644
--- a/tests/test_commandmanager.py
+++ b/tests/test_commandmanager.py
@@ -19,7 +19,7 @@ class TestCommandManager(CommandManager):
'one': TestCommand,
'two words': TestCommand,
'three word command': TestCommand,
- }
+ }
def test_lookup_and_find():
@@ -53,6 +53,7 @@ def test_lookup_with_remainder():
def test_find_invalid_command():
mgr = TestCommandManager('test')
+
def check_one(argv):
try:
mgr.find_command(argv)
@@ -88,7 +89,8 @@ def test_load_commands():
testcmd = mock.Mock(name='testcmd')
testcmd.name.replace.return_value = 'test'
mock_pkg_resources = mock.Mock(return_value=[testcmd])
- with mock.patch('pkg_resources.iter_entry_points', mock_pkg_resources) as iter_entry_points:
+ with mock.patch('pkg_resources.iter_entry_points',
+ mock_pkg_resources) as iter_entry_points:
mgr = CommandManager('test')
assert iter_entry_points.called_once_with('test')
names = [n for n, v in mgr]
diff --git a/tests/test_help.py b/tests/test_help.py
index 6d67356..bdf9d71 100644
--- a/tests/test_help.py
+++ b/tests/test_help.py
@@ -38,7 +38,7 @@ class TestCommandManager(CommandManager):
'one': TestCommand,
'two words': TestCommand,
'three word command': TestCommand,
- }
+ }
def test_show_help_for_command():
diff --git a/tests/test_lister.py b/tests/test_lister.py
index f71986d..c0452d5 100644
--- a/tests/test_lister.py
+++ b/tests/test_lister.py
@@ -1,8 +1,5 @@
#!/usr/bin/env python
-from cliff.command import Command
-from cliff.commandmanager import CommandManager
-from cliff.formatters.base import ListFormatter
from cliff.lister import Lister
import mock
@@ -16,19 +13,20 @@ class FauxFormatter(object):
def emit_list(self, columns, data, stdout, args):
self.args.append((columns, data))
+
class ExerciseLister(Lister):
- def load_formatter_plugins(self):
- self.formatters = {
- 'test': FauxFormatter(),
- }
- return
+ def load_formatter_plugins(self):
+ self.formatters = {
+ 'test': FauxFormatter(),
+ }
+ return
- def take_action(self, parsed_args):
- return (
- parsed_args.columns,
- [('a', 'A'), ('b', 'B')],
- )
+ def take_action(self, parsed_args):
+ return (
+ parsed_args.columns,
+ [('a', 'A'), ('b', 'B')],
+ )
# def run(self, parsed_args):
@@ -52,4 +50,3 @@ def test_formatter_args():
assert args[0] == list(parsed_args.columns)
data = list(args[1])
assert data == [['a', 'A'], ['b', 'B']]
-
diff --git a/tox.ini b/tox.ini
index 1604308..4da916c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -10,4 +10,4 @@ deps =
[testenv:style]
deps = flake8
-commands = flake8 cliff docs/source/conf.py
+commands = flake8 cliff docs/source/conf.py tests