From f9813709658cc45a08d6d5e94a762216afa65ed8 Mon Sep 17 00:00:00 2001 From: micbou Date: Mon, 29 Feb 2016 12:54:28 +0100 Subject: [PATCH] Fix CheckFilename test on Windows and Py2 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. --- python/ycm/tests/vimsupport_test.py | 2 +- python/ycm/vimsupport.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/python/ycm/tests/vimsupport_test.py b/python/ycm/tests/vimsupport_test.py index 120cb662..7e888e8a 100644 --- a/python/ycm/tests/vimsupport_test.py +++ b/python/ycm/tests/vimsupport_test.py @@ -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() ) diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index a3d8425a..28ab8e4b 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -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 ):