Merge pull request #1067 from ZyX-I/fix-1066

Add proper errno attribute to exception raised by uv watcher
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2014-09-07 23:30:40 +04:00
commit 9e686823a5
2 changed files with 7 additions and 1 deletions

View File

@ -7,6 +7,7 @@ from collections import defaultdict
from threading import RLock from threading import RLock
from functools import partial from functools import partial
from threading import Thread from threading import Thread
from errno import ENOENT
from powerline.lib.path import realpath from powerline.lib.path import realpath
@ -76,7 +77,7 @@ class UvWatcher(object):
except pyuv.error.FSEventError as e: except pyuv.error.FSEventError as e:
code = e.args[0] code = e.args[0]
if code == pyuv.errno.UV_ENOENT: if code == pyuv.errno.UV_ENOENT:
raise OSError('No such file or directory: ' + path) raise OSError(ENOENT, 'No such file or directory: ' + path)
else: else:
raise raise

View File

@ -6,6 +6,7 @@ import os
from time import sleep from time import sleep
from functools import partial from functools import partial
from errno import ENOENT
from powerline.lib.watcher import create_file_watcher, create_tree_watcher, INotifyError from powerline.lib.watcher import create_file_watcher, create_tree_watcher, INotifyError
from powerline.lib.watcher.uv import UvNotFound from powerline.lib.watcher.uv import UvNotFound
@ -168,6 +169,10 @@ class TestFilesystemWatchers(TestCase):
pass pass
ne = os.path.join(INOTIFY_DIR, 'notexists') ne = os.path.join(INOTIFY_DIR, 'notexists')
self.assertRaises(OSError, w, ne) self.assertRaises(OSError, w, ne)
try:
w(ne)
except OSError as e:
self.assertEqual(e.errno, ENOENT)
self.assertTrue(w(f1)) self.assertTrue(w(f1))
self.assertFalse(w.is_watching(ne)) self.assertFalse(w.is_watching(ne))
self.assertTrue(w.is_watching(f1)) self.assertTrue(w.is_watching(f1))