Переглянути джерело

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.
micbou 9 роки тому
батько
коміт
f981370965
2 змінених файлів з 3 додано та 2 видалено
  1. 1 1
      python/ycm/tests/vimsupport_test.py
  2. 2 1
      python/ycm/vimsupport.py

+ 1 - 1
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() )

+ 2 - 1
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 ):