annotate tests/test_sources_posts.py @ 169:f3aa511eef99

serve: Add option to use the debugger without `--debug`.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 03 Jan 2015 18:06:52 -0800
parents cb6eadea0845
children e7b865f8f335
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
95
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import pytest
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 from .mockutil import mock_fs, mock_fs_scope
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 @pytest.mark.parametrize('fs, src_type, expected_paths, expected_metadata', [
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 (mock_fs(), 'flat', [], []),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 (mock_fs().withPage('test/2014-01-01_foo.md'),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 'flat',
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 ['2014-01-01_foo.md'],
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 [(2014, 1, 1, 'foo')]),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 (mock_fs(), 'shallow', [], []),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 (mock_fs().withPage('test/2014/01-01_foo.md'),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 'shallow',
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 ['2014/01-01_foo.md'],
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 [(2014, 1, 1, 'foo')]),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 (mock_fs(), 'hierarchy', [], []),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 (mock_fs().withPage('test/2014/01/01_foo.md'),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 'hierarchy',
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 ['2014/01/01_foo.md'],
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 [(2014, 1, 1, 'foo')]),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 ])
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 def test_post_source_factories(fs, src_type, expected_paths, expected_metadata):
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 fs.withConfig({
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 'site': {
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 'sources': {
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 'test': {'type': 'posts/%s' % src_type}},
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 'routes': [
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 {'url': '/%slug%', 'source': 'test'}]
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 }
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 })
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 fs.withDir('kitchen/test')
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 with mock_fs_scope(fs):
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 app = fs.getApp(cache=False)
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 s = app.getSource('test')
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 facs = list(s.buildPageFactories())
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 paths = [f.rel_path for f in facs]
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 assert paths == expected_paths
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 metadata = [
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 (f.metadata['year'], f.metadata['month'],
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 f.metadata['day'], f.metadata['slug'])
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 for f in facs]
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 assert metadata == expected_metadata
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44