Beispiel #1
0
 def test_diverse_single_char_entries_in_iskeyword_are_found(self):
     vim_mock = VimMockFactory.get_mock(
         iskeyword='@,48-57,_,#,:,$%!,192-255')
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         actual_result = (
             localcomplete.get_additional_keyword_chars_from_vim())
     self.assertEqual(actual_result, '@_#:')
    def _helper_isolate_buffer_matches(self,
            buffers_contents,
            keyword_base,
            encoding='utf-8',
            keyword_chars='',
            min_len_all_buffer=0,
            want_ignorecase=False):

        case_mock_retval = re.IGNORECASE if want_ignorecase else 0

        chars_mock = mock.Mock(spec_set=[], return_value=keyword_chars)
        case_mock = mock.Mock(spec_set=[], return_value=case_mock_retval)
        buffers_mock = mock.Mock(spec_set=[], return_value=buffers_contents)
        transmit_result_mock = mock.Mock(spec_set=[], return_value=[])
        infercase_mock = mock.Mock(
                side_effect=lambda keyword, matches : matches)

        vim_mock = VimMockFactory.get_mock(
                min_len_all_buffer=min_len_all_buffer,
                encoding=encoding,
                keyword_base=keyword_base)

        with mock.patch.multiple(__name__ + '.localcomplete',
                get_additional_keyword_chars=chars_mock,
                get_casematch_flag=case_mock,
                generate_all_buffer_lines=buffers_mock,
                apply_infercase_to_matches_cond=infercase_mock,
                transmit_all_buffer_result_to_vim=transmit_result_mock,
                vim=vim_mock):
            yield transmit_result_mock
 def test_current_line_is_line_number(self):
     """
     Obtaining the current line from Vim returns the line number and not the
     index.
     """
     vim_mock = VimMockFactory.get_mock(current_line_index=3)
     self.assertEqual(vim_mock.eval("line('.')"), '4')
 def test_last_line_is_line_number(self):
     """
     Obtaining the last line from Vim returns the line number and not the
     index.
     """
     vim_mock = VimMockFactory.get_mock(buffer_content=["1", "2", "3"])
     self.assertEqual(vim_mock.eval("line('$')"), '3')
    def _helper_isolate_local_matches(self,
            haystack,
            keyword_base,
            encoding='utf-8',
            min_len_local=0,
            keyword_chars='',
            want_ignorecase=False):
        """
        Mock out all collaborator functions in the function under temporary
        test and the vim module.

        Yield produce_mock
        """
        case_mock_retval = re.IGNORECASE if want_ignorecase else 0

        chars_mock = mock.Mock(spec_set=[], return_value=keyword_chars)
        case_mock = mock.Mock(spec_set=[], return_value=case_mock_retval)
        haystack_mock = mock.Mock(spec_set=[], return_value=haystack)
        infercase_mock = mock.Mock(
                side_effect=lambda keyword, matches : matches)
        transmit_result_mock = mock.Mock(spec_set=[], return_value=[])

        vim_mock = VimMockFactory.get_mock(
                encoding=encoding,
                min_len_local=min_len_local,
                keyword_base=keyword_base)

        with mock.patch.multiple(__name__ + '.localcomplete',
                get_additional_keyword_chars=chars_mock,
                get_casematch_flag=case_mock,
                generate_haystack=haystack_mock,
                apply_infercase_to_matches_cond=infercase_mock,
                transmit_local_matches_result_to_vim=transmit_result_mock,
                vim=vim_mock):
            yield transmit_result_mock
Beispiel #6
0
    def _helper_isolate_buffer_matches(self,
                                       buffers_contents,
                                       keyword_base,
                                       encoding='utf-8',
                                       keyword_chars='',
                                       min_len_all_buffer=0,
                                       want_ignorecase=False):

        case_mock_retval = re.IGNORECASE if want_ignorecase else 0

        chars_mock = mock.Mock(spec_set=[], return_value=keyword_chars)
        case_mock = mock.Mock(spec_set=[], return_value=case_mock_retval)
        buffers_mock = mock.Mock(spec_set=[], return_value=buffers_contents)
        transmit_result_mock = mock.Mock(spec_set=[], return_value=[])
        infercase_mock = mock.Mock(
            side_effect=lambda keyword, matches: matches)

        vim_mock = VimMockFactory.get_mock(
            min_len_all_buffer=min_len_all_buffer,
            encoding=encoding,
            keyword_base=keyword_base)

        with mock.patch.multiple(
                __name__ + '.localcomplete',
                get_additional_keyword_chars=chars_mock,
                get_casematch_flag=case_mock,
                generate_all_buffer_lines=buffers_mock,
                apply_infercase_to_matches_cond=infercase_mock,
                transmit_all_buffer_result_to_vim=transmit_result_mock,
                vim=vim_mock):
            yield transmit_result_mock
 def test_current_line_is_line_number(self):
     """
     Obtaining the current line from Vim returns the line number and not the
     index.
     """
     vim_mock = VimMockFactory.get_mock(current_line_index=3)
     self.assertEqual(vim_mock.eval("line('.')"), '4')
 def test_diverse_single_char_entries_in_iskeyword_are_found(self):
     vim_mock = VimMockFactory.get_mock(
             iskeyword='@,48-57,_,#,:,$%!,192-255')
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         actual_result = (
                 localcomplete.get_additional_keyword_chars_from_vim())
     self.assertEqual(actual_result, '@_#:')
    def _helper_isolate_sut(self, buffer_content, current_line_index,
                            keyword_base, **further_vim_mock_args):

        vim_mock_defaults = dict(
            above_count=-1,
            below_count=-1,
            match_result_order=localcomplete.MATCH_ORDER_CENTERED,
            want_ignorecase_local=0,
            vim_ignorecase=1,
            vim_infercase=1,
            show_origin=0,
            origin_note_local='undertest',
            min_len_local=0,
            encoding='utf-8',
            iskeyword='',
            keyword_chars='',
        )

        vim_mock_args = dict(vim_mock_defaults)
        vim_mock_args.update(further_vim_mock_args)

        produce_mock = mock.Mock(spec_set=[], return_value=[])
        vim_mock = VimMockFactory.get_mock(
            buffer_content=buffer_content,
            current_line_index=current_line_index,
            keyword_base=keyword_base,
            **vim_mock_args)

        with mock.patch.multiple(__name__ + '.localcomplete',
                                 produce_result_value=produce_mock,
                                 vim=vim_mock):
            yield produce_mock
Beispiel #10
0
 def test_empty_input_list_creates_an_empty_output_list(self):
     vim_mock = VimMockFactory.get_mock(show_origin=1)
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         actual_result = localcomplete.produce_result_value([],
                                                            'testorigin')
     expected_result = []
     self.assertEqual(actual_result, expected_result)
    def _helper_isolate_sut(self, dict_content, keyword_base,
                            **further_vim_mock_args):
        """
        dict_content is one string that will be split at whitespace to
        replicate the format of a Vim dictionary.
        """

        # merge arguments
        vim_mock_defaults = dict(
            encoding='utf-8',
            show_origin=0,
            want_ignorecase_dict=0,
            vim_ignorecase=1,
            vim_infercase=1,
            origin_note_dict="undertest",
            dictionary="nonempty-valid",
        )

        vim_mock_args = dict(vim_mock_defaults)
        vim_mock_args.update(further_vim_mock_args)

        # prepare mocks
        translated_content = os.linesep.join(dict_content.split())
        codecs_open_mock = mock.mock_open(read_data=translated_content)

        vim_mock = VimMockFactory.get_mock(keyword_base=keyword_base,
                                           **vim_mock_args)

        # patch and yield
        with mock.patch(__name__ + '.localcomplete.codecs.open',
                        codecs_open_mock,
                        create=True):
            with mock.patch.multiple(__name__ + '.localcomplete',
                                     vim=vim_mock):
                yield vim_mock
 def test_empty_input_list_creates_an_empty_output_list(self):
     vim_mock = VimMockFactory.get_mock(show_origin=1)
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         actual_result = localcomplete.produce_result_value(
                 [], 'testorigin')
     expected_result = []
     self.assertEqual(actual_result, expected_result)
    def _helper_isolate_sut(self, buffer_content, current_line_index, keyword_base, **further_vim_mock_args):

        vim_mock_defaults = dict(
            above_count=-1,
            below_count=-1,
            match_result_order=localcomplete.MATCH_ORDER_CENTERED,
            want_ignorecase_local=0,
            vim_ignorecase=1,
            vim_infercase=1,
            show_origin=0,
            origin_note_local="undertest",
            min_len_local=0,
            encoding="utf-8",
            iskeyword="",
            keyword_chars="",
        )

        vim_mock_args = dict(vim_mock_defaults)
        vim_mock_args.update(further_vim_mock_args)

        produce_mock = mock.Mock(spec_set=[], return_value=[])
        vim_mock = VimMockFactory.get_mock(
            buffer_content=buffer_content,
            current_line_index=current_line_index,
            keyword_base=keyword_base,
            **vim_mock_args
        )

        with mock.patch.multiple(__name__ + ".localcomplete", produce_result_value=produce_mock, vim=vim_mock):
            yield produce_mock
    def _helper_isolate_sut(self, dict_content, keyword_base, **further_vim_mock_args):
        """
        dict_content is one string that will be split at whitespace to
        replicate the format of a Vim dictionary.
        """

        # merge arguments
        vim_mock_defaults = dict(
            encoding="utf-8",
            show_origin=0,
            want_ignorecase_dict=0,
            vim_ignorecase=1,
            vim_infercase=1,
            origin_note_dict="undertest",
            dictionary="nonempty-valid",
        )

        vim_mock_args = dict(vim_mock_defaults)
        vim_mock_args.update(further_vim_mock_args)

        # prepare mocks
        translated_content = os.linesep.join(dict_content.split())
        codecs_open_mock = mock.mock_open(read_data=translated_content)

        vim_mock = VimMockFactory.get_mock(keyword_base=keyword_base, **vim_mock_args)

        # patch and yield
        with mock.patch(__name__ + ".localcomplete.codecs.open", codecs_open_mock, create=True):
            with mock.patch.multiple(__name__ + ".localcomplete", vim=vim_mock):
                yield vim_mock
    def _helper_isolate_sut(self, line_up_to_cursor, encoding="utf-8", keyword_chars=""):

        line_mock = mock.Mock(spec_set=[], return_value=line_up_to_cursor)
        vim_mock = VimMockFactory.get_mock(keyword_chars=keyword_chars, encoding=encoding)

        with mock.patch.multiple(__name__ + ".localcomplete", findstart_get_line_up_to_cursor=line_mock, vim=vim_mock):
            yield vim_mock
Beispiel #16
0
    def _helper_isolate_local_matches(self,
                                      haystack,
                                      keyword_base,
                                      encoding='utf-8',
                                      min_len_local=0,
                                      keyword_chars='',
                                      want_ignorecase=False):
        """
        Mock out all collaborator functions in the function under temporary
        test and the vim module.

        Yield produce_mock
        """
        case_mock_retval = re.IGNORECASE if want_ignorecase else 0

        chars_mock = mock.Mock(spec_set=[], return_value=keyword_chars)
        case_mock = mock.Mock(spec_set=[], return_value=case_mock_retval)
        haystack_mock = mock.Mock(spec_set=[], return_value=haystack)
        infercase_mock = mock.Mock(
            side_effect=lambda keyword, matches: matches)
        transmit_result_mock = mock.Mock(spec_set=[], return_value=[])

        vim_mock = VimMockFactory.get_mock(encoding=encoding,
                                           min_len_local=min_len_local,
                                           keyword_base=keyword_base)

        with mock.patch.multiple(
                __name__ + '.localcomplete',
                get_additional_keyword_chars=chars_mock,
                get_casematch_flag=case_mock,
                generate_haystack=haystack_mock,
                apply_infercase_to_matches_cond=infercase_mock,
                transmit_local_matches_result_to_vim=transmit_result_mock,
                vim=vim_mock):
            yield transmit_result_mock
 def test_last_line_is_line_number(self):
     """
     Obtaining the last line from Vim returns the line number and not the
     index.
     """
     vim_mock = VimMockFactory.get_mock(buffer_content=["1", "2", "3"])
     self.assertEqual(vim_mock.eval("line('$')"), '3')
 def test_empty_result_without_single_char_entries_in_iskeyword(self):
     vim_mock = VimMockFactory.get_mock(
             iskeyword='48-57,192-255')
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         actual_result = (
                 localcomplete.get_additional_keyword_chars_from_vim())
     self.assertEqual(actual_result, '')
 def test_argument_is_passed_through(self):
     produce_mock = mock.Mock(side_effect=lambda matches, origin : matches)
     vim_mock = VimMockFactory.get_mock(origin_note_all_buffers="test")
     with mock.patch.multiple(__name__ + '.localcomplete',
             produce_result_value=produce_mock,
             vim=vim_mock):
         localcomplete.transmit_all_buffer_result_to_vim(1)
     vim_command_string = localcomplete.VIM_COMMAND_BUFFERCOMPLETE % 1
     vim_mock.command.assert_called_once_with(vim_command_string)
            def wrapped_test_method(self):
                byte_mock = mock.Mock(spec_set=[], return_value=byte_index)
                vim_mock = VimMockFactory.get_mock()

                with mock.patch.multiple(__name__ + '.localcomplete',
                        findstart_translate_to_byte_index=byte_mock,
                        findstart_get_starting_column_index=mock.Mock(),
                        vim=vim_mock):
                    f(self, vim_mock, byte_index)
Beispiel #21
0
    def _helper_isolate_column_translator(self, line_start, encoding='utf-8'):

        line_mock = mock.Mock(spec_set=[], return_value=line_start)
        vim_mock = VimMockFactory.get_mock(encoding=encoding)

        with mock.patch.multiple(__name__ + '.localcomplete',
                                 findstart_get_line_up_to_cursor=line_mock,
                                 vim=vim_mock):
            yield
Beispiel #22
0
 def test_argument_is_passed_through(self):
     produce_mock = mock.Mock(side_effect=lambda matches, origin: matches)
     vim_mock = VimMockFactory.get_mock(origin_note_all_buffers="test")
     with mock.patch.multiple(__name__ + '.localcomplete',
                              produce_result_value=produce_mock,
                              vim=vim_mock):
         localcomplete.transmit_all_buffer_result_to_vim(1)
     vim_command_string = localcomplete.VIM_COMMAND_BUFFERCOMPLETE % 1
     vim_mock.command.assert_called_once_with(vim_command_string)
Beispiel #23
0
    def _helper_execute_casematch_flag_test(self, want_ignorecase_local,
                                            want_ignorecase_dict,
                                            casematch_config, result_flag):

        vim_mock = VimMockFactory.get_mock(
            want_ignorecase_local=want_ignorecase_local,
            want_ignorecase_dict=want_ignorecase_dict)
        with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
            obtained_flag = localcomplete.get_casematch_flag(casematch_config)
        self.assertEqual(obtained_flag, result_flag)
Beispiel #24
0
            def wrapped_test_method(self):
                byte_mock = mock.Mock(spec_set=[], return_value=byte_index)
                vim_mock = VimMockFactory.get_mock()

                with mock.patch.multiple(
                        __name__ + '.localcomplete',
                        findstart_translate_to_byte_index=byte_mock,
                        findstart_get_starting_column_index=mock.Mock(),
                        vim=vim_mock):
                    f(self, vim_mock, byte_index)
Beispiel #25
0
    def _helper_mock_current(self, full_line, cursor_index):
        # The cursor_index can be after the full_line
        if cursor_index > len(full_line):
            raise LocalCompleteTestsError("cursor index not within line")
        vim_mock = VimMockFactory.get_mock(encoding="utf-8")
        vim_mock.current.line = full_line
        vim_mock.current.window.cursor = (0, cursor_index)

        with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
            yield
    def _helper_mock_current(self, full_line, cursor_index):
        # The cursor_index can be after the full_line
        if cursor_index > len(full_line):
            raise LocalCompleteTestsError("cursor index not within line")
        vim_mock = VimMockFactory.get_mock(encoding="utf-8")
        vim_mock.current.line = full_line
        vim_mock.current.window.cursor = (0, cursor_index)

        with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
            yield
Beispiel #27
0
    def _helper_execute_infercase_test(self, vim_ignorecase, vim_infercase,
                                       keyword_base, matches_input,
                                       matches_result):

        vim_mock = VimMockFactory.get_mock(vim_ignorecase=vim_ignorecase,
                                           vim_infercase=vim_infercase)
        with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
            actual_result = list(
                localcomplete.apply_infercase_to_matches_cond(
                    keyword_base=keyword_base, found_matches=matches_input))
        self.assertEqual(actual_result, matches_result)
    def _helper_isolate_column_translator(self,
            line_start,
            encoding='utf-8'):

        line_mock = mock.Mock(spec_set=[], return_value=line_start)
        vim_mock = VimMockFactory.get_mock(encoding=encoding)

        with mock.patch.multiple(__name__ + '.localcomplete',
                findstart_get_line_up_to_cursor=line_mock,
                vim=vim_mock):
            yield
    def _helper_execute_casematch_flag_test(self,
            want_ignorecase_local,
            want_ignorecase_dict,
            casematch_config,
            result_flag):

        vim_mock = VimMockFactory.get_mock(
                want_ignorecase_local=want_ignorecase_local,
                want_ignorecase_dict=want_ignorecase_dict)
        with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
            obtained_flag = localcomplete.get_casematch_flag(casematch_config)
        self.assertEqual(obtained_flag, result_flag)
 def test_nonempty_without_origin_note(self):
     vim_mock = VimMockFactory.get_mock(show_origin=0)
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         actual_result = localcomplete.produce_result_value(
                 ['1', '2', '3'],
                 'testorigin')
     expected_result = [
              {'word': '1'},
              {'word': '2'},
              {'word': '3'},
              ]
     self.assertEqual(actual_result, expected_result)
    def _helper_isolate_test_subject(self,
            expected_result,
            keyword_chars,
            keyword_chars_from_vim=''):

        vim_mock = VimMockFactory.get_mock(keyword_chars=keyword_chars)
        from_vim_mock = mock.Mock(return_value=keyword_chars_from_vim)

        with mock.patch.multiple(__name__ + '.localcomplete',
                get_additional_keyword_chars_from_vim=from_vim_mock,
                vim=vim_mock):
            actual_result = localcomplete.get_additional_keyword_chars()
        self.assertEqual(actual_result, expected_result)
    def _helper_isolate_sut(self,
                            line_up_to_cursor,
                            encoding='utf-8',
                            keyword_chars=''):

        line_mock = mock.Mock(spec_set=[], return_value=line_up_to_cursor)
        vim_mock = VimMockFactory.get_mock(keyword_chars=keyword_chars,
                                           encoding=encoding)

        with mock.patch.multiple(__name__ + '.localcomplete',
                                 findstart_get_line_up_to_cursor=line_mock,
                                 vim=vim_mock):
            yield vim_mock
Beispiel #33
0
    def _helper_isolate_test_subject(self,
                                     expected_result,
                                     keyword_chars,
                                     keyword_chars_from_vim=''):

        vim_mock = VimMockFactory.get_mock(keyword_chars=keyword_chars)
        from_vim_mock = mock.Mock(return_value=keyword_chars_from_vim)

        with mock.patch.multiple(
                __name__ + '.localcomplete',
                get_additional_keyword_chars_from_vim=from_vim_mock,
                vim=vim_mock):
            actual_result = localcomplete.get_additional_keyword_chars()
        self.assertEqual(actual_result, expected_result)
    def _helper_execute_infercase_test(self,
            vim_ignorecase,
            vim_infercase,
            keyword_base,
            matches_input,
            matches_result):

        vim_mock = VimMockFactory.get_mock(
                vim_ignorecase=vim_ignorecase,
                vim_infercase=vim_infercase)
        with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
            actual_result = list(localcomplete.apply_infercase_to_matches_cond(
                    keyword_base=keyword_base,
                    found_matches=matches_input))
        self.assertEqual(actual_result, matches_result)
Beispiel #35
0
    def _helper_isolate_column_getter(self,
                                      line_start,
                                      encoding='utf-8',
                                      keyword_chars=''):

        chars_mock = mock.Mock(spec_set=[], return_value=keyword_chars)
        line_mock = mock.Mock(spec_set=[], return_value=line_start)

        vim_mock = VimMockFactory.get_mock(encoding=encoding)

        with mock.patch.multiple(__name__ + '.localcomplete',
                                 get_additional_keyword_chars=chars_mock,
                                 findstart_get_line_up_to_cursor=line_mock,
                                 vim=vim_mock):
            yield
    def _helper_isolate_column_getter(self,
            line_start,
            encoding='utf-8',
            keyword_chars=''):

        chars_mock = mock.Mock(spec_set=[], return_value=keyword_chars)
        line_mock = mock.Mock(spec_set=[], return_value=line_start)

        vim_mock = VimMockFactory.get_mock(encoding=encoding)

        with mock.patch.multiple(__name__ + '.localcomplete',
                get_additional_keyword_chars=chars_mock,
                findstart_get_line_up_to_cursor=line_mock,
                vim=vim_mock):
            yield
Beispiel #37
0
 def test_nonempty_without_origin_note(self):
     vim_mock = VimMockFactory.get_mock(show_origin=0)
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         actual_result = localcomplete.produce_result_value(['1', '2', '3'],
                                                            'testorigin')
     expected_result = [
         {
             'word': '1'
         },
         {
             'word': '2'
         },
         {
             'word': '3'
         },
     ]
     self.assertEqual(actual_result, expected_result)
    def _helper_isolate_sut(self,
            match_result_order,
            expected_result_lines,
            buffer_content=("0", "1", "2", "3", "4", "5", "6"),
            above_range=range(1, 3),
            current_index=3,
            below_range=range(4, 6)):

        vim_mock = VimMockFactory.get_mock(
                match_result_order=match_result_order,
                buffer_content=buffer_content)
        buffer_range_mock = mock.Mock(
                return_value=(above_range, current_index, below_range))

        with mock.patch.multiple(__name__ + '.localcomplete',
                get_buffer_ranges=buffer_range_mock,
                vim=vim_mock):
            actual_result = list(localcomplete.generate_haystack())
        self.assertEqual(actual_result, expected_result_lines)
Beispiel #39
0
    def _helper_isolate_sut(self,
                            match_result_order,
                            expected_result_lines,
                            buffer_content=("0", "1", "2", "3", "4", "5", "6"),
                            above_range=range(1, 3),
                            current_index=3,
                            below_range=range(4, 6)):

        vim_mock = VimMockFactory.get_mock(
            match_result_order=match_result_order,
            buffer_content=buffer_content)
        buffer_range_mock = mock.Mock(return_value=(above_range, current_index,
                                                    below_range))

        with mock.patch.multiple(__name__ + '.localcomplete',
                                 get_buffer_ranges=buffer_range_mock,
                                 vim=vim_mock):
            actual_result = list(localcomplete.generate_haystack())
        self.assertEqual(actual_result, expected_result_lines)
    def _helper_isolate_sut(self, buffers_content, current_buffer_index,
                            keyword_base, **further_vim_mock_args):

        vim_mock_defaults = dict(
            want_ignorecase_local=0,
            vim_ignorecase=1,
            vim_infercase=1,
            show_origin=0,
            origin_note_all_buffers="undertest",
            encoding='utf-8',
            min_len_all_buffer=0,
            iskeyword='',
            keyword_chars='',
        )

        # setup a vim mock with explicit and default arguments

        vim_mock_args = dict(vim_mock_defaults)
        vim_mock_args.update(further_vim_mock_args)

        vim_mock = VimMockFactory.get_mock(keyword_base=keyword_base,
                                           **vim_mock_args)

        # Mock out vim_mock.buffers

        class VimBufferFake(list):
            number = None

        mock_buffers = []
        for index, content in enumerate(buffers_content):
            new_buffer = VimBufferFake(content)
            new_buffer.number = index
            mock_buffers.append(new_buffer)
            if index == current_buffer_index:
                vim_mock.current = mock.Mock()
                vim_mock.current.buffer = new_buffer
        vim_mock.buffers = mock_buffers

        # patch and yield

        with mock.patch.multiple(__name__ + '.localcomplete', vim=vim_mock):
            yield vim_mock
    def test_transmits_found_matches_to_vim(self):
        result_list = ['results']
        haystack = ['contents']
        min_len = 3

        vim_mock = VimMockFactory.get_mock(min_len_local=min_len)
        find_mock = mock.Mock(spec_set=[], return_value=result_list)
        haystack_mock = mock.Mock(spec_set=[], return_value=haystack)
        transmit_result_mock = mock.Mock(spec_set=[], return_value=[])

        with mock.patch.multiple(
                __name__ + '.localcomplete',
                find_matches_in_lines=find_mock,
                generate_haystack=haystack_mock,
                transmit_local_matches_result_to_vim=transmit_result_mock,
                vim=vim_mock):
            localcomplete.complete_local_matches()

        find_mock.assert_called_once_with(haystack, min_len)
        transmit_result_mock.assert_called_once_with(result_list)
    def test_transmits_found_matches_to_vim(self):
        result_list = ['results']
        buffers_contents = ['contents']
        min_len = 3

        vim_mock = VimMockFactory.get_mock(min_len_all_buffer=min_len)
        find_mock = mock.Mock(spec_set=[], return_value=result_list)
        buffers_mock = mock.Mock(spec_set=[], return_value=buffers_contents)
        transmit_result_mock = mock.Mock(spec_set=[], return_value=[])

        with mock.patch.multiple(
                __name__ + '.localcomplete',
                find_matches_in_lines=find_mock,
                generate_all_buffer_lines=buffers_mock,
                transmit_all_buffer_result_to_vim=transmit_result_mock,
                vim=vim_mock):
            localcomplete.complete_all_buffer_matches()

        find_mock.assert_called_once_with(buffers_contents, min_len)
        transmit_result_mock.assert_called_once_with(result_list)
    def _helper_isolate_sut(self, buffers_content, current_buffer_index, keyword_base, **further_vim_mock_args):

        vim_mock_defaults = dict(
            want_ignorecase_local=0,
            vim_ignorecase=1,
            vim_infercase=1,
            show_origin=0,
            origin_note_all_buffers="undertest",
            encoding="utf-8",
            min_len_all_buffer=0,
            iskeyword="",
            keyword_chars="",
        )

        # setup a vim mock with explicit and default arguments

        vim_mock_args = dict(vim_mock_defaults)
        vim_mock_args.update(further_vim_mock_args)

        vim_mock = VimMockFactory.get_mock(keyword_base=keyword_base, **vim_mock_args)

        # Mock out vim_mock.buffers

        class VimBufferFake(list):
            number = None

        mock_buffers = []
        for index, content in enumerate(buffers_content):
            new_buffer = VimBufferFake(content)
            new_buffer.number = index
            mock_buffers.append(new_buffer)
            if index == current_buffer_index:
                vim_mock.current = mock.Mock()
                vim_mock.current.buffer = new_buffer
        vim_mock.buffers = mock_buffers

        # patch and yield

        with mock.patch.multiple(__name__ + ".localcomplete", vim=vim_mock):
            yield vim_mock
    def _helper_isolate_find_matches(self,
                                     keyword_base,
                                     encoding='utf-8',
                                     keyword_chars='',
                                     want_ignorecase=False):

        case_mock_retval = re.IGNORECASE if want_ignorecase else 0

        chars_mock = mock.Mock(spec_set=[], return_value=keyword_chars)
        case_mock = mock.Mock(spec_set=[], return_value=case_mock_retval)
        infercase_mock = mock.Mock(
            side_effect=lambda keyword, matches: matches)

        vim_mock = VimMockFactory.get_mock(encoding=encoding,
                                           keyword_base=keyword_base)

        with mock.patch.multiple(
                __name__ + '.localcomplete',
                get_additional_keyword_chars=chars_mock,
                get_casematch_flag=case_mock,
                apply_infercase_to_matches_cond=infercase_mock,
                vim=vim_mock):
            yield
    def _helper_isolate_dict_matches(self,
            dict_content,
            keyword_base,
            encoding='utf-8',
            origin_note_dict='undertest',
            want_ignorecase=False,
            is_dictionary_configured=True,
            is_dictionary_path_valid=True):

        translated_content = os.linesep.join(dict_content.split())

        dictionary_path = 'test:nonempty' if is_dictionary_configured else ''

        content_mock = mock.Mock(spec_set=[], return_value=translated_content)

        case_mock_retval = re.IGNORECASE if want_ignorecase else 0
        case_mock = mock.Mock(spec_set=[], return_value=case_mock_retval)
        infercase_mock = mock.Mock(
                side_effect=lambda keyword, matches : matches)

        if not is_dictionary_path_valid:
            content_mock.side_effect = IOError("undertest")
        produce_mock = mock.Mock(spec_set=[], return_value=[])
        vim_mock = VimMockFactory.get_mock(
                origin_note_dict=origin_note_dict,
                encoding=encoding,
                keyword_base=keyword_base,
                dictionary=dictionary_path)

        with mock.patch.multiple(__name__ + '.localcomplete',
                read_file_contents=content_mock,
                produce_result_value=produce_mock,
                get_casematch_flag=case_mock,
                apply_infercase_to_matches_cond=infercase_mock,
                vim=vim_mock):

            yield (vim_mock, produce_mock)
Beispiel #46
0
    def _helper_isolate_dict_matches(self,
                                     dict_content,
                                     keyword_base,
                                     encoding='utf-8',
                                     origin_note_dict='undertest',
                                     want_ignorecase=False,
                                     is_dictionary_configured=True,
                                     is_dictionary_path_valid=True):

        translated_content = os.linesep.join(dict_content.split())

        dictionary_path = 'test:nonempty' if is_dictionary_configured else ''

        content_mock = mock.Mock(spec_set=[], return_value=translated_content)

        case_mock_retval = re.IGNORECASE if want_ignorecase else 0
        case_mock = mock.Mock(spec_set=[], return_value=case_mock_retval)
        infercase_mock = mock.Mock(
            side_effect=lambda keyword, matches: matches)

        if not is_dictionary_path_valid:
            content_mock.side_effect = IOError("undertest")
        produce_mock = mock.Mock(spec_set=[], return_value=[])
        vim_mock = VimMockFactory.get_mock(origin_note_dict=origin_note_dict,
                                           encoding=encoding,
                                           keyword_base=keyword_base,
                                           dictionary=dictionary_path)

        with mock.patch.multiple(
                __name__ + '.localcomplete',
                read_file_contents=content_mock,
                produce_result_value=produce_mock,
                get_casematch_flag=case_mock,
                apply_infercase_to_matches_cond=infercase_mock,
                vim=vim_mock):

            yield (vim_mock, produce_mock)
Beispiel #47
0
 def test_empty_result_without_single_char_entries_in_iskeyword(self):
     vim_mock = VimMockFactory.get_mock(iskeyword='48-57,192-255')
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         actual_result = (
             localcomplete.get_additional_keyword_chars_from_vim())
     self.assertEqual(actual_result, '')
 def test_requesting_an_invalid_mock_config_key_raises_an_exception(self):
     with self.assertRaises(LCTestUtilsError):
         VimMockFactory.get_mock(__INVALID__KEY__='')
 def test_evaluating_unregistered_vim_expressions_raises_an_exception(self):
     vim_mock = VimMockFactory.get_mock()
     with self.assertRaises(LCTestUtilsError):
         vim_mock.eval("&invalid")
 def test_vim_eval_always_returns_strings(self):
     vim_mock = VimMockFactory.get_mock(above_count=3)
     self.assertEqual(vim_mock.eval("localcomplete#getLinesAboveCount()"),
                      "3")
 def test_buffer_unset(self):
     """Raise an exception when no buffer content has been specified"""
     vim_mock = VimMockFactory.get_mock()
     with self.assertRaises(LCTestUtilsError):
         return vim_mock.current.buffer
 def test_buffer_full(self):
     """Don't raise an exception if there is something in the buffer"""
     vim_mock = VimMockFactory.get_mock(buffer_content=["zero", "one"])
     self.assertEqual(vim_mock.current.buffer[1], "one")
 def test_requesting_an_invalid_mock_config_key_raises_an_exception(self):
     with self.assertRaises(LCTestUtilsError):
         VimMockFactory.get_mock(__INVALID__KEY__='')
 def test_evaluating_unregistered_vim_expressions_raises_an_exception(self):
     vim_mock = VimMockFactory.get_mock()
     with self.assertRaises(LCTestUtilsError):
         vim_mock.eval("&invalid")
 def test_vim_eval_always_returns_strings(self):
     vim_mock = VimMockFactory.get_mock(above_count=3)
     self.assertEqual(
             vim_mock.eval("localcomplete#getLinesAboveCount()"),
             "3")
Beispiel #56
0
 def _helper_index_test(self, expected_result, **mock_arguments):
     vim_mock = VimMockFactory.get_mock(**mock_arguments)
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         ar, c, br = localcomplete.get_buffer_ranges()
         actual_result = (list(ar), c, list(br))
     self.assertEqual(actual_result, expected_result)
 def test_buffer_full(self):
     """Don't raise an exception if there is something in the buffer"""
     vim_mock = VimMockFactory.get_mock(buffer_content=["zero", "one"])
     self.assertEqual(vim_mock.current.buffer[1], "one")
 def _helper_index_test(self, expected_result, **mock_arguments):
     vim_mock = VimMockFactory.get_mock(**mock_arguments)
     with mock.patch(__name__ + '.localcomplete.vim', vim_mock):
         ar, c, br = localcomplete.get_buffer_ranges()
         actual_result = (list(ar), c, list(br))
     self.assertEqual(actual_result, expected_result)