Esempio n. 1
0
def test_watchdog_catch_file_creation_event():
    l = FlagListener()
    wd = Watchdog(tmp_wpth, l)
    wd.start()

    with open(pj(tmp_wpth, "toto.txt"), 'w') as f:
        json.dump("lorem ipsum", f)

    sleep(0.5)
    wd.stop()

    assert l.flag == "toto.txt"
Esempio n. 2
0
def test_watchdog_catch_file_multiple_creation_event():
    l = FlagListener()
    wd = Watchdog(tmp_wpth, l)
    wd.start()

    res = []
    for i in range(2):
        with open(pj(tmp_wpth, "toto.txt"), 'w') as f:
            json.dump("lorem ipsum", f)

        sleep(0.5)
        res.append(l.flag == "toto.txt")
        l.flag = None

    wd.stop()
    assert all(res)
Esempio n. 3
0
def test_watchdog_run_separate_thread():
    wd = Watchdog(tmp_wpth, None)
    wd.start()
    while not wd.is_running():
        sleep(0.1)

    res = wd.watched_path() == tmp_wpth

    wd.stop()
    assert res
Esempio n. 4
0
def test_watchdog_do_not_catch_dir_creation_event():
    l = FlagListener()
    wd = Watchdog(tmp_wpth, l)
    wd.start()
    while not wd.is_running():
        sleep(0.1)

    mkdir(pj(tmp_wpth, "tutu"))

    sleep(0.5)
    wd.stop()
    rmdir(pj(tmp_wpth, "tutu"))

    assert l.flag is None
from oaserver.watchdog import Watchdog, WatchdogListener


class LogWatch(WatchdogListener):
    def __init__(self):
        pass

    def file_created(self, name, cnt):
        print name, cnt


log = LogWatch()
w = Watchdog("dirac:/vo.france-grilles.fr/user/j/jchopard/tata", log)
w.start()