diff --git a/livereload/watcher.py b/livereload/watcher.py index 09c3a1b..57d9898 100644 --- a/livereload/watcher.py +++ b/livereload/watcher.py @@ -88,6 +88,7 @@ def examine(self): # clean filepath self.filepath = None delays = set() + never_reload = False for path in self._tasks: item = self._tasks[path] self._task_mtimes = item['mtimes'] @@ -95,7 +96,9 @@ def examine(self): if changed: func = item['func'] delay = item['delay'] - if delay and isinstance(delay, float): + if delay == 'forever': + never_reload = True + elif delay and isinstance(delay, float): delays.add(delay) if func: name = getattr(func, 'name', None) @@ -110,6 +113,8 @@ def examine(self): if delays: delay = max(delays) + elif never_reload: + delay = 'forever' else: delay = None return self.filepath, delay diff --git a/tests/test_watcher.py b/tests/test_watcher.py index 07ee21c..46e79d0 100644 --- a/tests/test_watcher.py +++ b/tests/test_watcher.py @@ -150,3 +150,32 @@ def test_watch_multiple_dirs(self): os.remove(second_path) assert watcher.examine() == (second_path, None) assert watcher.examine() == (None, None) + + def test_watch_delay_forever(self): + watcher = Watcher() + watcher._start -= 1 + + filepath = os.path.join(tmpdir, 'foo') + with open(filepath, 'w') as f: + f.write('') + + watcher.watch(filepath, delay='forever') + + assert watcher.examine() == (os.path.abspath(filepath), 'forever') + assert watcher.examine() == (None, None) + + def test_watch_delay_forever_beside_a_numeric_delay(self): + watcher = Watcher() + watcher._start -= 1 + + forever_path = os.path.join(tmpdir, 'foo') + delayed_path = os.path.join(tmpdir, 'bar') + for path in (forever_path, delayed_path): + with open(path, 'w') as f: + f.write('') + + watcher.watch(forever_path, delay='forever') + watcher.watch(delayed_path, delay=1.0) + + assert watcher.examine() == (os.path.abspath(delayed_path), 1.0) + assert watcher.examine() == (None, None)