Auto merge of #2710 - micbou:buffer-unload-unicode-warnings, r=vheon

[READY] Fix unicode warning when unloading buffer on Python 2

When a buffer is unloaded, [we compare its name to the current buffer one in the `BuildRequestData` function](5b89d41832/python/ycm/client/base_request.py (L160)). This raises a unicode warning on Python 2 when the deleted buffer name contains non-ASCII characters because the deleted buffer name is a byte object while the current buffer name is a unicode one.

I updated the `BufferUnload` test to show the issue. I'll send the fix once the builds failed.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2710)
<!-- Reviewable:end -->
This commit is contained in:
zzbot 2017-07-08 08:51:33 -07:00 committed by GitHub
commit 1e38a2bfc5
2 changed files with 8 additions and 5 deletions

View File

@ -25,7 +25,8 @@ from __future__ import absolute_import
from builtins import * # noqa from builtins import * # noqa
from ycm.tests.test_utils import ( CurrentWorkingDirectory, ExtendedMock, from ycm.tests.test_utils import ( CurrentWorkingDirectory, ExtendedMock,
MockVimBuffers, MockVimModule, VimBuffer ) MockVimBuffers, MockVimModule, VimBuffer,
ToBytesOnPY2 )
MockVimModule() MockVimModule()
import contextlib import contextlib
@ -447,14 +448,14 @@ def EventNotification_BufferVisit_BuildRequestForCurrentAndUnsavedBuffers_test(
@YouCompleteMeInstance() @YouCompleteMeInstance()
def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test( def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
ycm ): ycm ):
current_buffer_file = os.path.realpath( 'current_buffer' ) current_buffer_file = os.path.realpath( 'current_βuffer' )
current_buffer = VimBuffer( name = current_buffer_file, current_buffer = VimBuffer( name = current_buffer_file,
number = 1, number = 1,
contents = [ 'current_buffer_contents' ], contents = [ 'current_buffer_contents' ],
filetype = 'some_filetype', filetype = 'some_filetype',
modified = True ) modified = True )
deleted_buffer_file = os.path.realpath( 'deleted_buffer' ) deleted_buffer_file = os.path.realpath( 'deleted_βuffer' )
deleted_buffer = VimBuffer( name = deleted_buffer_file, deleted_buffer = VimBuffer( name = deleted_buffer_file,
number = 2, number = 2,
contents = [ 'deleted_buffer_contents' ], contents = [ 'deleted_buffer_contents' ],
@ -464,7 +465,7 @@ def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
with patch( 'ycm.client.event_notification.EventNotification.' with patch( 'ycm.client.event_notification.EventNotification.'
'PostDataToHandlerAsync' ) as post_data_to_handler_async: 'PostDataToHandlerAsync' ) as post_data_to_handler_async:
with MockVimBuffers( [ current_buffer, deleted_buffer ], current_buffer ): with MockVimBuffers( [ current_buffer, deleted_buffer ], current_buffer ):
ycm.OnBufferUnload( deleted_buffer_file ) ycm.OnBufferUnload( ToBytesOnPY2( deleted_buffer_file ) )
assert_that( assert_that(
# Positional arguments passed to PostDataToHandlerAsync. # Positional arguments passed to PostDataToHandlerAsync.

View File

@ -374,7 +374,9 @@ class YouCompleteMe( object ):
def OnBufferUnload( self, deleted_buffer_file ): def OnBufferUnload( self, deleted_buffer_file ):
SendEventNotificationAsync( 'BufferUnload', filepath = deleted_buffer_file ) SendEventNotificationAsync(
'BufferUnload',
filepath = utils.ToUnicode( deleted_buffer_file ) )
def OnBufferVisit( self ): def OnBufferVisit( self ):