diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_page.py	Sun Aug 10 23:43:16 2014 -0700
@@ -0,0 +1,72 @@
+import pytest
+from piecrust.page import parse_segments
+
+
+
+test_parse_segments_data1 = ("", {'content': ''})
+test_parse_segments_data2 = ("Foo bar", {'content': 'Foo bar'})
+test_parse_segments_data3 = ("""Something that spans
+several lines
+like this""",
+        {'content': """Something that spans
+several lines
+like this"""})
+test_parse_segments_data4 = ("""Blah blah
+---foo---
+Something else
+---bar---
+Last thing
+""",
+        {
+            'content': "Blah blah\n",
+            'foo': "Something else\n",
+            'bar': "Last thing\n"})
+test_parse_segments_data5 = ("""Blah blah
+<--textile-->
+Here's some textile
+""",
+        {
+            'content': [
+                ("Blah blah\n", None),
+                ("Here's some textile\n", 'textile')]})
+test_parse_segments_data6 = ("""Blah blah
+Whatever
+<--textile-->
+Oh well, that's good
+---foo---
+Another segment
+With another...
+<--change-->
+...of formatting.
+""",
+        {
+            'content': [
+                ("Blah blah\nWhatever\n", None),
+                ("Oh well, that's good\n", 'textile')],
+            'foo': [
+                ("Another segment\nWith another...\n", None),
+                ("...of formatting.\n", 'change')]})
+
+@pytest.mark.parametrize('text, expected', [
+        test_parse_segments_data1,
+        test_parse_segments_data2,
+        test_parse_segments_data3,
+        test_parse_segments_data4,
+        test_parse_segments_data5,
+        test_parse_segments_data6,
+    ])
+def test_parse_segments(text, expected):
+    actual = parse_segments(text)
+    assert actual is not None
+    assert actual.keys() == expected.keys()
+    for key, val in expected.iteritems():
+        if isinstance(val, str):
+            assert len(actual[key].parts) == 1
+            assert actual[key].parts[0].content == val
+            assert actual[key].parts[0].fmt is None
+        else:
+            assert len(actual[key].parts) == len(val)
+            for i, part in enumerate(val):
+                assert actual[key].parts[i].content == part[0]
+                assert actual[key].parts[i].fmt == part[1]
+