How to use the watchgod.RegExpWatcher function in watchgod

To help you get started, we’ve selected a few watchgod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samuelcolvin / watchgod / tests / test_watch.py View on Github external
def test_regexp_no_re_files(tmpdir):
    mktree(tmpdir, tree)

    re_dirs = r'^(?:(?!recursive_dir).)*$'

    watcher_no_re_files = RegExpWatcher(str(tmpdir), re_dirs=re_dirs)
    changes = watcher_no_re_files.check()
    assert changes == set()

    sleep(0.01)
    tmpdir.join('foo/spam.py').write('xxx')
    tmpdir.join('foo/bar.txt').write('change')
    tmpdir.join('foo/recursive_dir/foo.js').write('change')

    assert watcher_no_re_files.check() == {
        (Change.modified, str(tmpdir.join('foo/spam.py'))),
        (Change.modified, str(tmpdir.join('foo/bar.txt')))
    }
github samuelcolvin / watchgod / tests / test_watch.py View on Github external
def test_regexp_no_args(tmpdir):
    mktree(tmpdir, tree)

    watcher_no_args = RegExpWatcher(str(tmpdir))
    changes = watcher_no_args.check()
    assert changes == set()

    sleep(0.01)
    tmpdir.join('foo/spam.py').write('xxx')
    tmpdir.join('foo/bar.txt').write('change')
    tmpdir.join('foo/recursive_dir/foo.js').write('change')

    assert watcher_no_args.check() == {
        (Change.modified, str(tmpdir.join('foo/spam.py'))),
        (Change.modified, str(tmpdir.join('foo/bar.txt'))),
        (Change.added, str(tmpdir.join('foo/recursive_dir/foo.js')))
    }
github samuelcolvin / watchgod / tests / test_watch.py View on Github external
def test_regexp(tmpdir):
    mktree(tmpdir, tree)

    re_files = r'^.*(\.txt|\.js)$'
    re_dirs = r'^(?:(?!recursive_dir).)*$'

    watcher = RegExpWatcher(str(tmpdir), re_files, re_dirs)
    changes = watcher.check()
    assert changes == set()

    sleep(0.01)
    tmpdir.join('foo/spam.py').write('xxx')
    tmpdir.join('foo/bar.txt').write('change')
    tmpdir.join('foo/borec.txt').write('ahoy')
    tmpdir.join('foo/borec-js.js').write('peace')
    tmpdir.join('foo/recursive_dir/b.js').write('borec')

    assert watcher.check() == {
        (Change.modified, str(tmpdir.join('foo/bar.txt'))),
        (Change.added, str(tmpdir.join('foo/borec.txt'))),
        (Change.added, str(tmpdir.join('foo/borec-js.js')))
    }
github samuelcolvin / watchgod / tests / test_watch.py View on Github external
def test_regexp_no_re_dirs(tmpdir):
    mktree(tmpdir, tree)

    re_files = r'^.*(\.txt|\.js)$'

    watcher_no_re_dirs = RegExpWatcher(str(tmpdir), re_files)
    changes = watcher_no_re_dirs.check()
    assert changes == set()

    sleep(0.01)
    tmpdir.join('foo/spam.py').write('xxx')
    tmpdir.join('foo/bar.txt').write('change')
    tmpdir.join('foo/recursive_dir/foo.js').write('change')

    assert watcher_no_re_dirs.check() == {
        (Change.modified, str(tmpdir.join('foo/bar.txt'))),
        (Change.added, str(tmpdir.join('foo/recursive_dir/foo.js')))
    }