From b0786d5c4f419ddb07f9147e7c04deb56eb405a1 Mon Sep 17 00:00:00 2001 From: micbou Date: Tue, 10 May 2016 16:30:04 +0200 Subject: [PATCH] Fix LookupError exception when opening a file Open the file in binary mode in CheckFilename function. Use ReadFile helper in syntax_parse tests. --- python/ycm/tests/syntax_parse_test.py | 3 ++- python/ycm/vimsupport.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/python/ycm/tests/syntax_parse_test.py b/python/ycm/tests/syntax_parse_test.py index dc2e61ae..8fe5c79c 100644 --- a/python/ycm/tests/syntax_parse_test.py +++ b/python/ycm/tests/syntax_parse_test.py @@ -30,12 +30,13 @@ import os from nose.tools import eq_ from hamcrest import assert_that, has_items from ycm import syntax_parse +from ycmd.utils import ReadFile def ContentsOfTestFile( test_file ): dir_of_script = os.path.dirname( os.path.abspath( __file__ ) ) full_path_to_test_file = os.path.join( dir_of_script, 'testdata', test_file ) - return open( full_path_to_test_file ).read() + return ReadFile( full_path_to_test_file ) diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 115c0e9d..076dcbb4 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -851,7 +851,9 @@ def WriteToPreviewWindow( message ): def CheckFilename( filename ): """Check if filename is openable.""" try: - open( filename ).close() + # We don't want to check for encoding issues when trying to open the file + # so we open it in binary mode. + open( filename, mode = 'rb' ).close() except TypeError: raise RuntimeError( "'{0}' is not a valid filename".format( filename ) ) except IOError as error: