Esempio n. 1
0
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))}
Esempio n. 2
0
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')))}
Esempio n. 3
0
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')))}
Esempio n. 4
0
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()
Esempio n. 5
0
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')))}
Esempio n. 6
0
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))}
Esempio n. 7
0
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'))}
Esempio n. 8
0
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'))}
Esempio n. 9
0
def test_does_not_exist(caplog):
    AllWatcher('/foo/bar')
    assert "error walking file system: FileNotFoundError [Errno 2] No such file or directory: '/foo/bar'" in caplog.text
Esempio n. 10
0
def test_does_not_exist(caplog, tmp_path):
    p = str(tmp_path / 'missing')
    AllWatcher(p)
    assert f"error walking file system: FileNotFoundError [Errno 2] No such file or directory: '{p}'" in caplog.text
Esempio n. 11
0
def _main():
    watcher = AllWatcher('/Users/johan/Dev/smash-rl')
    run_process(path='stats.json', target=plot_stuff, watcher_cls=watcher)