예제 #1
0
 def test_kwarg_preserve_gaps(self):
     """The CLI should enable the user to choose preserve_gaps as a gap handling method."""
     test_args = ['2-3', '>', '4/5', '-pg']
     mock_expand_range.return_value = (2, 3)
     mock_expand_spot.return_value = (4, 5)
     
     move(self.test_set, test_args)
     
     mock_assert_msg(mock_move_files.assert_called_once_with, [(2, 3), (4, 5), KeywordArgTuple('preserve_gaps', True)], "The CLI fails to provide access to the gap-handling option strip_gaps.")
    def test_multiple_short_commands(self):
        """The method should be able to print the help text of multiple short commands with a short description each."""
        CMD1 = ('first command', 'a test command')
        CMD2 = ('second command', 'another test command')

        _print_elements(CMD1, CMD2)

        assertion_calls = [(mock_print.assert_any_call, [
            'first command', 'a test command',
            KeywordArgTuple(key='sep', value='\t\t\t')
        ]),
                           (mock_print.assert_called_with, [
                               'second command', 'another test command',
                               KeywordArgTuple(key='sep', value='\t\t\t')
                           ])]

        mock_assert_many_msg(
            assertion_calls,
            "The CLI help method fails to print multiple short commands at once."
        )
    def test_single_short_command(self):
        """The method should be able to print the help text of a single short command with a short description."""
        CMD = ('command', 'a test command')

        _print_elements(CMD)

        mock_assert_msg(
            mock_print.assert_called_once_with, [
                'command', 'a test command',
                KeywordArgTuple(key='sep', value='\t\t\t\t')
            ],
            "The CLI help method fails to print a command along with its description."
        )
예제 #4
0
    def test_kwarg_preserve_gaps(self):
        """The CLI should enable the user to choose preserve_gaps as a gap handling method."""
        test_args = ['2-3', '~', '4-5', '-pg']
        mock_expand_range.side_effect = lambda x: (2, 3) if x.startswith(
            '2') else (4, 5)

        switch(self.test_set, test_args)

        mock_assert_msg(
            mock_switch_file_ranges.assert_called_once_with,
            [(2, 3),
             (4, 5), KeywordArgTuple('preserve_gaps', True)],
            "The CLI fails to provide access to the gap-handling option strip_gaps."
        )
예제 #5
0
    def test_kwarg_strip_gaps(self):
        """The CLI should enable the user to choose strip_gaps as a gap handling method."""
        test_args = ['-', '2-3', '4-5', '-sg']
        mock_expand_range.side_effect = lambda x: (2, 3) if x.startswith(
            '2') else (4, 5)

        remove(self.test_set, test_args)

        mock_assert_msg(
            mock_remove_files.assert_called_once_with,
            [[2, 3, 4, 5], self.default_remove_set,
             KeywordArgTuple('strip_gaps', True)],
            "The CLI fails to provide access to the gap-handling option strip_gaps."
        )
    def test_long_cmd(self):
        """The method should put the description onto a new line if the command is too long."""
        CMD = ('insanely LONG COMMAND [--with MANY] OPTIONS',
               'command description')

        _print_elements(CMD)

        mock_assert_msg(
            mock_print.assert_called_once_with, [
                'insanely LONG COMMAND [--with MANY] OPTIONS',
                'command description',
                KeywordArgTuple(key='sep', value='\n\t\t\t\t')
            ],
            "The CLI help method fails to properly print a very long command.")
예제 #7
0
    def test_gap_handler_and_custom_set_specified(self, mock_expand_pattern):
        """The CLI should be able to handle an operation which asks both for a custom set to remove files into and a specific gap-handling strategy."""
        test_args = ["-", "-a", "custom*set", "1-3",
                     "-pg"]  # append files and preserve gaps
        mock_expand_range.return_value = (1, 3)

        mock_expand_pattern.return_value = ('custom', 'set')
        CLI.default_remove_set = self.default_remove_set

        custom_remove_set = FileSet(('custom', 'set'), [])
        CLI.file_set_cache = [custom_remove_set
                              ]  # set already exists (for convenience)

        remove(self.test_set, test_args)

        mock_assert_msg(
            mock_remove_files.assert_called_once_with,
            [[1, 2, 3], custom_remove_set,
             KeywordArgTuple('preserve_gaps', True)],
            "The CLI fails to correctly remove files into a custom set if a gap-handling strategy is specified"
        )
    def test_long_desc(self):
        """The method should be able to print the help text of a short command with a long description that requires appropriate word-wrap. Additional lines should be indented with two spaces."""
        CMD = (
            'my command',
            'This is a test command that serves no particular purpose in a production environment and in fact is not even implemented, yet it is quite useful for being used as a test dummy.'
        )

        _print_elements(CMD)

        expected_wrapped_desc = ''.join([
            "This is a test command that serves no particular", '\n\t\t\t\t',
            '  ', "purpose in a production environment and in", '\n\t\t\t\t',
            '  ', "fact is not even implemented, yet it is quite",
            '\n\t\t\t\t', '  ', "useful for being used as a test dummy."
        ])
        mock_assert_msg(
            mock_print.assert_called_once_with, [
                'my command', expected_wrapped_desc,
                KeywordArgTuple(key='sep', value='\t\t\t')
            ],
            "The CLI help method fails to properly format and print a command with a long description."
        )
def preserve_gaps(boolean):
    return KeywordArgTuple('preserve_gaps', boolean)
예제 #10
0
def strip_gaps(boolean):
    return KeywordArgTuple('strip_gaps', boolean)