Beispiel #1
0
 def test_execute_calls_run_command_if_argv_given(self):
     manager = ExecutionManager(argv=['vcs', 'show', '-h'])
     manager.run_command = mock.Mock()
     manager.execute()
     # we also check argv passed to the command
     manager.run_command.assert_called_once_with('show',
         ['vcs', 'show', '-h'])
Beispiel #2
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    from vcs.cli import ExecutionManager
    manager = ExecutionManager(argv)
    manager.execute()
    return 0
Beispiel #3
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    from vcs.cli import ExecutionManager
    manager = ExecutionManager(argv)
    manager.execute()
    return 0
Beispiel #4
0
 def test_get_command_class(self):
     manager = ExecutionManager()
     with mock.patch.object(vcs.cli, 'registry', {
         'foo': 'decimal.Decimal',
         'bar': 'socket.socket'}):
         from decimal import Decimal
         from socket import socket
         self.assertEqual(manager.get_command_class('foo'), Decimal)
         self.assertEqual(manager.get_command_class('bar'), socket)
Beispiel #5
0
    def test_get_commands(self):
        manager = ExecutionManager()
        with mock.patch.object(vcs.cli, 'registry', {
            'foo': 'vcs.cli.BaseCommand',
            'bar': 'vcs.cli.ExecutionManager'}):

            self.assertItemsEqual(manager.get_commands(), {
                'foo': BaseCommand,
                'bar': ExecutionManager,
            })
Beispiel #6
0
    def test_run_command(self):
        manager = ExecutionManager(stdout=io.StringIO(),
            stderr=io.StringIO())

        class Command(BaseCommand):

            def run_from_argv(self, argv):
                self.stdout.write(u'foo')
                self.stderr.write(u'bar')

        with mock.patch.object(manager, 'get_command_class') as m:
            m.return_value = Command
            manager.run_command('cmd', manager.argv)
            self.assertEqual(manager.stdout.getvalue(), u'foo')
            self.assertEqual(manager.stderr.getvalue(), u'bar')
Beispiel #7
0
 def test_get_vcsrc(self):
     with nested(mock.patch('vcs.conf.settings.VCSRC_PATH', 'foobar'),
                 mock.patch('vcs.cli.create_module')) as (VP, m):
         # Use not-dummy manager here as we need to test get_vcsrc behavior
         m.return_value = mock.Mock()
         manager = ExecutionManager()
         self.assertEqual(manager.vimrc, m.return_value)
         m.assert_called_once_with('vcsrc', 'foobar')
Beispiel #8
0
 def test_show_help_writes_to_stdout(self):
     manager = ExecutionManager(stdout=io.StringIO(), stderr=io.StringIO())
     manager.show_help()
     self.assertGreater(len(manager.stdout.getvalue()), 0)
Beispiel #9
0
 def test_execute_calls_show_help_if_argv_not_given(self):
     manager = ExecutionManager(argv=['vcs'])
     manager.show_help = mock.Mock()
     manager.execute()
     manager.show_help.assert_called_once_with()