From 62d0aa159fc046a27bed47e337d787a08f4687d0 Mon Sep 17 00:00:00 2001 From: Sunaina Pai Date: Sat, 17 Mar 2018 14:45:21 +0530 Subject: Add makesite: A simple static site generator --- test/test_list.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/test_list.py (limited to 'test/test_list.py') diff --git a/test/test_list.py b/test/test_list.py new file mode 100644 index 0000000..8acb2ef --- /dev/null +++ b/test/test_list.py @@ -0,0 +1,46 @@ +import unittest +import shutil +import os +import makesite +from test import path + +class PagesTest(unittest.TestCase): + def setUp(self): + self.site_path = path.temppath('site') + + def tearDown(self): + shutil.rmtree(self.site_path) + + def test_list(self): + posts = [{'content': 'Foo'}, {'content': 'Bar'}] + dst = os.path.join(self.site_path, 'list.txt') + list_layout = '
{{ content }}
' + item_layout = '

{{ content }}

' + makesite.make_list(posts, dst, list_layout, item_layout) + with open(os.path.join(self.site_path, 'list.txt')) as f: + self.assertEqual(f.read(), '

Foo

Bar

') + + def test_list_params(self): + posts = [{'content': 'Foo', 'title': 'foo'}, + {'content': 'Bar', 'title': 'bar'}] + dst = os.path.join(self.site_path, 'list.txt') + list_layout = '
{{ key }}:{{ title }}:{{ content }}
' + item_layout = '

{{ key }}:{{ title }}:{{ content }}

' + makesite.make_list(posts, dst, list_layout, item_layout, + key='val', title='lorem') + with open(os.path.join(self.site_path, 'list.txt')) as f: + text = f.read() + self.assertEqual(text, + '
val:lorem:

val:foo:Foo

val:bar:Bar

') + + def test_dst_params(self): + posts = [{'content': 'Foo'}, {'content': 'Bar'}] + dst = os.path.join(self.site_path, '{{ key }}.txt') + list_layout = '
{{ content }}
' + item_layout = '

{{ content }}

' + makesite.make_list(posts, dst, list_layout, item_layout, key='val') + + expected_path = os.path.join(self.site_path, 'val.txt') + self.assertTrue(os.path.isfile(expected_path)) + with open(expected_path) as f: + self.assertEqual(f.read(), '

Foo

Bar

') -- cgit v1.2.3