mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
files_changed: cleanup and add a test
This commit is contained in:
parent
4f95b9f05c
commit
39bdbcfd86
2 changed files with 20 additions and 5 deletions
|
|
@ -210,9 +210,6 @@ LAST_MTIME = 0
|
|||
def files_changed(path, extensions):
|
||||
"""Return True if the files have changed since the last check"""
|
||||
|
||||
def with_extension(f):
|
||||
return any(f.endswith(ext) for ext in extensions)
|
||||
|
||||
def file_times(path):
|
||||
"""Return the last time files have been modified"""
|
||||
for root, dirs, files in os.walk(path):
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ try:
|
|||
import unittest2 as unittest
|
||||
except ImportError:
|
||||
import unittest # NOQA
|
||||
|
||||
import os
|
||||
import datetime
|
||||
import time
|
||||
|
||||
from pelican import utils
|
||||
from pelican.contents import Article
|
||||
|
||||
from support import get_article
|
||||
|
||||
|
||||
|
|
@ -73,3 +74,20 @@ class TestUtils(unittest.TestCase):
|
|||
self.assertIn(fr_article1, trans)
|
||||
self.assertNotIn(en_article1, trans)
|
||||
self.assertNotIn(fr_article1, index)
|
||||
|
||||
def test_files_changed(self):
|
||||
"Test if file changes are correctly detected"
|
||||
|
||||
path = os.path.join(os.path.dirname(__file__), 'content')
|
||||
filename = os.path.join(path, 'article_with_metadata.rst')
|
||||
changed = utils.files_changed(path, 'rst')
|
||||
self.assertEquals(changed, True)
|
||||
|
||||
changed = utils.files_changed(path, 'rst')
|
||||
self.assertEquals(changed, False)
|
||||
|
||||
t = time.time()
|
||||
os.utime(filename, (t, t))
|
||||
changed = utils.files_changed(path, 'rst')
|
||||
self.assertEquals(changed, True)
|
||||
self.assertAlmostEqual(utils.LAST_MTIME, t, places=2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue