def test_start_watching_fails_early_in_thread(self): """An early failure inside the thread should errback the deferred.""" test_path = self.mktemp("test_directory") self.patch(filesystem_notifications, "CreateFileW", self.random_error) watch = Watch(1, test_path, None) d = watch.start_watching() yield self.assertFailure(d, common_tests.FakeException)
def test_update_subdirs_delete_not_present(self): """Test when we delete and is not present.""" path = '/Users/username/path/to/not/dir' test_path = self.mktemp("test_directory") watch = Watch(1, test_path, None) watch._update_subdirs(path, REVERSE_MACOS_ACTIONS[IN_DELETE]) self.assertTrue(path not in watch._subdirs)
def test_update_subdirs_create_not_present(self): """Test when we update on a create event and not present.""" path = '/Users/username/path/to/not/dir' test_path = self.mktemp("test_directory") watch = Watch(1, test_path, None) watch._update_subdirs(path, REVERSE_MACOS_ACTIONS[IN_CREATE]) self.assertTrue(path in watch._subdirs)
def test_is_path_dir_missing_no_subdir(self): """Test when the path does not exist and is no a subdir.""" path = '/Users/username/path/to/not/dir' test_path = self.mktemp("test_directory") self.patch(os.path, 'exists', lambda path: False) watch = Watch(1, test_path, None) self.assertFalse(watch._path_is_dir(path))
def test_stop_watching_fired_when_watch_thread_finishes(self): """The deferred returned is fired when the watch thread finishes.""" test_path = self.mktemp("another_test_directory") watch = Watch(1, test_path, self.mask) yield watch.start_watching() self.assertNotEqual(watch.platform_watch._watch_handle, None) yield watch.stop_watching() self.assertEqual(watch.platform_watch._watch_handle, None)
def test_is_path_dir_present_no_dir(self): """Test when the path is present but not a dir.""" path = '/Users/username/path/to/not/dir' test_path = self.mktemp("test_directory") self.patch(os.path, 'exists', lambda path: True) self.patch(os.path, 'isdir', lambda path: False) watch = Watch(1, test_path, None) watch._subdirs.add(path) self.assertFalse(watch._path_is_dir(path))
def test_stop_multiple(self): """Watches should became watching=False and the observer stopped.""" second_path = self.parent_path + "second_path" second_watch = Watch(2, second_path, None) second_watch._watching = True self.manager._wdm[2] = second_watch self.manager.stop() self.assertFalse(second_watch.platform_watch.watching) self.assertEqual(second_watch._subdirs, set()) # Give time to the thread to be finished. self.manager.platform_manager.observer.join() self.assertFalse(self.manager.platform_manager.observer.is_alive())
def test_close_handle_is_called_on_error(self): """CloseHandle is called when there's an error in the watch thread.""" test_path = self.mktemp("test_directory") close_called = [] self.patch(filesystem_notifications, "CreateFileW", lambda *_: None) self.patch(filesystem_notifications, "CloseHandle", close_called.append) self.patch(filesystem_notifications, "ReadDirectoryChangesW", self.random_error) watch = Watch(1, test_path, self.mask) d = watch.start_watching() yield self.assertFailure(d, common_tests.FakeException) self.assertEqual(len(close_called), 1) yield watch.stop_watching()