示例#1
0
    def test_execute_non_exec_commands_with_autocompletion(self):
        behavedplugin1 = dummyplugin.BehavedPlugin('behavedplugin1')
        behavedplugin2 = dummyplugin.BehavedPlugin('behavedplugin2')

        cmd = sysadmintoolkit.cmdprompt.CmdPrompt(self.nulllogger,
                                                  mode='testcase',
                                                  is_interactive=False)
        cmd.add_plugin(behavedplugin1)
        cmd.add_plugin(behavedplugin2)

        cmd.preloop()

        try:
            sys.stdout = self.devnull

            self.assertEqual(cmd.onecmd('non ex co'), 411)
            self.assertEqual(behavedplugin1.last_state, 'init')
            self.assertEqual(behavedplugin2.last_state, 'init')

            # Test a registered label with no executable commands
            self.assertEqual(cmd.onecmd('uniq'), 410)
            self.assertEqual(behavedplugin1.last_state, 'init')
            self.assertEqual(behavedplugin2.last_state, 'init')

            self.assertEqual(cmd.onecmd('th i j a he labe'), 410)
            self.assertEqual(behavedplugin1.last_state, 'init')
            self.assertEqual(behavedplugin2.last_state, 'init')
        finally:
            sys.stdout = self.original_stdout
示例#2
0
    def test_execute_static_commands_with_autocompletion(self):
        behavedplugin1 = dummyplugin.BehavedPlugin('behavedplugin1')
        behavedplugin2 = dummyplugin.BehavedPlugin('behavedplugin2')

        cmd = sysadmintoolkit.cmdprompt.CmdPrompt(self.nulllogger,
                                                  mode='testcase',
                                                  is_interactive=False)
        cmd.add_plugin(behavedplugin1)
        cmd.add_plugin(behavedplugin2)

        cmd.preloop()

        try:
            sys.stdout = self.devnull
            self.assertEqual(behavedplugin1.last_state, 'init')
            self.assertEqual(behavedplugin2.last_state, 'init')

            self.assertEqual(cmd.onecmd('uniq behavedplugin1 c'), 12345)
            self.assertEqual(behavedplugin1.last_state,
                             'plugin behavedplugin1 behaved function 1')
            self.assertEqual(cmd.onecmd('reset'), 0)

            self.assertEqual(
                cmd.onecmd(
                    '    uniq      behavedplugin1     command     w       spaces    '
                ), 12345)
            self.assertEqual(behavedplugin1.last_state,
                             'plugin behavedplugin1 behaved function 1')
            self.assertEqual(cmd.onecmd('reset'), 0)

            self.assertEqual(cmd.onecmd('co c'), 403)
            self.assertEqual(behavedplugin1.last_state, 'init')
            self.assertEqual(behavedplugin2.last_state, 'init')

            self.assertEqual(cmd.onecmd('uni command'), 404)
            self.assertEqual(behavedplugin1.last_state, 'init')
            self.assertEqual(behavedplugin2.last_state, 'init')

            self.assertEqual(cmd.onecmd('n conflict command'), 12345)
            self.assertEqual(behavedplugin1.last_state,
                             'plugin behavedplugin1 behaved function 1')
            self.assertEqual(behavedplugin2.last_state,
                             'plugin behavedplugin2 behaved function 1')
            self.assertEqual(cmd.onecmd('reset'), 0)
        finally:
            sys.stdout = self.original_stdout
示例#3
0
    def test_command_analysis(self):
        behavedplugin1 = dummyplugin.BehavedPlugin('behavedplugin1')

        cmd = sysadmintoolkit.cmdprompt.CmdPrompt(self.nulllogger,
                                                  mode='testcase',
                                                  is_interactive=False)
        cmd.add_plugin(behavedplugin1)

        cmd.preloop()

        self.assertTrue('exec_commands' in sysadmintoolkit.userinput.UserInput(
            'unique behavedplugin1 command', cmd).status)
        self.assertTrue(
            'exec_commands_with_pipe' in sysadmintoolkit.userinput.UserInput(
                'unique behavedplugin1 command | some shell command',
                cmd).status)
        self.assertTrue(
            'some shell command' in sysadmintoolkit.userinput.UserInput(
                'unique behavedplugin1 command | some shell command',
                cmd).rest_of_line)