Ejemplo n.º 1
0
    def test_with_failing_command(self, executable_factory, readout):
        """ Handle the case where a command returns non-zero exit status """

        executable_factory('nd-my-command', '#!/bin/bash\nexit 1')
        with readout() as message:
            help.main(['nd'])
        assert 'my-command   <help not found>' in message
Ejemplo n.º 2
0
    def test_with_command_with_empty_help(self, executable_factory, readout):
        """ Handle the case where help returns empty string """

        executable_factory('nd-my-command', make_help_command(''))
        with readout() as message:
            help.main(['nd'])
        assert 'my-command   <help not found>' in message
Ejemplo n.º 3
0
    def test_with_namespace(self, executable_factory, readout):
        """ Running help on a namespace shows help for each command in the namespace """

        executable_factory('nd-my-namespace~my-command', make_help_command('my help message'))
        with readout() as message:
            help.main(['nd', 'my-namespace'])
        assert 'my-namespace my-command   my help message' in message
Ejemplo n.º 4
0
    def test_parses_nonargparse_generated_help(self, executable_factory, readout):
        """ Print help for all commands parses descriptions from generic commands' --help """

        executable_factory('nd-my-command', make_help_command('my help message'))
        with readout() as message:
            help.main(['nd'])
        assert 'my-command   my help message' in message
Ejemplo n.º 5
0
    def test_calls_commands_with_help_flag(self, executable_factory, readout, run_as_child):
        """ Print help for all commands parses descriptions from generic commands' --help """

        executable_factory('nd-my-command', '#!/bin/echo')
        with readout() as message:
            run_as_child(help.main, ['nd', 'my-command'])
        assert '--help' in message
Ejemplo n.º 6
0
    def test_slow_help_is_skipped(self, executable_factory, readout):
        """ Skip printing help info for a slow help """

        executable_factory('nd-my-command', '#!/usr/bin/env bash\nsleep 10\necho my help message')
        with readout() as message:
            with mock.patch.object(help, 'HELP_TIMEOUT', 0):
                help.main(['nd'])
        assert 'my-command   <help not found>' in message
Ejemplo n.º 7
0
    def test_with_no_args(self, executable_factory, readout):
        """ Running help without a command or namespace prints help of commands on path """

        executable_factory('nd-my-namespace~my-command', make_help_command('my help message'))
        with readout() as message:
            help.main(['nd'])
        assert 'Showing help for all' in message
        assert 'my-namespace my-command   my help message' in message
Ejemplo n.º 8
0
    def test_excludes_completion_commands(self, executable_factory, readout):
        """ Doesn't report autocompletion scripts """

        executable_factory('nd-my-command')
        executable_factory('nd-my-command.completion')
        executable_factory('nd-my-command.completion.sh')
        with readout() as message:
            help.main(['nd'])
        assert 'my-command' in message
        assert 'my-command.completion' not in message
Ejemplo n.º 9
0
    def test_excluded_command(self, executable_factory, monkeypatch, readout):
        """ Help returns an error when applied to excluded commands. """

        monkeypatch.setenv('BUCKLE_HELP_OPTS_ND', '-X nd-my-excluded-command')
        executable_factory('nd-my-included-command')
        executable_factory('nd-my-excluded-command', '#!/bin/echo\nFAIL')
        with readout() as message:
            help.main(['nd'])
        assert 'my-included-command' in message
        assert 'my-excluded-command' not in message
Ejemplo n.º 10
0
    def test_parses_argparse_generated_help(self, executable_factory, readout):
        """ Print help for all commands parses argparse's description from its generated help """

        executable_factory('nd-my-command', make_help_command("""\
            usage: ...

            my help message"""), dedent=False)
        with readout() as message:
            help.main(['nd'])
        assert 'my-command   my help message' in message
Ejemplo n.º 11
0
    def test_dot_commands_run_only_once(self, executable_factory, monkeypatch,
                                        readout):
        """ Handle the dot command appearing multiple times on path by running it only once """

        tmp_path = executable_factory(
            'nd-.my-check', '#!/bin/bash\necho my dot command output')
        monkeypatch.setenv('PATH', tmp_path, prepend=':')
        with readout() as output:
            self.command.run_dot_commands([], '', [])
        assert output == 'my dot command output\n'
Ejemplo n.º 12
0
    def test_child_dot_commands_do_not_run(self, executable_factory, readout):
        """ Dot commands in child namespaces do not get called """

        executable_factory('nd-.my-check',
                           '#!/bin/bash\necho parent dot command output')
        executable_factory('nd-my-namespace~.my-check',
                           '#!/bin/bash\necho child dot command output')
        with readout() as output:
            self.command.run_dot_commands([], '', [])
        assert output == 'parent dot command output\n'
Ejemplo n.º 13
0
    def test_dot_commands_run_alphabetically(self, executable_factory,
                                             readout):
        """ All dot commands for the given namespace should run in alphabetical order """

        executable_factory('nd-.my-checkC',
                           '#!/bin/bash\necho dot command C output')
        executable_factory('nd-.my-checkA',
                           '#!/bin/bash\necho dot command A output')
        executable_factory('nd-.my-checkB',
                           '#!/bin/bash\necho dot command B output')
        with readout() as output:
            self.command.run_dot_commands([], '', [])
        assert output == 'dot command A output\ndot command B output\ndot command C output\n'
Ejemplo n.º 14
0
 def test_runs_with_passed_command_and_args(self, executable_factory,
                                            readout):
     """ Dot Commands are called with the called command and its args """
     executable_factory(
         'nd-my-namespace~.my-check', """\
         #!/bin/bash
         echo $1
         echo $2
         echo $3""")
     with readout() as output:
         self.command.run_dot_commands(['my-namespace'], 'my-command',
                                       ['arg1', 'arg2'])
     assert output == 'my-namespace my-command\narg1\narg2\n'
Ejemplo n.º 15
0
    def test_dot_commands_disabled_option(self, disable_clock_check,
                                          disable_update, executable_factory,
                                          readout, run_as_child):
        """ Ignore dot commands before the given command if option is set in toolbelt """

        executable_factory('nd-.my-check',
                           '#!/bin/bash\necho my dot command output')
        executable_factory('nd-my-command',
                           '#!/bin/bash\necho my command output')
        with readout() as output:
            run_as_child(base.main,
                         ['buckle', '--skip-dot-commands', 'my-command'])
        assert output == 'my command output\n'
Ejemplo n.º 16
0
    def test_without_columns_envvar(self, executable_factory, monkeypatch, readout):
        """ Running help on a namespace shows help for each command in the namespace """

        monkeypatch.delenv('COLUMNS')

        with mock.patch.object(os, 'popen') as popen:
            popen.return_value.read.return_value = '30 40'

            executable_factory('nd-my-command',
                               make_help_command('my really really really long help message'))
            with readout() as message:
                help.main(['nd'])
            assert '...' in message

            popen.assert_called_with('stty size', 'r')
Ejemplo n.º 17
0
    def test_dot_commands_run_in_order_of_namespace(self, executable_factory,
                                                    readout):
        """ Dot commands in parent namespaces run before its children """

        executable_factory('nd-.my-check',
                           '#!/bin/bash\necho parent dot command output')
        executable_factory('nd-my-namespace~.my-check',
                           '#!/bin/bash\necho child dot command output')
        executable_factory('nd-my-namespace~subnamespace~.my-check',
                           '#!/bin/bash\necho grandchild dot command output')
        with readout() as output:
            self.command.run_dot_commands(['my-namespace', 'subnamespace'], '',
                                          [])
        assert output == (
            'parent dot command output\nchild dot command output\n'
            'grandchild dot command output\n')
Ejemplo n.º 18
0
    def test_output_is_sorted_alphabetically_by_namespace(self, executable_factory, readout):
        """ Help returns an error when applied to excluded commands. """

        executable_factory('nd-my-a-command')
        executable_factory('nd-my-z-command')
        executable_factory('nd-my-a-namespace~my-command')
        executable_factory('nd-my-namespace~my-subnamespace~my-command')
        executable_factory('nd-my-z-namespace~my-command')

        with readout() as output:
            help.main(['nd'])
        message = str(output)
        assert (message.index('my-a-command') <
                message.index('my-z-command') <
                message.index('my-a-namespace my-command') <
                message.index('my-namespace my-subnamespace my-command') <
                message.index('my-z-namespace my-command'))