comparison tests/test_pipelines_page.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
comparison
equal deleted inserted replaced
978:7e51d14097cb 979:45ad976712ec
1 import time 1 import time
2 import os.path 2 import os.path
3 import urllib.parse 3 import urllib.parse
4 import pytest 4 import pytest
5 from piecrust.pipelines.records import MultiRecord 5 from piecrust.pipelines.records import MultiRecord
6 from piecrust.pipelines._pagebaker import PageBaker 6 from piecrust.pipelines._pagebaker import get_output_path
7 from .mockutil import get_mock_app, mock_fs, mock_fs_scope 7 from .mockutil import get_mock_app, mock_fs, mock_fs_scope
8 8
9 9
10 @pytest.mark.parametrize('uri, pretty, expected', [ 10 @pytest.mark.parametrize('uri, pretty, expected', [
11 # Pretty URLs 11 # Pretty URLs
39 app = get_mock_app() 39 app = get_mock_app()
40 if pretty: 40 if pretty:
41 app.config.set('site/pretty_urls', True) 41 app.config.set('site/pretty_urls', True)
42 assert app.config.get('site/pretty_urls') == pretty 42 assert app.config.get('site/pretty_urls') == pretty
43 43
44 out_dir = '/destination'
45
44 for site_root in ['/', '/whatever/', '/~johndoe/']: 46 for site_root in ['/', '/whatever/', '/~johndoe/']:
45 app.config.set('site/root', urllib.parse.quote(site_root)) 47 app.config.set('site/root', urllib.parse.quote(site_root))
46 baker = PageBaker(app, '/destination') 48 path = get_output_path(app, out_dir,
47 try: 49 urllib.parse.quote(site_root) + uri,
48 path = baker.getOutputPath(urllib.parse.quote(site_root) + uri, 50 pretty)
49 pretty) 51 expected = os.path.normpath(
50 expected = os.path.normpath( 52 os.path.join('/destination', expected))
51 os.path.join('/destination', expected)) 53 assert expected == path
52 assert expected == path
53 finally:
54 baker.shutdown()
55 54
56 55
57 def test_removed(): 56 def test_removed():
58 fs = (mock_fs() 57 fs = (mock_fs()
59 .withConfig() 58 .withConfig()
79 fs = (mock_fs() 78 fs = (mock_fs()
80 .withConfig() 79 .withConfig()
81 .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 80 .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'},
82 'a foo page')) 81 'a foo page'))
83 with mock_fs_scope(fs): 82 with mock_fs_scope(fs):
84 fs.runChef('bake')
85 mtime = os.path.getmtime(fs.path('kitchen/_counter/foo.html'))
86 time.sleep(1) 83 time.sleep(1)
84 fs.runChef('bake', '-o', fs.path('counter'))
85 time.sleep(0.1)
86 mtime = os.path.getmtime(fs.path('counter/foo.html'))
87 87
88 fs.runChef('bake') 88 time.sleep(1)
89 assert mtime == os.path.getmtime(fs.path('kitchen/_counter/foo.html')) 89 fs.runChef('bake', '-o', fs.path('counter'))
90 time.sleep(0.1)
91 assert mtime == os.path.getmtime(fs.path('counter/foo.html'))
90 92
91 MultiRecord.RECORD_VERSION += 1 93 MultiRecord.RECORD_VERSION += 1
92 try: 94 try:
93 fs.runChef('bake') 95 time.sleep(1)
94 assert mtime < os.path.getmtime(fs.path( 96 fs.runChef('bake', '-o', fs.path('counter'))
95 'kitchen/_counter/foo.html')) 97 time.sleep(0.1)
98 assert mtime < os.path.getmtime(fs.path('counter/foo.html'))
96 finally: 99 finally:
97 MultiRecord.RECORD_VERSION -= 1 100 MultiRecord.RECORD_VERSION -= 1
98 101