summaryrefslogtreecommitdiff
path: root/cliff/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cliff/tests')
-rw-r--r--cliff/tests/__init__.py0
-rw-r--r--cliff/tests/test_app.py389
-rw-r--r--cliff/tests/test_command.py22
-rw-r--r--cliff/tests/test_commandmanager.py121
-rw-r--r--cliff/tests/test_complete.py130
-rw-r--r--cliff/tests/test_help.py116
-rw-r--r--cliff/tests/test_lister.py55
-rw-r--r--cliff/tests/test_show.py54
8 files changed, 0 insertions, 887 deletions
diff --git a/cliff/tests/__init__.py b/cliff/tests/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/cliff/tests/__init__.py
+++ /dev/null
diff --git a/cliff/tests/test_app.py b/cliff/tests/test_app.py
deleted file mode 100644
index e3bc12e..0000000
--- a/cliff/tests/test_app.py
+++ /dev/null
@@ -1,389 +0,0 @@
-# -*- encoding: utf-8 -*-
-from argparse import ArgumentError
-try:
- from StringIO import StringIO
-except ImportError:
- # Probably python 3, that test won't be run so ignore the error
- pass
-import sys
-
-import nose
-import mock
-
-from cliff.app import App
-from cliff.command import Command
-from cliff.commandmanager import CommandManager
-
-
-def make_app():
- cmd_mgr = CommandManager('cliff.tests')
-
- # Register a command that succeeds
- command = mock.MagicMock(spec=Command)
- command_inst = mock.MagicMock(spec=Command)
- command_inst.run.return_value = 0
- command.return_value = command_inst
- cmd_mgr.add_command('mock', command)
-
- # 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.return_value = err_command_inst
- cmd_mgr.add_command('error', err_command)
-
- app = App('testing interactive mode',
- '1',
- cmd_mgr,
- stderr=mock.Mock(), # suppress warning messages
- )
- return app, command
-
-
-def test_no_args_triggers_interactive_mode():
- app, command = make_app()
- app.interact = mock.MagicMock(name='inspect')
- app.run([])
- app.interact.assert_called_once_with()
-
-
-def test_interactive_mode_cmdloop():
- app, command = make_app()
- app.interactive_app_factory = mock.MagicMock(
- name='interactive_app_factory'
- )
- assert app.interpreter is None
- app.run([])
- assert app.interpreter is not None
- app.interactive_app_factory.return_value.cmdloop.assert_called_once_with()
-
-
-def test_initialize_app():
- app, command = make_app()
- app.initialize_app = mock.MagicMock(name='initialize_app')
- app.run(['mock'])
- app.initialize_app.assert_called_once_with(['mock'])
-
-
-def test_prepare_to_run_command():
- app, command = make_app()
- app.prepare_to_run_command = mock.MagicMock(name='prepare_to_run_command')
- app.run(['mock'])
- app.prepare_to_run_command.assert_called_once_with(command())
-
-
-def test_clean_up_success():
- app, command = make_app()
- app.clean_up = mock.MagicMock(name='clean_up')
- app.run(['mock'])
- app.clean_up.assert_called_once_with(command.return_value, 0, None)
-
-
-def test_clean_up_error():
- app, command = make_app()
-
- app.clean_up = mock.MagicMock(name='clean_up')
- app.run(['error'])
-
- app.clean_up.assert_called_once()
- call_args = app.clean_up.call_args_list[0]
- assert call_args == mock.call(mock.ANY, 1, mock.ANY)
- args, kwargs = call_args
- assert isinstance(args[2], RuntimeError)
- assert args[2].args == ('test exception',)
-
-
-def test_clean_up_error_debug():
- app, command = make_app()
-
- app.clean_up = mock.MagicMock(name='clean_up')
- try:
- app.run(['--debug', 'error'])
- except RuntimeError as err:
- assert app.clean_up.call_args_list[0][0][2] is err
- else:
- assert False, 'Should have had an exception'
-
- app.clean_up.assert_called_once()
- call_args = app.clean_up.call_args_list[0]
- assert call_args == mock.call(mock.ANY, 1, mock.ANY)
- args, kwargs = call_args
- assert isinstance(args[2], RuntimeError)
- assert args[2].args == ('test exception',)
-
-
-def test_error_handling_clean_up_raises_exception():
- app, command = make_app()
-
- app.clean_up = mock.MagicMock(
- name='clean_up',
- side_effect=RuntimeError('within clean_up'),
- )
- app.run(['error'])
-
- app.clean_up.assert_called_once()
- call_args = app.clean_up.call_args_list[0]
- assert call_args == mock.call(mock.ANY, 1, mock.ANY)
- args, kwargs = call_args
- assert isinstance(args[2], RuntimeError)
- assert args[2].args == ('test exception',)
-
-
-def test_error_handling_clean_up_raises_exception_debug():
- app, command = make_app()
-
- app.clean_up = mock.MagicMock(
- name='clean_up',
- side_effect=RuntimeError('within clean_up'),
- )
- try:
- app.run(['--debug', 'error'])
- except RuntimeError as err:
- if not hasattr(err, '__context__'):
- # The exception passed to clean_up is not the exception
- # caused *by* clean_up. This test is only valid in python
- # 2 because under v3 the original exception is re-raised
- # with the new one as a __context__ attribute.
- assert app.clean_up.call_args_list[0][0][2] is not err
- else:
- assert False, 'Should have had an exception'
-
- app.clean_up.assert_called_once()
- call_args = app.clean_up.call_args_list[0]
- assert call_args == mock.call(mock.ANY, 1, mock.ANY)
- args, kwargs = call_args
- assert isinstance(args[2], RuntimeError)
- assert args[2].args == ('test exception',)
-
-
-def test_normal_clean_up_raises_exception():
- app, command = make_app()
-
- app.clean_up = mock.MagicMock(
- name='clean_up',
- side_effect=RuntimeError('within clean_up'),
- )
- app.run(['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_normal_clean_up_raises_exception_debug():
- app, command = make_app()
-
- 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):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- def build_option_parser(self, description, version):
- parser = super(MyApp, self).build_option_parser(description,
- version)
- parser.add_argument(
- '-h', '--help',
- default=self, # tricky
- help="show this help message and exit",
- )
-
- # TODO: tests should really use unittest2.
- try:
- MyApp()
- except ArgumentError:
- pass
- else:
- raise Exception('Exception was not thrown')
-
-
-def test_option_parser_conflicting_option_custom_arguments_should_not_throw():
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- 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.add_argument(
- '-h', '--help',
- default=self, # tricky
- help="show this help message and exit",
- )
-
- MyApp()
-
-
-def test_output_encoding_default():
- # The encoding should come from getdefaultlocale() because
- # stdout has no encoding set.
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stdout = StringIO()
- getdefaultlocale = lambda: ('ignored', 'utf-8')
-
- with mock.patch('sys.stdout', stdout):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stdout.write(u_data)
- actual = stdout.getvalue()
- assert data == actual
-
-
-def test_output_encoding_cliff_default():
- # The encoding should come from cliff.App.DEFAULT_OUTPUT_ENCODING
- # because the other values are missing or None
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stdout = StringIO()
- getdefaultlocale = lambda: ('ignored', None)
-
- with mock.patch('sys.stdout', stdout):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stdout.write(u_data)
- actual = stdout.getvalue()
- assert data == actual
-
-
-def test_output_encoding_sys():
- # The encoding should come from sys.stdout because it is set
- # there.
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stdout = StringIO()
- stdout.encoding = 'utf-8'
- getdefaultlocale = lambda: ('ignored', 'utf-16')
-
- with mock.patch('sys.stdout', stdout):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stdout.write(u_data)
- actual = stdout.getvalue()
- assert data == actual
-
-
-def test_error_encoding_default():
- # The encoding should come from getdefaultlocale() because
- # stdout has no encoding set.
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stderr = StringIO()
- getdefaultlocale = lambda: ('ignored', 'utf-8')
-
- with mock.patch('sys.stderr', stderr):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stderr.write(u_data)
- actual = stderr.getvalue()
- assert data == actual
-
-
-def test_error_encoding_sys():
- # The encoding should come from sys.stdout (not sys.stderr)
- # because it is set there.
- if sys.version_info[:2] != (2, 6):
- raise nose.SkipTest('only needed for python 2.6')
- data = '\xc3\xa9'
- u_data = data.decode('utf-8')
-
- class MyApp(App):
- def __init__(self):
- super(MyApp, self).__init__(
- description='testing',
- version='0.1',
- command_manager=CommandManager('tests'),
- )
-
- stdout = StringIO()
- stdout.encoding = 'utf-8'
- stderr = StringIO()
- getdefaultlocale = lambda: ('ignored', 'utf-16')
-
- with mock.patch('sys.stdout', stdout):
- with mock.patch('sys.stderr', stderr):
- with mock.patch('locale.getdefaultlocale', getdefaultlocale):
- app = MyApp()
- app.stderr.write(u_data)
- actual = stderr.getvalue()
- assert data == actual
-
-
-def test_unknown_cmd():
- app, command = make_app()
- assert app.run(['hell']) == 2
-
-
-def test_unknown_cmd_debug():
- app, command = make_app()
- try:
- app.run(['--debug', 'hell']) == 2
- except ValueError as err:
- assert "['hell']" in ('%s' % err)
diff --git a/cliff/tests/test_command.py b/cliff/tests/test_command.py
deleted file mode 100644
index 39fde51..0000000
--- a/cliff/tests/test_command.py
+++ /dev/null
@@ -1,22 +0,0 @@
-
-from cliff.command import Command
-
-
-class TestCommand(Command):
- """Description of command.
- """
-
- def take_action(self, parsed_args):
- return
-
-
-def test_get_description():
- cmd = TestCommand(None, None)
- desc = cmd.get_description()
- assert desc == "Description of command.\n "
-
-
-def test_get_parser():
- cmd = TestCommand(None, None)
- parser = cmd.get_parser('NAME')
- assert parser.prog == 'NAME'
diff --git a/cliff/tests/test_commandmanager.py b/cliff/tests/test_commandmanager.py
deleted file mode 100644
index 9a50a5e..0000000
--- a/cliff/tests/test_commandmanager.py
+++ /dev/null
@@ -1,121 +0,0 @@
-
-import mock
-
-from cliff.commandmanager import CommandManager
-
-
-class TestCommand(object):
- @classmethod
- def load(cls):
- return cls
-
- def __init__(self):
- return
-
-
-class TestCommandManager(CommandManager):
- def _load_commands(self):
- self.commands = {
- 'one': TestCommand,
- 'two words': TestCommand,
- 'three word command': TestCommand,
- }
-
-
-def test_lookup_and_find():
- def check(mgr, argv):
- cmd, name, remaining = mgr.find_command(argv)
- assert cmd
- assert name == ' '.join(argv)
- assert not remaining
- mgr = TestCommandManager('test')
- for expected in [['one'],
- ['two', 'words'],
- ['three', 'word', 'command'],
- ]:
- yield check, mgr, expected
- return
-
-
-def test_lookup_with_remainder():
- def check(mgr, argv):
- cmd, name, remaining = mgr.find_command(argv)
- assert cmd
- assert remaining == ['--opt']
- mgr = TestCommandManager('test')
- for expected in [['one', '--opt'],
- ['two', 'words', '--opt'],
- ['three', 'word', 'command', '--opt'],
- ]:
- yield check, mgr, expected
- return
-
-
-def test_find_invalid_command():
- mgr = TestCommandManager('test')
-
- def check_one(argv):
- try:
- mgr.find_command(argv)
- except ValueError as err:
- assert '-b' in ('%s' % err)
- else:
- assert False, 'expected a failure'
- for argv in [['a', '-b'],
- ['-b'],
- ]:
- yield check_one, argv
-
-
-def test_find_unknown_command():
- mgr = TestCommandManager('test')
- try:
- mgr.find_command(['a', 'b'])
- except ValueError as err:
- assert "['a', 'b']" in ('%s' % err)
- else:
- assert False, 'expected a failure'
-
-
-def test_add_command():
- mgr = TestCommandManager('test')
- mock_cmd = mock.Mock()
- mgr.add_command('mock', mock_cmd)
- found_cmd, name, args = mgr.find_command(['mock'])
- assert found_cmd is mock_cmd
-
-
-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:
- mgr = CommandManager('test')
- assert iter_entry_points.called_once_with('test')
- names = [n for n, v in mgr]
- assert names == ['test']
-
-
-def test_load_commands_keep_underscores():
- testcmd = mock.Mock()
- testcmd.name = 'test_cmd'
- mock_pkg_resources = mock.Mock(return_value=[testcmd])
- with mock.patch('pkg_resources.iter_entry_points',
- mock_pkg_resources) as iter_entry_points:
- mgr = CommandManager('test', convert_underscores=False)
- assert iter_entry_points.called_once_with('test')
- names = [n for n, v in mgr]
- assert names == ['test_cmd']
-
-
-def test_load_commands_replace_underscores():
- testcmd = mock.Mock()
- testcmd.name = 'test_cmd'
- mock_pkg_resources = mock.Mock(return_value=[testcmd])
- with mock.patch('pkg_resources.iter_entry_points',
- mock_pkg_resources) as iter_entry_points:
- mgr = CommandManager('test', convert_underscores=True)
- assert iter_entry_points.called_once_with('test')
- names = [n for n, v in mgr]
- assert names == ['test cmd']
diff --git a/cliff/tests/test_complete.py b/cliff/tests/test_complete.py
deleted file mode 100644
index b5a6bbf..0000000
--- a/cliff/tests/test_complete.py
+++ /dev/null
@@ -1,130 +0,0 @@
-"""Bash completion tests
-"""
-
-import mock
-
-from cliff.app import App
-from cliff.commandmanager import CommandManager
-from cliff import complete
-
-
-def test_complete_dictionary():
- sot = complete.CompleteDictionary()
- sot.add_command("image delete".split(),
- [mock.Mock(option_strings=["1"])])
- sot.add_command("image list".split(),
- [mock.Mock(option_strings=["2"])])
- sot.add_command("image create".split(),
- [mock.Mock(option_strings=["3"])])
- sot.add_command("volume type create".split(),
- [mock.Mock(option_strings=["4"])])
- sot.add_command("volume type delete".split(),
- [mock.Mock(option_strings=["5"])])
- assert "image volume" == sot.get_commands()
- result = sot.get_data()
- assert "image" == result[0][0]
- assert "create delete list" == result[0][1]
- assert "image_create" == result[1][0]
- assert "3" == result[1][1]
- assert "image_delete" == result[2][0]
- assert "1" == result[2][1]
- assert "image_list" == result[3][0]
- assert "2" == result[3][1]
-
-
-class FakeStdout:
- def __init__(self):
- self.content = []
-
- def write(self, text):
- self.content.append(text)
-
- def make_string(self):
- result = ''
- for line in self.content:
- result = result + line
- return result
-
-
-def given_cmdo_data():
- cmdo = "image server"
- data = [("image", "create"),
- ("image_create", "--eolus"),
- ("server", "meta ssh"),
- ("server_meta_delete", "--wilson"),
- ("server_ssh", "--sunlight")]
- return cmdo, data
-
-
-def then_data(content):
- assert " cmds='image server'\n" in content
- assert " cmds_image='create'\n" in content
- assert " cmds_image_create='--eolus'\n" in content
- assert " cmds_server='meta ssh'\n" in content
- assert " cmds_server_meta_delete='--wilson'\n" in content
- assert " cmds_server_ssh='--sunlight'\n" in content
-
-
-def test_complete_no_code():
- output = FakeStdout()
- sot = complete.CompleteNoCode("doesNotMatter", output)
- sot.write(*given_cmdo_data())
- then_data(output.content)
-
-
-def test_complete_bash():
- output = FakeStdout()
- sot = complete.CompleteBash("openstack", output)
- sot.write(*given_cmdo_data())
- then_data(output.content)
- assert "_openstack()\n" in output.content[0]
- assert "complete -F _openstack openstack\n" in output.content[-1]
-
-
-def test_complete_command_parser():
- sot = complete.CompleteCommand(mock.Mock(), mock.Mock())
- parser = sot.get_parser('nothing')
- assert "nothing" == parser.prog
- assert "print bash completion command\n " == parser.description
-
-
-def given_complete_command():
- cmd_mgr = CommandManager('cliff.tests')
- app = App('testing', '1', cmd_mgr, stdout=FakeStdout())
- sot = complete.CompleteCommand(app, mock.Mock())
- cmd_mgr.add_command('complete', complete.CompleteCommand)
- return sot, app, cmd_mgr
-
-
-def then_actions_equal(actions):
- optstr = ' '.join(opt for action in actions
- for opt in action.option_strings)
- assert '-h --help --name --shell' == optstr
-
-
-def test_complete_command_get_actions():
- sot, app, cmd_mgr = given_complete_command()
- app.interactive_mode = False
- actions = sot.get_actions(["complete"])
- then_actions_equal(actions)
-
-
-def test_complete_command_get_actions_interactive():
- sot, app, cmd_mgr = given_complete_command()
- app.interactive_mode = True
- actions = sot.get_actions(["complete"])
- then_actions_equal(actions)
-
-
-def test_complete_command_take_action():
- sot, app, cmd_mgr = given_complete_command()
- parsed_args = mock.Mock()
- parsed_args.name = "test_take"
- parsed_args.shell = "bash"
- content = app.stdout.content
- assert 0 == sot.take_action(parsed_args)
- assert "_test_take()\n" in content[0]
- assert "complete -F _test_take test_take\n" in content[-1]
- assert " cmds='complete help'\n" in content
- assert " cmds_complete='-h --help --name --shell'\n" in content
- assert " cmds_help='-h --help'\n" in content
diff --git a/cliff/tests/test_help.py b/cliff/tests/test_help.py
deleted file mode 100644
index bdf9d71..0000000
--- a/cliff/tests/test_help.py
+++ /dev/null
@@ -1,116 +0,0 @@
-try:
- from StringIO import StringIO
-except:
- from io import StringIO
-
-import mock
-
-from cliff.app import App
-from cliff.command import Command
-from cliff.commandmanager import CommandManager
-from cliff.help import HelpCommand
-
-
-class TestParser(object):
-
- def print_help(self, stdout):
- stdout.write('TestParser')
-
-
-class TestCommand(Command):
-
- @classmethod
- def load(cls):
- return cls
-
- def get_parser(self, ignore):
- # Make it look like this class is the parser
- # so parse_args() is called.
- return TestParser()
-
- def take_action(self, args):
- return
-
-
-class TestCommandManager(CommandManager):
- def _load_commands(self):
- self.commands = {
- 'one': TestCommand,
- 'two words': TestCommand,
- 'three word command': TestCommand,
- }
-
-
-def test_show_help_for_command():
- # FIXME(dhellmann): Are commands tied too closely to the app? Or
- # do commands know too much about apps by using them to get to the
- # command manager?
- stdout = StringIO()
- app = App('testing', '1', TestCommandManager('cliff.test'), stdout=stdout)
- app.NAME = 'test'
- help_cmd = HelpCommand(app, mock.Mock())
- parser = help_cmd.get_parser('test')
- parsed_args = parser.parse_args(['one'])
- try:
- help_cmd.run(parsed_args)
- except SystemExit:
- pass
- assert stdout.getvalue() == 'TestParser'
-
-
-def test_list_matching_commands():
- # FIXME(dhellmann): Are commands tied too closely to the app? Or
- # do commands know too much about apps by using them to get to the
- # command manager?
- stdout = StringIO()
- app = App('testing', '1', TestCommandManager('cliff.test'), stdout=stdout)
- app.NAME = 'test'
- help_cmd = HelpCommand(app, mock.Mock())
- parser = help_cmd.get_parser('test')
- parsed_args = parser.parse_args(['t'])
- try:
- help_cmd.run(parsed_args)
- except SystemExit:
- pass
- help_output = stdout.getvalue()
- assert 'Command "t" matches:' in help_output
- assert 'two' in help_output
- assert 'three' in help_output
-
-
-def test_list_matching_commands_no_match():
- # FIXME(dhellmann): Are commands tied too closely to the app? Or
- # do commands know too much about apps by using them to get to the
- # command manager?
- stdout = StringIO()
- app = App('testing', '1', TestCommandManager('cliff.test'), stdout=stdout)
- app.NAME = 'test'
- help_cmd = HelpCommand(app, mock.Mock())
- parser = help_cmd.get_parser('test')
- parsed_args = parser.parse_args(['z'])
- try:
- help_cmd.run(parsed_args)
- except SystemExit:
- pass
- except ValueError:
- pass
- else:
- assert False, 'Should have seen a ValueError'
-
-
-def test_show_help_for_help():
- # FIXME(dhellmann): Are commands tied too closely to the app? Or
- # do commands know too much about apps by using them to get to the
- # command manager?
- stdout = StringIO()
- app = App('testing', '1', TestCommandManager('cliff.test'), stdout=stdout)
- app.NAME = 'test'
- help_cmd = HelpCommand(app, mock.Mock())
- parser = help_cmd.get_parser('test')
- parsed_args = parser.parse_args([])
- try:
- help_cmd.run(parsed_args)
- except SystemExit:
- pass
- help_text = stdout.getvalue()
- assert 'usage: test help [-h]' in help_text
diff --git a/cliff/tests/test_lister.py b/cliff/tests/test_lister.py
deleted file mode 100644
index 7d1876f..0000000
--- a/cliff/tests/test_lister.py
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/env python
-
-import weakref
-
-from cliff.lister import Lister
-
-import mock
-
-
-class FauxFormatter(object):
-
- def __init__(self):
- self.args = []
- self.obj = weakref.proxy(self)
-
- def emit_list(self, columns, data, stdout, args):
- self.args.append((columns, data))
-
-
-class ExerciseLister(Lister):
-
- def _load_formatter_plugins(self):
- return {
- 'test': FauxFormatter(),
- }
- return
-
- def take_action(self, parsed_args):
- return (
- parsed_args.columns,
- [('a', 'A'), ('b', 'B')],
- )
-
-
-# def run(self, parsed_args):
-# self.formatter = self.formatters[parsed_args.formatter]
-# column_names, data = self.take_action(parsed_args)
-# self.produce_output(parsed_args, column_names, data)
-# return 0
-
-def test_formatter_args():
- app = mock.Mock()
- test_lister = ExerciseLister(app, [])
-
- parsed_args = mock.Mock()
- parsed_args.columns = ('Col1', 'Col2')
- parsed_args.formatter = 'test'
-
- test_lister.run(parsed_args)
- f = test_lister.formatters['test']
- assert len(f.args) == 1
- args = f.args[0]
- assert args[0] == list(parsed_args.columns)
- data = list(args[1])
- assert data == [['a', 'A'], ['b', 'B']]
diff --git a/cliff/tests/test_show.py b/cliff/tests/test_show.py
deleted file mode 100644
index 41df5e1..0000000
--- a/cliff/tests/test_show.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env python
-
-from cliff.show import ShowOne
-
-import mock
-
-
-class FauxFormatter(object):
-
- def __init__(self):
- self.args = []
-
- def emit_list(self, columns, data, stdout, args):
- self.args.append((columns, data))
-
-
-class ExerciseShowOne(ShowOne):
-
- 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 test_formatter_args():
-# app = mock.Mock()
-# test_lister = ExerciseLister(app, [])
-
-# parsed_args = mock.Mock()
-# parsed_args.columns = ('Col1', 'Col2')
-# parsed_args.formatter = 'test'
-
-# test_lister.run(parsed_args)
-# f = test_lister.formatters['test']
-# assert len(f.args) == 1
-# args = f.args[0]
-# assert args[0] == list(parsed_args.columns)
-# data = list(args[1])
-# assert data == [['a', 'A'], ['b', 'B']]
-
-def test_dict2columns():
- app = mock.Mock()
- test_show = ExerciseShowOne(app, [])
- d = {'a': 'A', 'b': 'B', 'c': 'C'}
- expected = [('a', 'b', 'c'), ('A', 'B', 'C')]
- actual = list(test_show.dict2columns(d))
- assert expected == actual