Remove unit tests
This commit is contained in:
parent
7a41f3cecf
commit
22a8fd6ba8
12 changed files with 0 additions and 573 deletions
16
test/path.py
16
test/path.py
|
@ -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)
|
|
@ -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('<!-- a: 1 -->\n<!-- b: 2 -->\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'], '<p><em>Foo</em></p>\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)
|
|
@ -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)
|
|
@ -1,43 +0,0 @@
|
|||
import unittest
|
||||
import makesite
|
||||
|
||||
|
||||
class HeaderTest(unittest.TestCase):
|
||||
"""Tests for read_headers() function."""
|
||||
|
||||
def test_single_header(self):
|
||||
text = '<!-- key1: val1 -->'
|
||||
headers = list(makesite.read_headers(text))
|
||||
self.assertEqual(headers, [('key1', 'val1', 19)])
|
||||
|
||||
def test_multiple_headers(self):
|
||||
text = '<!-- key1: val1 -->\n<!-- key2: val2-->'
|
||||
headers = list(makesite.read_headers(text))
|
||||
self.assertEqual(headers, [('key1', 'val1', 20), ('key2', 'val2', 38)])
|
||||
|
||||
def test_headers_and_text(self):
|
||||
text = '<!-- a: 1 -->\n<!-- b: 2 -->\nFoo\n<!-- c: 3 -->'
|
||||
headers = list(makesite.read_headers(text))
|
||||
self.assertEqual(headers, [('a', '1', 14), ('b', '2', 28)])
|
||||
|
||||
def test_headers_and_blank_line(self):
|
||||
text = '<!-- a: 1 -->\n<!-- b: 2 -->\n\n<!-- c: 3 -->\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 = '<!--\na: 1 --><!-- b:\n2 -->\n<!-- c: 3\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, [])
|
|
@ -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 = '<div>{{ content }}</div>'
|
||||
item_layout = '<p>{{ content }}</p>'
|
||||
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(), '<div><p>Foo</p><p>Bar</p></div>')
|
||||
|
||||
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 = '<div>{{ key }}:{{ title }}:{{ content }}</div>'
|
||||
item_layout = '<p>{{ key }}:{{ title }}:{{ content }}</p>'
|
||||
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,
|
||||
'<div>val:lorem:<p>val:foo:Foo</p><p>val:bar:Bar</p></div>')
|
||||
|
||||
def test_dst_params(self):
|
||||
posts = [{'content': 'Foo'}, {'content': 'Bar'}]
|
||||
dst = os.path.join(self.site_path, '{{ key }}.txt')
|
||||
list_layout = '<div>{{ content }}</div>'
|
||||
item_layout = '<p>{{ content }}</p>'
|
||||
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(), '<div><p>Foo</p><p>Bar</p></div>')
|
|
@ -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('<a href="/">Home</a>', s1)
|
||||
self.assertIn('<title>Proin Quam - Lorem Ipsum</title>', s1)
|
||||
self.assertIn('Published on 2018-01-01 by <b>Admin</b>', s1)
|
||||
|
||||
self.assertIn('<link>http://localhost:8000/</link>', s2)
|
||||
self.assertIn('<link>http://localhost:8000/blog/proin-quam/</link>', 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('<a href="/base/">Home</a>', s1)
|
||||
self.assertIn('<title>Proin Quam - Foo</title>', s1)
|
||||
self.assertIn('Published on 2018-01-01 by <b>Bar</b>', s1)
|
||||
|
||||
self.assertIn('<link>http://localhost/base/</link>', s2)
|
||||
self.assertIn('<link>http://localhost/base/blog/proin-quam/</link>', s2)
|
|
@ -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('<!-- tag: foo -->Foo')
|
||||
with open(os.path.join(self.blog_path, 'header-bar.txt'), 'w') as f:
|
||||
f.write('<!-- title: bar -->Bar')
|
||||
with open(os.path.join(self.blog_path, 'placeholder-foo.txt'), 'w') as f:
|
||||
f.write('<!-- title: foo -->{{ title }}:{{ author }}:Foo')
|
||||
with open(os.path.join(self.blog_path, 'placeholder-bar.txt'), 'w') as f:
|
||||
f.write('<!-- title: bar --><!-- render: yes -->{{ 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 = '<div>{{ content }}</div>'
|
||||
makesite.make_pages(src, dst, tpl)
|
||||
with open(os.path.join(self.site_path, 'foo.txt')) as f:
|
||||
self.assertEqual(f.read(), '<div>Foo</div>')
|
||||
with open(os.path.join(self.site_path, 'bar.txt')) as f:
|
||||
self.assertEqual(f.read(), '<div>Bar</div>')
|
||||
|
||||
def test_pages_dated(self):
|
||||
src = os.path.join(self.blog_path, '2*.txt')
|
||||
dst = os.path.join(self.site_path, '{{ slug }}.txt')
|
||||
tpl = '<div>{{ content }}</div>'
|
||||
makesite.make_pages(src, dst, tpl)
|
||||
with open(os.path.join(self.site_path, 'foo.txt')) as f:
|
||||
self.assertEqual(f.read(), '<div>Foo</div>')
|
||||
with open(os.path.join(self.site_path, 'bar.txt')) as f:
|
||||
self.assertEqual(f.read(), '<div>Bar</div>')
|
||||
|
||||
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 = '<div>{{ slug }}:{{ title }}:{{ date }}:{{ content }}</div>'
|
||||
makesite.make_pages(src, dst, tpl, title='Lorem')
|
||||
with open(os.path.join(self.site_path, 'foo.txt')) as f:
|
||||
self.assertEqual(f.read(), '<div>foo:Lorem:2018-01-01:Foo</div>')
|
||||
with open(os.path.join(self.site_path, 'bar.txt')) as f:
|
||||
self.assertEqual(f.read(), '<div>bar:Lorem:2018-01-02:Bar</div>')
|
||||
|
||||
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 = '<div>{{ content }}</div>'
|
||||
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 = '<div>{{ content }}</div>'
|
||||
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(), '<div>{{ title }}:{{ author }}:Foo</div>')
|
||||
|
||||
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 = '<div>{{ content }}</div>'
|
||||
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(), '<div>foo:Admin:Foo</div>')
|
||||
|
||||
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 = '<div>{{ content }}</div>'
|
||||
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(), '<div>bar:Admin:Bar</div>')
|
||||
|
||||
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 = '<div>{{ content }}</div>'
|
||||
item_layout = '<p>{{ summary }}</p>'
|
||||
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(), '<div><p>{{ title }}:{{ author }}:Foo</p><p>bar:Admin:Bar</p></div>')
|
|
@ -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))
|
|
@ -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')
|
|
@ -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')
|
|
@ -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)
|
Loading…
Add table
Reference in a new issue