Mercurial > piecrust2
comparison tests/test_page.py @ 3:f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
- Serving works, with debug window.
- Baking works, multi-threading, with dependency handling.
- Various things not implemented yet.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 10 Aug 2014 23:43:16 -0700 |
parents | |
children | 474c9882decf |
comparison
equal
deleted
inserted
replaced
2:40fa08b261b9 | 3:f485ba500df3 |
---|---|
1 import pytest | |
2 from piecrust.page import parse_segments | |
3 | |
4 | |
5 | |
6 test_parse_segments_data1 = ("", {'content': ''}) | |
7 test_parse_segments_data2 = ("Foo bar", {'content': 'Foo bar'}) | |
8 test_parse_segments_data3 = ("""Something that spans | |
9 several lines | |
10 like this""", | |
11 {'content': """Something that spans | |
12 several lines | |
13 like this"""}) | |
14 test_parse_segments_data4 = ("""Blah blah | |
15 ---foo--- | |
16 Something else | |
17 ---bar--- | |
18 Last thing | |
19 """, | |
20 { | |
21 'content': "Blah blah\n", | |
22 'foo': "Something else\n", | |
23 'bar': "Last thing\n"}) | |
24 test_parse_segments_data5 = ("""Blah blah | |
25 <--textile--> | |
26 Here's some textile | |
27 """, | |
28 { | |
29 'content': [ | |
30 ("Blah blah\n", None), | |
31 ("Here's some textile\n", 'textile')]}) | |
32 test_parse_segments_data6 = ("""Blah blah | |
33 Whatever | |
34 <--textile--> | |
35 Oh well, that's good | |
36 ---foo--- | |
37 Another segment | |
38 With another... | |
39 <--change--> | |
40 ...of formatting. | |
41 """, | |
42 { | |
43 'content': [ | |
44 ("Blah blah\nWhatever\n", None), | |
45 ("Oh well, that's good\n", 'textile')], | |
46 'foo': [ | |
47 ("Another segment\nWith another...\n", None), | |
48 ("...of formatting.\n", 'change')]}) | |
49 | |
50 @pytest.mark.parametrize('text, expected', [ | |
51 test_parse_segments_data1, | |
52 test_parse_segments_data2, | |
53 test_parse_segments_data3, | |
54 test_parse_segments_data4, | |
55 test_parse_segments_data5, | |
56 test_parse_segments_data6, | |
57 ]) | |
58 def test_parse_segments(text, expected): | |
59 actual = parse_segments(text) | |
60 assert actual is not None | |
61 assert actual.keys() == expected.keys() | |
62 for key, val in expected.iteritems(): | |
63 if isinstance(val, str): | |
64 assert len(actual[key].parts) == 1 | |
65 assert actual[key].parts[0].content == val | |
66 assert actual[key].parts[0].fmt is None | |
67 else: | |
68 assert len(actual[key].parts) == len(val) | |
69 for i, part in enumerate(val): | |
70 assert actual[key].parts[i].content == part[0] | |
71 assert actual[key].parts[i].fmt == part[1] | |
72 |