From e86f4eedcf83066e4e16d82ceec43bf2deb43b8e Mon Sep 17 00:00:00 2001 From: Deniz Turgut Date: Fri, 19 Apr 2013 23:35:09 -0400 Subject: [PATCH] bugfix and tests for no settings path (no -s option) --- pelican/tests/test_utils.py | 4 ++++ pelican/utils.py | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pelican/tests/test_utils.py b/pelican/tests/test_utils.py index f89c2907..18babca7 100644 --- a/pelican/tests/test_utils.py +++ b/pelican/tests/test_utils.py @@ -150,6 +150,10 @@ class TestUtils(LoggedTestCase): self.assertEqual(next(folder_watcher), True) self.assertEqual(next(file_watcher), True) + # file watcher with None or empty path should return None + self.assertEqual(next(utils.file_watcher('')), None) + self.assertEqual(next(utils.file_watcher(None)), None) + empty_path = os.path.join(os.path.dirname(__file__), 'empty') try: os.mkdir(empty_path) diff --git a/pelican/utils.py b/pelican/utils.py index c6f108f9..39a3f8f4 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -463,12 +463,15 @@ def file_watcher(path): '''Generator for monitoring a file for modifications''' LAST_MTIME = 0 while True: - mtime = os.stat(path).st_mtime - if mtime > LAST_MTIME: - LAST_MTIME = mtime - yield True + if path: + mtime = os.stat(path).st_mtime + if mtime > LAST_MTIME: + LAST_MTIME = mtime + yield True + else: + yield False else: - yield False + yield None def set_date_tzinfo(d, tz_name=None):