diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/path.py b/test/path.py deleted file mode 100644 index 38c0991..0000000 --- a/test/path.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import tempfile -import shutil - - -def temppath(*paths): - return os.path.join(tempfile.gettempdir(), *paths) - - -def move(src, dst): - if os.path.isfile(dst): - os.remove(dst) - elif os.path.isdir(dst): - shutil.rmtree(dst) - if os.path.exists(src): - os.rename(src, dst) diff --git a/test/test_content.py b/test/test_content.py deleted file mode 100644 index 66342d9..0000000 --- a/test/test_content.py +++ /dev/null @@ -1,104 +0,0 @@ -import unittest -import shutil -import os - -import makesite -from test import path - - -class ContentTest(unittest.TestCase): - def setUp(self): - self.blog_path = path.temppath('blog') - self.undated_path = os.path.join(self.blog_path, 'foo.txt') - self.dated_path = os.path.join(self.blog_path, '2018-01-01-foo.txt') - self.normal_post_path = os.path.join(self.blog_path, 'baz.txt') - self.md_post_path = os.path.join(self.blog_path, 'qux.md') - self.no_md_post_path = os.path.join(self.blog_path, 'qux.txt') - - os.makedirs(self.blog_path) - - with open(self.undated_path, 'w') as f: - f.write('hello world') - - with open(self.dated_path, 'w') as f: - f.write('hello world') - - with open(self.normal_post_path, 'w') as f: - f.write('\n\nFoo') - - with open(self.md_post_path, 'w') as f: - f.write('*Foo*') - - with open(self.no_md_post_path, 'w') as f: - f.write('*Foo*') - - def tearDown(self): - shutil.rmtree(self.blog_path) - - # Rudimentary mock because unittest.mock is unavailable in Python 2.7. - def mock(self, *args): - self.mock_args = args - - def test_content_content(self): - content = makesite.read_content(self.undated_path) - self.assertEqual(content['content'], 'hello world') - - def test_content_date(self): - content = makesite.read_content(self.dated_path) - self.assertEqual(content['date'], '2018-01-01') - - def test_content_date_missing(self): - content = makesite.read_content(self.undated_path) - self.assertEqual(content['date'], '1970-01-01') - - def test_content_slug_dated(self): - content = makesite.read_content(self.dated_path) - self.assertEqual(content['slug'], 'foo') - - def test_content_slug_undated(self): - content = makesite.read_content(self.undated_path) - self.assertEqual(content['slug'], 'foo') - - def test_content_headers(self): - content = makesite.read_content(self.normal_post_path) - self.assertEqual(content['a'], '1') - self.assertEqual(content['b'], '2') - self.assertEqual(content['content'], 'Foo') - - def test_markdown_rendering(self): - content = makesite.read_content(self.md_post_path) - self.assertEqual(content['content'], '

Foo

\n') - - def test_markdown_import_error(self): - makesite._test = 'ImportError' - original_log = makesite.log - - makesite.log = self.mock - self.mock_args = None - content = makesite.read_content(self.md_post_path) - - makesite._test = None - makesite.log = original_log - - self.assertEqual(content['content'], '*Foo*') - self.assertEqual(self.mock_args, - ('WARNING: Cannot render Markdown in {}: {}', - self.md_post_path, 'Error forced by test')) - - def test_no_markdown_rendering(self): - content = makesite.read_content(self.no_md_post_path) - self.assertEqual(content['content'], '*Foo*') - - def test_no_markdown_import_error(self): - makesite._test = 'ImportError' - original_log = makesite.log - - makesite.log = self.mock - self.mock_args = None - content = makesite.read_content(self.no_md_post_path) - - makesite._test = None - makesite.log = original_log - - self.assertEqual(content['content'], '*Foo*') - self.assertIsNone(self.mock_args) diff --git a/test/test_file_io.py b/test/test_file_io.py deleted file mode 100644 index 3760956..0000000 --- a/test/test_file_io.py +++ /dev/null @@ -1,39 +0,0 @@ -import unittest -import os -import shutil - -import makesite -from test import path - - -class FileIOTest(unittest.TestCase): - """Tests for file I/O functions.""" - - def test_fread(self): - text = 'foo\nbar\n' - filepath = path.temppath('foo.txt') - with open(filepath, 'w') as f: - f.write(text) - text_read = makesite.fread(filepath) - os.remove(filepath) - self.assertEqual(text_read, text) - - def test_fwrite(self): - text = 'baz\nqux\n' - filepath = path.temppath('foo.txt') - makesite.fwrite(filepath, text) - with open(filepath) as f: - text_read = f.read() - os.remove(filepath) - self.assertEqual(text_read, text) - - def test_fwrite_makedir(self): - text = 'baz\nqux\n' - dirpath = path.temppath('foo', 'bar') - filepath = os.path.join(dirpath, 'foo.txt') - makesite.fwrite(filepath, text) - with open(filepath) as f: - text_read = f.read() - self.assertTrue(os.path.isdir(dirpath)) - shutil.rmtree(path.temppath('foo')) - self.assertEqual(text_read, text) diff --git a/test/test_headers.py b/test/test_headers.py deleted file mode 100644 index 56eeb4a..0000000 --- a/test/test_headers.py +++ /dev/null @@ -1,43 +0,0 @@ -import unittest -import makesite - - -class HeaderTest(unittest.TestCase): - """Tests for read_headers() function.""" - - def test_single_header(self): - text = '' - headers = list(makesite.read_headers(text)) - self.assertEqual(headers, [('key1', 'val1', 19)]) - - def test_multiple_headers(self): - text = '\n' - headers = list(makesite.read_headers(text)) - self.assertEqual(headers, [('key1', 'val1', 20), ('key2', 'val2', 38)]) - - def test_headers_and_text(self): - text = '\n\nFoo\n' - headers = list(makesite.read_headers(text)) - self.assertEqual(headers, [('a', '1', 14), ('b', '2', 28)]) - - def test_headers_and_blank_line(self): - text = '\n\n\n\n' - headers = list(makesite.read_headers(text)) - self.assertEqual(headers, [('a', '1', 14), - ('b', '2', 29), - ('c', '3', 43)]) - - def test_multiline_header(self): - text = '\n' - headers = list(makesite.read_headers(text)) - self.assertEqual(headers, [('a', '1', 13), - ('b', '2', 27), - ('c', '3', 40)]) - - def test_no_header(self): - headers = list(makesite.read_headers('Foo')) - self.assertEqual(headers, []) - - def test_empty_string(self): - headers = list(makesite.read_headers('')) - self.assertEqual(headers, []) diff --git a/test/test_list.py b/test/test_list.py deleted file mode 100644 index 8acb2ef..0000000 --- a/test/test_list.py +++ /dev/null @@ -1,46 +0,0 @@ -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

') diff --git a/test/test_main.py b/test/test_main.py deleted file mode 100644 index 50f1cc5..0000000 --- a/test/test_main.py +++ /dev/null @@ -1,73 +0,0 @@ -import unittest -import makesite -import os -import shutil -import json - -from test import path - - -class MainTest(unittest.TestCase): - def setUp(self): - path.move('_site', '_site.backup') - path.move('params.json', 'params.json.backup') - - def tearDown(self): - path.move('_site.backup', '_site') - path.move('params.json.backup', 'params') - - def test_site_missing(self): - makesite.main() - - def test_site_exists(self): - os.mkdir('_site') - with open('_site/foo.txt', 'w') as f: - f.write('foo') - - self.assertTrue(os.path.isfile('_site/foo.txt')) - makesite.main() - self.assertFalse(os.path.isfile('_site/foo.txt')) - - def test_default_params(self): - makesite.main() - - with open('_site/blog/proin-quam/index.html') as f: - s1 = f.read() - - with open('_site/blog/rss.xml') as f: - s2 = f.read() - - shutil.rmtree('_site') - - self.assertIn('Home', s1) - self.assertIn('Proin Quam - Lorem Ipsum', s1) - self.assertIn('Published on 2018-01-01 by Admin', s1) - - self.assertIn('http://localhost:8000/', s2) - self.assertIn('http://localhost:8000/blog/proin-quam/', s2) - - def test_json_params(self): - params = { - 'base_path': '/base', - 'subtitle': 'Foo', - 'author': 'Bar', - 'site_url': 'http://localhost/base' - } - with open('params.json', 'w') as f: - json.dump(params, f) - makesite.main() - - with open('_site/blog/proin-quam/index.html') as f: - s1 = f.read() - - with open('_site/blog/rss.xml') as f: - s2 = f.read() - - shutil.rmtree('_site') - - self.assertIn('Home', s1) - self.assertIn('Proin Quam - Foo', s1) - self.assertIn('Published on 2018-01-01 by Bar', s1) - - self.assertIn('http://localhost/base/', s2) - self.assertIn('http://localhost/base/blog/proin-quam/', s2) diff --git a/test/test_pages.py b/test/test_pages.py deleted file mode 100644 index 0fefdaa..0000000 --- a/test/test_pages.py +++ /dev/null @@ -1,127 +0,0 @@ -import unittest -import os -import shutil -import makesite -from test import path - -class PagesTest(unittest.TestCase): - def setUp(self): - self.blog_path = path.temppath('blog') - self.site_path = path.temppath('site') - os.makedirs(self.blog_path) - - with open(os.path.join(self.blog_path, 'foo.txt'), 'w') as f: - f.write('Foo') - with open(os.path.join(self.blog_path, 'bar.txt'), 'w') as f: - f.write('Bar') - with open(os.path.join(self.blog_path, '2018-01-01-foo.txt'), 'w') as f: - f.write('Foo') - with open(os.path.join(self.blog_path, '2018-01-02-bar.txt'), 'w') as f: - f.write('Bar') - with open(os.path.join(self.blog_path, 'header-foo.txt'), 'w') as f: - f.write('Foo') - with open(os.path.join(self.blog_path, 'header-bar.txt'), 'w') as f: - f.write('Bar') - with open(os.path.join(self.blog_path, 'placeholder-foo.txt'), 'w') as f: - f.write('{{ title }}:{{ author }}:Foo') - with open(os.path.join(self.blog_path, 'placeholder-bar.txt'), 'w') as f: - f.write('{{ title }}:{{ author }}:Bar') - - def tearDown(self): - shutil.rmtree(self.blog_path) - shutil.rmtree(self.site_path) - - def test_pages_undated(self): - src = os.path.join(self.blog_path, '[fb]*.txt') - dst = os.path.join(self.site_path, '{{ slug }}.txt') - tpl = '
{{ content }}
' - makesite.make_pages(src, dst, tpl) - with open(os.path.join(self.site_path, 'foo.txt')) as f: - self.assertEqual(f.read(), '
Foo
') - with open(os.path.join(self.site_path, 'bar.txt')) as f: - self.assertEqual(f.read(), '
Bar
') - - def test_pages_dated(self): - src = os.path.join(self.blog_path, '2*.txt') - dst = os.path.join(self.site_path, '{{ slug }}.txt') - tpl = '
{{ content }}
' - makesite.make_pages(src, dst, tpl) - with open(os.path.join(self.site_path, 'foo.txt')) as f: - self.assertEqual(f.read(), '
Foo
') - with open(os.path.join(self.site_path, 'bar.txt')) as f: - self.assertEqual(f.read(), '
Bar
') - - def test_pages_layout_params(self): - src = os.path.join(self.blog_path, '2*.txt') - dst = os.path.join(self.site_path, '{{ slug }}.txt') - tpl = '
{{ slug }}:{{ title }}:{{ date }}:{{ content }}
' - makesite.make_pages(src, dst, tpl, title='Lorem') - with open(os.path.join(self.site_path, 'foo.txt')) as f: - self.assertEqual(f.read(), '
foo:Lorem:2018-01-01:Foo
') - with open(os.path.join(self.site_path, 'bar.txt')) as f: - self.assertEqual(f.read(), '
bar:Lorem:2018-01-02:Bar
') - - def test_pages_return_value(self): - src = os.path.join(self.blog_path, '2*.txt') - dst = os.path.join(self.site_path, '{{ slug }}.txt') - tpl = '
{{ content }}
' - posts = makesite.make_pages(src, dst, tpl) - self.assertEqual(len(posts), 2) - self.assertEqual(posts[0]['date'], '2018-01-02') - self.assertEqual(posts[1]['date'], '2018-01-01') - - def test_content_header_params(self): - # Test that header params from one post is not used in another - # post. - src = os.path.join(self.blog_path, 'header*.txt') - dst = os.path.join(self.site_path, '{{ slug }}.txt') - tpl = '{{ title }}:{{ tag }}:{{ content }}' - makesite.make_pages(src, dst, tpl) - with open(os.path.join(self.site_path, 'header-foo.txt')) as f: - self.assertEqual(f.read(), '{{ title }}:foo:Foo') - with open(os.path.join(self.site_path, 'header-bar.txt')) as f: - self.assertEqual(f.read(), 'bar:{{ tag }}:Bar') - - def test_content_no_rendering(self): - # Test that placeholders are not populated in content rendering - # by default. - src = os.path.join(self.blog_path, 'placeholder-foo.txt') - dst = os.path.join(self.site_path, '{{ slug }}.txt') - tpl = '
{{ content }}
' - makesite.make_pages(src, dst, tpl, author='Admin') - with open(os.path.join(self.site_path, 'placeholder-foo.txt')) as f: - self.assertEqual(f.read(), '
{{ title }}:{{ author }}:Foo
') - - def test_content_rendering_via_kwargs(self): - # Test that placeholders are populated in content rendering when - # requested in make_pages. - src = os.path.join(self.blog_path, 'placeholder-foo.txt') - dst = os.path.join(self.site_path, '{{ slug }}.txt') - tpl = '
{{ content }}
' - makesite.make_pages(src, dst, tpl, author='Admin', render='yes') - with open(os.path.join(self.site_path, 'placeholder-foo.txt')) as f: - self.assertEqual(f.read(), '
foo:Admin:Foo
') - - def test_content_rendering_via_header(self): - # Test that placeholders are populated in content rendering when - # requested in content header. - src = os.path.join(self.blog_path, 'placeholder-bar.txt') - dst = os.path.join(self.site_path, '{{ slug }}.txt') - tpl = '
{{ content }}
' - makesite.make_pages(src, dst, tpl, author='Admin') - with open(os.path.join(self.site_path, 'placeholder-bar.txt')) as f: - self.assertEqual(f.read(), '
bar:Admin:Bar
') - - def test_rendered_content_in_summary(self): - # Test that placeholders are populated in summary if and only if - # content rendering is enabled. - src = os.path.join(self.blog_path, 'placeholder*.txt') - post_dst = os.path.join(self.site_path, '{{ slug }}.txt') - list_dst = os.path.join(self.site_path, 'list.txt') - post_layout = '' - list_layout = '
{{ content }}
' - item_layout = '

{{ summary }}

' - posts = makesite.make_pages(src, post_dst, post_layout, author='Admin') - makesite.make_list(posts, list_dst, list_layout, item_layout) - with open(os.path.join(self.site_path, 'list.txt')) as f: - self.assertEqual(f.read(), '

{{ title }}:{{ author }}:Foo

bar:Admin:Bar

') diff --git a/test/test_path.py b/test/test_path.py deleted file mode 100644 index 91e76e8..0000000 --- a/test/test_path.py +++ /dev/null @@ -1,78 +0,0 @@ -import unittest -import os -import shutil - -from test import path - -class PathTest(unittest.TestCase): - def test_temppath(self): - self.assertTrue(path.temppath()) - - def test_move_existing_file(self): - src = os.path.join(path.temppath(), 'foo.txt') - dst = os.path.join(path.temppath(), 'bar.txt') - with open(src, 'w') as f: - f.write('foo') - - path.move(src, dst) - self.assertFalse(os.path.isfile(src)) - self.assertTrue(os.path.isfile(dst)) - - with open(dst) as f: - text = f.read() - - os.remove(dst) - - self.assertEqual(text, 'foo') - - def test_move_missing_file(self): - src = os.path.join(path.temppath(), 'foo.txt') - dst = os.path.join(path.temppath(), 'bar.txt') - path.move(src, dst) - self.assertFalse(os.path.isfile(src)) - self.assertFalse(os.path.isfile(dst)) - - def test_move_file_cleanup(self): - src = os.path.join(path.temppath(), 'foo.txt') - dst = os.path.join(path.temppath(), 'bar.txt') - with open(dst, 'w') as f: - f.write('foo') - path.move(src, dst) - self.assertFalse(os.path.isfile(src)) - self.assertFalse(os.path.isfile(dst)) - - def test_move_existing_dir(self): - src = os.path.join(path.temppath(), 'foo') - srcf = os.path.join(src, 'foo.txt') - dst = os.path.join(path.temppath(), 'bar') - dstf = os.path.join(dst, 'foo.txt') - - os.makedirs(src) - with open(srcf, 'w') as f: - f.write('foo') - - path.move(src, dst) - self.assertFalse(os.path.isdir(src)) - self.assertTrue(os.path.isdir(dst)) - - with open(dstf) as f: - text = f.read() - - shutil.rmtree(dst) - - self.assertEqual(text, 'foo') - - def test_move_missing_dir(self): - src = os.path.join(path.temppath(), 'foo') - dst = os.path.join(path.temppath(), 'bar') - path.move(src, dst) - self.assertFalse(os.path.isdir(src)) - self.assertFalse(os.path.isdir(dst)) - - def test_move_dir_cleanup(self): - src = os.path.join(path.temppath(), 'foo') - dst = os.path.join(path.temppath(), 'bar') - os.makedirs(dst) - path.move(src, dst) - self.assertFalse(os.path.isdir(src)) - self.assertFalse(os.path.isdir(dst)) diff --git a/test/test_render.py b/test/test_render.py deleted file mode 100644 index e036b70..0000000 --- a/test/test_render.py +++ /dev/null @@ -1,25 +0,0 @@ -import unittest -import makesite - -class RenderTest(unittest.TestCase): - """Tests for render() function.""" - - def test_oneline_template(self): - tpl = 'foo {{ key1 }} baz {{ key2 }}' - out = makesite.render(tpl, key1='bar', key2='qux') - self.assertEqual(out, 'foo bar baz qux') - - def test_multiline_template(self): - tpl = 'foo {{ key1 }}\nbaz {{ key1 }}' - out = makesite.render(tpl, key1='bar') - self.assertEqual(out, 'foo bar\nbaz bar') - - def test_repeated_key(self): - tpl = 'foo {{ key1 }} baz {{ key1 }}' - out = makesite.render(tpl, key1='bar') - self.assertEqual(out, 'foo bar baz bar') - - def test_multiline_placeholder(self): - tpl = 'foo {{\nkey1\n}} baz {{\nkey2\n}}' - out = makesite.render(tpl, key1='bar', key2='qux') - self.assertEqual(out, 'foo bar baz qux') diff --git a/test/test_rfc_2822_date.py b/test/test_rfc_2822_date.py deleted file mode 100644 index db9970f..0000000 --- a/test/test_rfc_2822_date.py +++ /dev/null @@ -1,13 +0,0 @@ -import unittest -import makesite - - -class RFC822DateTest(unittest.TestCase): - - def test_epoch(self): - self.assertEqual(makesite.rfc_2822_format('1970-01-01'), - 'Thu, 01 Jan 1970 00:00:00 +0000') - - def test_2018_06_16(self): - self.assertEqual(makesite.rfc_2822_format('2018-06-16'), - 'Sat, 16 Jun 2018 00:00:00 +0000') diff --git a/test/test_truncate.py b/test/test_truncate.py deleted file mode 100644 index 3486d71..0000000 --- a/test/test_truncate.py +++ /dev/null @@ -1,9 +0,0 @@ -import unittest -import makesite - - -class TruncateTest(unittest.TestCase): - def test_truncate(self): - long_text = ' \n'.join('word' + str(i) for i in range(50)) - expected_text = ' '.join('word' + str(i) for i in range(25)) - self.assertEqual(makesite.truncate(long_text), expected_text)