def test_exclude_filter(self): """Test that the exclude filter works as expectd.""" handler = TestCaseHandler(number_events=0) manager = WatchManager(handler) self.addCleanup(manager.stop) # add a watch that will always exclude all actions manager.add_watch( self.basedir, self.mask, exclude_filter=lambda x: True) # execution the actions file_name = os.path.join(self.basedir, 'test_file_create') open(file_name, 'w').close() # give some time for the system to get the events self.assertEqual(0, len(handler.processed_events))
def test_add_watch_twice(self): """Adding a watch twice succeeds when the watch is running.""" self.patch(Watch, "start_watching", lambda self: None) self.patch(Watch, "started", lambda self: True) manager = WatchManager(None) self.addCleanup(manager.stop) path = '/Users/username/path' mask = 'fake bit mask' d1 = manager.add_watch(path, mask) d2 = manager.add_watch(path, mask) self.assertTrue(d1.result, "Should not be called yet.") self.assertTrue(d2, "Should not be called yet.")
def test_add_watch_twice(self): """Check the deferred returned by a second add_watch.""" self.patch(Watch, "start_watching", lambda self: None) self.patch(Watch, "started", lambda self: True) manager = WatchManager(None) self.addCleanup(manager.stop) path = '/Users/username/path' mask = 'fake bit mask' d1 = manager.add_watch(path, mask) d2 = manager.add_watch(path, mask) self.assertTrue(d1.result, "Should not be called yet.") self.assertTrue(d2, "Should not be called yet.")
def test_add_watch_twice(self): """Adding a watch twice succeeds when the watch is running.""" self.patch(Watch, "start_watching", lambda self: self.started) manager = WatchManager(None) # no need to stop watching because start_watching is fake path = u'\\\\?\\C:\\test' # a valid windows path mask = 'fake bit mask' d1 = manager.add_watch(path, mask) d2 = manager.add_watch(path, mask) self.assertFalse(d1.called, "Should not be called yet.") self.assertFalse(d2.called, "Should not be called yet.") manager._wdm.values()[0].started.callback(True) self.assertTrue(d1.called, "Should already be called.") self.assertTrue(d2.called, "Should already be called.")