def test_monitoring(self, capsys): # this test is shaky at best, we need to wait (sleep) before # watchdog notices the file change, therefore a slower PC might # "fail" this test (2,6Ghz + SSD) triggered_txt = list() triggered_not_txt = list() tmpdir = tempfile.mkdtemp() fn = path.join(tmpdir, "test.txt") monitor = Monitor(tmpdir) @monitor.listen(["*.txt"], on_startup=True) def add_to_triggered_txt(): triggered_txt.append(len(triggered_txt)) @monitor.listen(["!*.txt"], on_startup=False) def add_to_triggered_not_txt(): triggered_not_txt.append(len(triggered_not_txt)) thread = Thread(target=lambda: monitor.run(0.1)) thread.start() sleep(0.4) with open(fn, "w") as stream: stream.write("Test!") with open(fn + ".tmp", "w") as stream: stream.write("Other test.") sleep(0.9) with open(fn, "w") as stream: stream.write("Testing some more!") sleep(0.5) unlink(fn) unlink(fn + ".tmp") sleep(0.5) monitor.stop() thread.join() assert triggered_txt == [0, 1, 2, 3] assert triggered_not_txt == [0, 1] out, err = capsys.readouterr() assert " - add_to_triggered_txt - created " + fn in out assert " - add_to_triggered_not_txt - created " + fn in out assert " - add_to_triggered_txt - modified " + fn in out assert " - add_to_triggered_txt - deleted " + fn in out assert " - add_to_triggered_not_txt - deleted " + fn in out
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function from pandora import Monitor from subprocess import call from pandora import absfilename monitor = Monitor() here = absfilename(".") @monitor.listen(["monitor.py"]) def on_monitor_change(): monitor.restart_process() def listen(name): @monitor.listen(["sources/%s/src/*.py" % name, "sources/%s/*.rst" % name], on_startup=True) def on_change(source): docs = absfilename("docs", name, here=here) sources = absfilename("sources", name, here=here) print("Source", sources) print("Docs ", docs) call(["sphinx-build", "-b", "html", "docs", docs], cwd=sources) for package in ["Assemble", "Avenue", "Disinfect", "Pandora", "Poort"]: listen(package)