def test_file_moved(self): path = os.path.join(self.tmpdir, "tmpfile") create(path) config = [{"directories": {self.tmpdir: {"mask": ["move"]}}}] self.assertValid(config) self.assertEqual(watchdog.beacon(config), []) os.rename(path, path + "_moved") ret = check_events(config) self.assertEqual(len(ret), 1) self.assertEqual(ret[0]["path"], path) self.assertEqual(ret[0]["change"], "moved")
def test_file_moved(self): path = os.path.join(self.tmpdir, 'tmpfile') create(path) config = [{'directories': {self.tmpdir: {'mask': ['move']}}}] self.assertValid(config) self.assertEqual(watchdog.beacon(config), []) os.rename(path, path + '_moved') ret = check_events(config) self.assertEqual(len(ret), 1) self.assertEqual(ret[0]['path'], path) self.assertEqual(ret[0]['change'], 'moved')
def test_file_moved(tmp_path): path = str(tmp_path / "tmpfile") create(path) config = [{"directories": {str(tmp_path): {"mask": ["move"]}}}] assertValid(config) assert watchdog.beacon(config) == [] os.rename(path, path + "_moved") ret = check_events(config) assert len(ret) == 1 assert ret[0]["path"] == path assert ret[0]["change"] == "moved"
def test_file_modified(self): path = os.path.join(self.tmpdir, 'tmpfile') config = [{'directories': {self.tmpdir: {'mask': ['modify']}}}] self.assertValid(config) self.assertEqual(watchdog.beacon(config), []) create(path, 'some content') ret = check_events(config) self.assertEqual(len(ret), 2) self.assertEqual(ret[0]['path'], os.path.dirname(path)) self.assertEqual(ret[0]['change'], 'modified') self.assertEqual(ret[1]['path'], path) self.assertEqual(ret[1]['change'], 'modified')
def test_trigger_all_possible_events(self): path = os.path.join(self.tmpdir, 'tmpfile') moved = path + '_moved' config = [{ 'directories': { self.tmpdir: {}, } }] self.assertValid(config) self.assertEqual(watchdog.beacon(config), []) # create create(path) # modify create(path, 'modified content') # move os.rename(path, moved) # delete os.remove(moved) ret = check_events(config) self.assertEqual(len(ret), 8) # create self.assertEqual(ret[0]['path'], path) self.assertEqual(ret[0]['change'], 'created') self.assertEqual(ret[1]['path'], self.tmpdir) self.assertEqual(ret[1]['change'], 'modified') # modify self.assertEqual(ret[2]['path'], path) self.assertEqual(ret[2]['change'], 'modified') self.assertEqual(ret[3]['path'], path) self.assertEqual(ret[3]['change'], 'modified') # move self.assertEqual(ret[4]['path'], path) self.assertEqual(ret[4]['change'], 'moved') self.assertEqual(ret[5]['path'], self.tmpdir) self.assertEqual(ret[5]['change'], 'modified') # delete self.assertEqual(ret[6]['path'], moved) self.assertEqual(ret[6]['change'], 'deleted') self.assertEqual(ret[7]['path'], self.tmpdir) self.assertEqual(ret[7]['change'], 'modified')
def test_file_create_in_directory(self): config = [{ 'directories': { self.tmpdir: { 'mask': ['create', 'modify'] } } }] self.assertValid(config) self.assertEqual(watchdog.beacon(config), []) path = os.path.join(self.tmpdir, 'tmpfile') create(path) ret = check_events(config) self.assertEqual(len(ret), 2) self.assertEqual(ret[0]['path'], path) self.assertEqual(ret[0]['change'], 'created') self.assertEqual(ret[1]['path'], self.tmpdir) self.assertEqual(ret[1]['change'], 'modified')
def test_empty_config(self): config = [{}] ret = watchdog.beacon(config) self.assertEqual(ret, [])
def test_empty_config(): config = [{}] ret = watchdog.beacon(config) assert ret == []