Mercurial > piecrust2
changeset 30:4bd840ae75cd
Fix stupid bug in default source, add some unit tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 19 Aug 2014 12:46:55 -0700 |
parents | 7e44f6092a1d |
children | 8c15fc45d712 |
files | piecrust/sources/base.py tests/test_sources_base.py |
diffstat | 2 files changed, 65 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/sources/base.py Tue Aug 19 11:51:09 2014 -0700 +++ b/piecrust/sources/base.py Tue Aug 19 12:46:55 2014 -0700 @@ -307,7 +307,7 @@ for f in filter(self._filterPageFilename, filenames): slug, ext = os.path.splitext(os.path.join(rel_dirpath, f)) slug = slug.replace('\\', '/') - if ext not in self.supported_extensions: + if ext.lstrip('.') not in self.supported_extensions: slug += ext if slug.startswith('./') or slug.startswith('.\\'): slug = slug[2:]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_sources_base.py Tue Aug 19 12:46:55 2014 -0700 @@ -0,0 +1,64 @@ +import os +import pytest +from piecrust.app import PieCrust +from piecrust.sources.base import DefaultPageSource +from .mockutil import mock_fs, mock_fs_scope + + +@pytest.mark.parametrize('fs, expected_paths, expected_slugs', [ + (mock_fs(), [], []), + (mock_fs().withPage('test/foo.html'), + ['foo.html'], ['foo']), + (mock_fs().withPage('test/foo.md'), + ['foo.md'], ['foo']), + (mock_fs().withPage('test/foo.ext'), + ['foo.ext'], ['foo.ext']), + (mock_fs().withPage('test/foo/bar.html'), + ['foo/bar.html'], ['foo/bar']), + (mock_fs().withPage('test/foo/bar.md'), + ['foo/bar.md'], ['foo/bar']), + (mock_fs().withPage('test/foo/bar.ext'), + ['foo/bar.ext'], ['foo/bar.ext']), + ]) +def test_default_source_factories(fs, expected_paths, expected_slugs): + fs.withConfig({ + 'site': { + 'sources': { + 'test': {}}, + 'routes': [ + {'url': '/%path%', 'source': 'test'}] + } + }) + fs.withDir('kitchen/_content/test') + with mock_fs_scope(fs): + app = PieCrust(fs.path('kitchen'), cache=False) + s = app.getSource('test') + facs = list(s.buildPageFactories()) + paths = [f.rel_path for f in facs] + assert paths == expected_paths + slugs = [f.metadata['path'] for f in facs] + assert slugs == expected_slugs + + + +@pytest.mark.parametrize('ref_path, expected', [ + ('foo.html', '/kitchen/_content/test/foo.html'), + ('foo/bar.html', '/kitchen/_content/test/foo/bar.html'), + ]) +def test_default_source_resolve_ref(ref_path, expected): + fs = mock_fs() + fs.withConfig({ + 'site': { + 'sources': { + 'test': {}}, + 'routes': [ + {'url': '/%path%', 'source': 'test'}] + } + }) + expected = fs.path(expected).replace('/', os.sep) + with mock_fs_scope(fs): + app = PieCrust(fs.path('kitchen'), cache=False) + s = app.getSource('test') + actual = s.resolveRef(ref_path) + assert actual == expected +