# HG changeset patch # User Ludovic Chabant # Date 1410151030 25200 # Node ID cb6eadea0845b64f71710f945315a50395ffc914 # Parent b536022078a2fe8bea5bc6c977a90d56f0935403 Fixed a bug with the `shallow` source. Add unit tests. diff -r b536022078a2 -r cb6eadea0845 piecrust/sources/posts.py --- a/piecrust/sources/posts.py Sun Sep 07 21:36:42 2014 -0700 +++ b/piecrust/sources/posts.py Sun Sep 07 21:37:10 2014 -0700 @@ -205,7 +205,7 @@ year = int(yd) year_dir = os.path.join(self.fs_endpoint_path, yd) - _, __, filenames = os.walk(year_dir) + _, __, filenames = next(os.walk(year_dir)) for f in filenames: match = file_pattern.match(f) if match is None: diff -r b536022078a2 -r cb6eadea0845 tests/test_sources_posts.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_sources_posts.py Sun Sep 07 21:37:10 2014 -0700 @@ -0,0 +1,44 @@ +import os +import pytest +from .mockutil import mock_fs, mock_fs_scope + + +@pytest.mark.parametrize('fs, src_type, expected_paths, expected_metadata', [ + (mock_fs(), 'flat', [], []), + (mock_fs().withPage('test/2014-01-01_foo.md'), + 'flat', + ['2014-01-01_foo.md'], + [(2014, 1, 1, 'foo')]), + (mock_fs(), 'shallow', [], []), + (mock_fs().withPage('test/2014/01-01_foo.md'), + 'shallow', + ['2014/01-01_foo.md'], + [(2014, 1, 1, 'foo')]), + (mock_fs(), 'hierarchy', [], []), + (mock_fs().withPage('test/2014/01/01_foo.md'), + 'hierarchy', + ['2014/01/01_foo.md'], + [(2014, 1, 1, 'foo')]), + ]) +def test_post_source_factories(fs, src_type, expected_paths, expected_metadata): + fs.withConfig({ + 'site': { + 'sources': { + 'test': {'type': 'posts/%s' % src_type}}, + 'routes': [ + {'url': '/%slug%', 'source': 'test'}] + } + }) + fs.withDir('kitchen/test') + with mock_fs_scope(fs): + app = fs.getApp(cache=False) + s = app.getSource('test') + facs = list(s.buildPageFactories()) + paths = [f.rel_path for f in facs] + assert paths == expected_paths + metadata = [ + (f.metadata['year'], f.metadata['month'], + f.metadata['day'], f.metadata['slug']) + for f in facs] + assert metadata == expected_metadata +