annotate tests/test_formatter.py @ 303:6bd9d44fc535

Wiki updater cleanup and improvements. * Less confusing API on `WikiParameters`. * Less confusing way to do things when running the Flask app. * When running locally, and the user edits a page, just resolve that page and mark any other including/querying page invalidated. Resolve those lazily on demand. * Add DB ability to return the resolved state of pages.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 01 Oct 2014 08:19:03 -0700
parents 1ef50117ec58
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
228
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import pytest
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 from wikked.formatter import PageFormatter, FormattingContext
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 from tests import format_link, format_include
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 @pytest.mark.parametrize('in_text, text, meta, links', [
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 (
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 "Something.\nThat's it.\n",
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 "Something.\nThat's it.\n",
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 None, None),
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 (
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 "Some meta.\n\n{{foo: Whatever man}}\n",
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 "Some meta.\n\n",
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 {'foo': ["Whatever man"]}, None),
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 (
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 "Some multi-meta.\n\n{{foo: First}}\n{{foo: Second}}\n",
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 "Some multi-meta.\n\n\n",
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 {'foo': ["First", "Second"]}, None),
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 (
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 "Multi-line meta:\n\n{{foo: This is a\n multi-line meta\n}}\n",
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 "Multi-line meta:\n\n",
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 {'foo': ["This is a\n multi-line meta"]}, None)
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 ])
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 def test_formatter(in_text, text, meta, links):
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 f = PageFormatter()
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 ctx = FormattingContext('/foo')
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 actual = f.formatText(ctx, in_text)
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 assert actual == text
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 if meta:
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 assert ctx.meta == meta
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 else:
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 assert ctx.meta == {}
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 if links:
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 assert ctx.out_links == links
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 else:
1ef50117ec58 Added test for the `PageFormatter`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 assert ctx.out_links == []