Skip to content

Commit

Permalink
Fix CheckFilename test on Windows and Py2
Browse files Browse the repository at this point in the history
On Windows and Python 2, the full exception message from IOError
in CheckFilename will contain the filepath formatted as a unicode
string. Since the filepath is already added in the RuntimeError
message, use the strerror attribute to only display the error.
  • Loading branch information
micbou committed Feb 29, 2016
1 parent 1b0a8ea commit f981370
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/ycm/tests/vimsupport_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ def CheckFilename_test():
calling( vimsupport.CheckFilename ).with_args( 'nonexistent_file' ),
raises( RuntimeError,
"filename 'nonexistent_file' cannot be opened. "
"\[Errno 2\] No such file or directory: 'nonexistent_file'" )
"No such file or directory." )
)

assert_that( vimsupport.CheckFilename( __file__ ), none() )
Expand Down
3 changes: 2 additions & 1 deletion python/ycm/vimsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ def CheckFilename( filename ):
raise RuntimeError( "'{0}' is not a valid filename".format( filename ) )
except IOError as error:
raise RuntimeError(
"filename '{0}' cannot be opened. {1}".format( filename, error ) )
"filename '{0}' cannot be opened. {1}.".format( filename,
error.strerror ) )


def BufferIsVisibleForFilename( filename ):
Expand Down

0 comments on commit f981370

Please sign in to comment.