def test_recognize_event_patterns(self): events = [ inotify_simple.Event(wd=1, mask=inotify_simple.flags.MOVED_FROM, cookie=233, name='fromA'), inotify_simple.Event(wd=3, mask=inotify_simple.flags.MOVED_TO, cookie=233, name='toA'), inotify_simple.Event(wd=5, mask=inotify_simple.flags.MOVED_FROM, cookie=234, name='from'), inotify_simple.Event(wd=7, mask=inotify_simple.flags.MOVED_TO, cookie=235, name='to') ] move_pairs, all_events = self.watcher._recognize_event_patterns(events) self.assertEqual(4, len(all_events)) self.assertIn(233, move_pairs) self.assertNotIn(234, move_pairs) self.assertNotIn(235, move_pairs) (ev_a, flags_a), (ev_b, flags_b) = move_pairs[233] self.assertEqual([inotify_simple.flags.MOVED_FROM], flags_a) self.assertEqual('fromA', ev_a.name) self.assertEqual([inotify_simple.flags.MOVED_TO], flags_b) self.assertEqual('toA', ev_b.name) self.assertEqual((ev_b, flags_b), all_events[1])
def test_event_names(ev1, ev2): events = [ inotify_simple.Event(0, ev1, 0, "ev1"), inotify_simple.Event(0, ev2, 0, "ev2"), inotify_simple.Event(0, ev1 | ev2, 0, "ev1ev2")] descriptions = daemon.Daemon.describe_events(events) assert len(descriptions) == len(events) assert "ev1" in descriptions[0] assert str(ev1) in descriptions[0] assert "ev2" in descriptions[1] assert str(ev2) in descriptions[1] assert "ev1" in descriptions[2] assert "ev2" in descriptions[2] assert str(ev1) in descriptions[2] assert str(ev2) in descriptions[2]
def test_track_no_our_events(no_sleep, mock_mainfunc, ptmpdir): _, _, inotifier = mock_mainfunc inotifier.v.clear() inotifier.v.extend([inotify_simple.Event(0, 0, 0, "Fake")] * 3) app = get_app() app.destination_path = ptmpdir.join("filename").strpath app.track() assert not os.path.exists(ptmpdir.join("filename").strpath)
def inotifier(request): mock = have_mocked(request, "inotify_simple.INotify") mock.return_value = mock mock.__enter__.return_value = mock values = [inotify_simple.Event(0, 0, 0, os.path.basename(concierge.DEFAULT_RC))] values *= 3 def side_effect(): if values: return [values.pop()] raise KeyboardInterrupt mock.read.side_effect = side_effect mock.v = values return mock