Mercurial > piecrust2
diff tests/test_sources_base.py @ 979:45ad976712ec
tests: Big push to get the tests to pass again.
- Lots of fixes everywhere in the code.
- Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now.
- Replace all `.md` test files with `.html` since now a auto-format extension always sets the format.
- Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 29 Oct 2017 22:51:57 -0700 |
parents | 72f17534d58e |
children | 8adc27285d93 |
line wrap: on
line diff
--- a/tests/test_sources_base.py Sun Oct 29 22:46:41 2017 -0700 +++ b/tests/test_sources_base.py Sun Oct 29 22:51:57 2017 -0700 @@ -1,7 +1,7 @@ import os import pytest -from piecrust.app import PieCrust from .mockutil import mock_fs, mock_fs_scope +from .pathutil import slashfix @pytest.mark.parametrize('fs_fac, expected_paths, expected_slugs', [ @@ -19,7 +19,7 @@ (lambda: mock_fs().withPage('test/foo/bar.ext'), ['foo/bar.ext'], ['foo/bar.ext']), ]) -def test_default_source_factories(fs_fac, expected_paths, expected_slugs): +def test_default_source_items(fs_fac, expected_paths, expected_slugs): fs = fs_fac() fs.withConfig({ 'site': { @@ -31,25 +31,30 @@ }) fs.withDir('kitchen/test') with mock_fs_scope(fs): - app = PieCrust(fs.path('kitchen'), cache=False) + app = fs.getApp() s = app.getSource('test') - facs = list(s.buildPageFactories()) - paths = [f.rel_path for f in facs] - assert paths == expected_paths - slugs = [f.metadata['slug'] for f in facs] + items = list(s.getAllContents()) + paths = [os.path.relpath(f.spec, s.fs_endpoint_path) for f in items] + assert paths == slashfix(expected_paths) + slugs = [f.metadata['route_params']['slug'] for f in items] assert slugs == expected_slugs @pytest.mark.parametrize( - 'ref_path, expected_path, expected_metadata', - [ - ('foo.html', '/kitchen/test/foo.html', {'slug': 'foo'}), - ('foo/bar.html', '/kitchen/test/foo/bar.html', + 'fs_fac, ref_path, expected_path, expected_metadata', [ + (lambda: mock_fs().withPage('test/foo.html'), + 'foo.html', + 'test/foo.html', + {'slug': 'foo'}), + (lambda: mock_fs().withPage('test/foo/bar.html'), + 'foo/bar.html', + 'test/foo/bar.html', {'slug': 'foo/bar'}), + ]) -def test_default_source_resolve_ref(ref_path, expected_path, - expected_metadata): - fs = mock_fs() +def test_default_source_find_item(fs_fac, ref_path, expected_path, + expected_metadata): + fs = fs_fac() fs.withConfig({ 'site': { 'sources': { @@ -58,10 +63,11 @@ {'url': '/%path%', 'source': 'test'}] } }) - expected_path = fs.path(expected_path).replace('/', os.sep) with mock_fs_scope(fs): - app = PieCrust(fs.path('kitchen'), cache=False) + app = fs.getApp() s = app.getSource('test') - actual_path, actual_metadata = s.resolveRef(ref_path) - assert actual_path == expected_path - assert actual_metadata == expected_metadata + item = s.findContent({'slug': ref_path}) + assert item is not None + assert os.path.relpath(item.spec, app.root_dir) == \ + slashfix(expected_path) + assert item.metadata['route_params'] == expected_metadata