def test_add_watched_file(tmpdir): file = tmpdir.join('bar.txt') watcher = AllWatcher(str(file)) assert watcher.check() == set() sleep(0.01) file.write('foobar') assert watcher.check() == {(Change.added, str(file))}
def test_add(tmpdir): watcher = AllWatcher(str(tmpdir)) changes = watcher.check() assert changes == set() sleep(0.01) tmpdir.join('foo.txt').write('foobar') changes = watcher.check() assert changes == {(Change.added, str(tmpdir.join('foo.txt')))}
def test_ignore_root(tmpdir): mktree(tmpdir, tree) watcher = AllWatcher(str(tmpdir), ignored_paths={tmpdir.join('foo')}) assert watcher.check() == set() sleep(0.01) tmpdir.join('foo/bar.txt').write('foobar') assert watcher.check() == set()
def test_modify(tmpdir): mktree(tmpdir, tree) watcher = AllWatcher(str(tmpdir)) assert watcher.check() == set() sleep(0.01) tmpdir.join('foo/bar.txt').write('foobar') assert watcher.check() == {(Change.modified, str(tmpdir.join('foo/bar.txt')))}
def test_modify_watched_file(tmpdir): file = tmpdir.join('bar.txt') file.write('foobar') watcher = AllWatcher(str(file)) assert watcher.check() == set() sleep(0.01) file.write('foobar') assert watcher.check() == {(Change.modified, str(file)) } # same content but time updated sleep(0.01) file.write('baz') assert watcher.check() == {(Change.modified, str(file))}
def test_ignore_file_path(tmpdir): mktree(tmpdir, tree) watcher = AllWatcher(str(tmpdir), ignored_paths={tmpdir.join('foo', 'bar.txt')}) assert watcher.check() == set() sleep(0.01) tmpdir.join('foo', 'bar.txt').write('foobar') tmpdir.join('foo', 'new_not_ignored.txt').write('foobar') tmpdir.join('foo', 'spam.py').write('foobar') assert watcher.check() == {(Change.added, tmpdir.join('foo', 'new_not_ignored.txt')), (Change.modified, tmpdir.join('foo', 'spam.py'))}
def test_ignore_subdir(tmpdir): mktree(tmpdir, tree) watcher = AllWatcher(str(tmpdir), ignored_paths={tmpdir.join('dir', 'ignored')}) assert watcher.check() == set() sleep(0.01) tmpdir.mkdir('dir') tmpdir.mkdir('dir', 'ignored') tmpdir.mkdir('dir', 'not_ignored') tmpdir.join('dir', 'ignored', 'file.txt').write('content') tmpdir.join('dir', 'not_ignored', 'file.txt').write('content') assert watcher.check() == {(Change.added, tmpdir.join('dir', 'not_ignored', 'file.txt'))}
def test_delete(tmpdir): mktree(tmpdir, tree) watcher = AllWatcher(str(tmpdir)) sleep(0.01) tmpdir.join('foo/bar.txt').remove() assert watcher.check() == {(Change.deleted, str(tmpdir.join('foo/bar.txt')))}