def test_watch(tmod): mangle = "_5" registry = Registry() watcher = watch(pattern=tmod.rel("*.py"), registry=registry, debounce=0) za = tmod.imp("za", mangle=mangle) assert za.word == "tyrant" # This one is a syntax error, but it shouldn't kill the thread tmod.write("za_5.py", 'word = "pirate\n') # If the FS is slow 0.05 seconds might not be enough, but oh well time.sleep(0.05) assert za.word == "tyrant" # This one is OK and the change should be loaded tmod.write("za_5.py", 'word = "pirate"\n') time.sleep(0.05) assert za.word == "pirate" watcher.stop() # Updates won't reload anymore tmod.write("za_5.py", 'word = "nowatch"\n') time.sleep(0.05) assert za.word == "pirate" watcher.join() assert not watcher.observer.is_alive()
def test_debounce(tmod): def lg(evt): evts.append(type(evt).__name__) evts = [] mangle = "_6" registry = Registry() watch(pattern=tmod.rel("*.py"), registry=registry, debounce=0.1) registry.activity.register(lg) za = tmod.imp("za", mangle=mangle) assert za.word == "tyrant" tmod.write("za_6.py", "") time.sleep(0.05) tmod.write("za_6.py", 'word = "tyrant"\nxxx = "xxx"') time.sleep(0.20) assert za.word == "tyrant" assert za.xxx == "xxx" assert evts.count("DeleteOperation") == 0 assert evts.count("AddOperation") == 1 assert evts.count("UpdateOperation") == 1