mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
tests: Update tests after filename/filepath -> source_path
This commit is contained in:
parent
9b574361c9
commit
54a9132aea
4 changed files with 29 additions and 29 deletions
|
|
@ -229,20 +229,20 @@ class TestTemplatePagesGenerator(unittest.TestCase):
|
||||||
|
|
||||||
# create a dummy template file
|
# create a dummy template file
|
||||||
template_dir = os.path.join(self.temp_content, 'template')
|
template_dir = os.path.join(self.temp_content, 'template')
|
||||||
template_filename = os.path.join(template_dir, 'source.html')
|
template_path = os.path.join(template_dir, 'source.html')
|
||||||
os.makedirs(template_dir)
|
os.makedirs(template_dir)
|
||||||
with open(template_filename, 'w') as template_file:
|
with open(template_path, 'w') as template_file:
|
||||||
template_file.write(self.TEMPLATE_CONTENT)
|
template_file.write(self.TEMPLATE_CONTENT)
|
||||||
|
|
||||||
writer = Writer(self.temp_output, settings=settings)
|
writer = Writer(self.temp_output, settings=settings)
|
||||||
generator.generate_output(writer)
|
generator.generate_output(writer)
|
||||||
|
|
||||||
output_filename = os.path.join(
|
output_path = os.path.join(
|
||||||
self.temp_output, 'generated', 'file.html')
|
self.temp_output, 'generated', 'file.html')
|
||||||
|
|
||||||
# output file has been generated
|
# output file has been generated
|
||||||
self.assertTrue(os.path.exists(output_filename))
|
self.assertTrue(os.path.exists(output_path))
|
||||||
|
|
||||||
# output content is correct
|
# output content is correct
|
||||||
with open(output_filename, 'r') as output_file:
|
with open(output_path, 'r') as output_file:
|
||||||
self.assertEquals(output_file.read(), 'foo: bar')
|
self.assertEquals(output_file.read(), 'foo: bar')
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ class TestPelican(unittest.TestCase):
|
||||||
def test_basic_generation_works(self):
|
def test_basic_generation_works(self):
|
||||||
# when running pelican without settings, it should pick up the default
|
# when running pelican without settings, it should pick up the default
|
||||||
# ones and generate correct output without raising any exception
|
# ones and generate correct output without raising any exception
|
||||||
settings = read_settings(filename=None, override={
|
settings = read_settings(path=None, override={
|
||||||
'PATH': INPUT_PATH,
|
'PATH': INPUT_PATH,
|
||||||
'OUTPUT_PATH': self.temp_path,
|
'OUTPUT_PATH': self.temp_path,
|
||||||
'LOCALE': locale.normalize('en_US'),
|
'LOCALE': locale.normalize('en_US'),
|
||||||
|
|
@ -86,7 +86,7 @@ class TestPelican(unittest.TestCase):
|
||||||
|
|
||||||
def test_custom_generation_works(self):
|
def test_custom_generation_works(self):
|
||||||
# the same thing with a specified set of settings should work
|
# the same thing with a specified set of settings should work
|
||||||
settings = read_settings(filename=SAMPLE_CONFIG, override={
|
settings = read_settings(path=SAMPLE_CONFIG, override={
|
||||||
'PATH': INPUT_PATH,
|
'PATH': INPUT_PATH,
|
||||||
'OUTPUT_PATH': self.temp_path,
|
'OUTPUT_PATH': self.temp_path,
|
||||||
'LOCALE': locale.normalize('en_US'),
|
'LOCALE': locale.normalize('en_US'),
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ CUR_DIR = os.path.dirname(__file__)
|
||||||
CONTENT_PATH = os.path.join(CUR_DIR, 'content')
|
CONTENT_PATH = os.path.join(CUR_DIR, 'content')
|
||||||
|
|
||||||
|
|
||||||
def _filename(*args):
|
def _path(*args):
|
||||||
return os.path.join(CONTENT_PATH, *args)
|
return os.path.join(CONTENT_PATH, *args)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ class RstReaderTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_article_with_metadata(self):
|
def test_article_with_metadata(self):
|
||||||
reader = readers.RstReader({})
|
reader = readers.RstReader({})
|
||||||
content, metadata = reader.read(_filename('article_with_metadata.rst'))
|
content, metadata = reader.read(_path('article_with_metadata.rst'))
|
||||||
expected = {
|
expected = {
|
||||||
'category': 'yeah',
|
'category': 'yeah',
|
||||||
'author': 'Alexis Métaireau',
|
'author': 'Alexis Métaireau',
|
||||||
|
|
@ -37,7 +37,7 @@ class RstReaderTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_article_with_filename_metadata(self):
|
def test_article_with_filename_metadata(self):
|
||||||
content, metadata = readers.read_file(
|
content, metadata = readers.read_file(
|
||||||
_filename('2012-11-29_rst_w_filename_meta#foo-bar.rst'),
|
_path('2012-11-29_rst_w_filename_meta#foo-bar.rst'),
|
||||||
settings={})
|
settings={})
|
||||||
expected = {
|
expected = {
|
||||||
'category': 'yeah',
|
'category': 'yeah',
|
||||||
|
|
@ -48,7 +48,7 @@ class RstReaderTest(unittest.TestCase):
|
||||||
self.assertEquals(value, expected[key], key)
|
self.assertEquals(value, expected[key], key)
|
||||||
|
|
||||||
content, metadata = readers.read_file(
|
content, metadata = readers.read_file(
|
||||||
_filename('2012-11-29_rst_w_filename_meta#foo-bar.rst'),
|
_path('2012-11-29_rst_w_filename_meta#foo-bar.rst'),
|
||||||
settings={
|
settings={
|
||||||
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2}).*'
|
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2}).*'
|
||||||
})
|
})
|
||||||
|
|
@ -62,7 +62,7 @@ class RstReaderTest(unittest.TestCase):
|
||||||
self.assertEquals(value, expected[key], key)
|
self.assertEquals(value, expected[key], key)
|
||||||
|
|
||||||
content, metadata = readers.read_file(
|
content, metadata = readers.read_file(
|
||||||
_filename('2012-11-29_rst_w_filename_meta#foo-bar.rst'),
|
_path('2012-11-29_rst_w_filename_meta#foo-bar.rst'),
|
||||||
settings={
|
settings={
|
||||||
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2})_' \
|
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2})_' \
|
||||||
'_(?P<Slug>.*)' \
|
'_(?P<Slug>.*)' \
|
||||||
|
|
@ -82,7 +82,7 @@ class RstReaderTest(unittest.TestCase):
|
||||||
def test_article_metadata_key_lowercase(self):
|
def test_article_metadata_key_lowercase(self):
|
||||||
"""Keys of metadata should be lowercase."""
|
"""Keys of metadata should be lowercase."""
|
||||||
reader = readers.RstReader({})
|
reader = readers.RstReader({})
|
||||||
content, metadata = reader.read(_filename('article_with_uppercase_metadata.rst'))
|
content, metadata = reader.read(_path('article_with_uppercase_metadata.rst'))
|
||||||
|
|
||||||
self.assertIn('category', metadata, "Key should be lowercase.")
|
self.assertIn('category', metadata, "Key should be lowercase.")
|
||||||
self.assertEquals('Yeah', metadata.get('category'), "Value keeps cases.")
|
self.assertEquals('Yeah', metadata.get('category'), "Value keeps cases.")
|
||||||
|
|
@ -90,7 +90,7 @@ class RstReaderTest(unittest.TestCase):
|
||||||
def test_typogrify(self):
|
def test_typogrify(self):
|
||||||
# if nothing is specified in the settings, the content should be
|
# if nothing is specified in the settings, the content should be
|
||||||
# unmodified
|
# unmodified
|
||||||
content, _ = readers.read_file(_filename('article.rst'))
|
content, _ = readers.read_file(_path('article.rst'))
|
||||||
expected = "<p>This is some content. With some stuff to "\
|
expected = "<p>This is some content. With some stuff to "\
|
||||||
""typogrify".</p>\n<p>Now with added "\
|
""typogrify".</p>\n<p>Now with added "\
|
||||||
'support for <abbr title="three letter acronym">'\
|
'support for <abbr title="three letter acronym">'\
|
||||||
|
|
@ -100,7 +100,7 @@ class RstReaderTest(unittest.TestCase):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# otherwise, typogrify should be applied
|
# otherwise, typogrify should be applied
|
||||||
content, _ = readers.read_file(_filename('article.rst'),
|
content, _ = readers.read_file(_path('article.rst'),
|
||||||
settings={'TYPOGRIFY': True})
|
settings={'TYPOGRIFY': True})
|
||||||
expected = "<p>This is some content. With some stuff to "\
|
expected = "<p>This is some content. With some stuff to "\
|
||||||
"“typogrify”.</p>\n<p>Now with added "\
|
"“typogrify”.</p>\n<p>Now with added "\
|
||||||
|
|
@ -118,7 +118,7 @@ class MdReaderTest(unittest.TestCase):
|
||||||
def test_article_with_md_extension(self):
|
def test_article_with_md_extension(self):
|
||||||
# test to ensure the md extension is being processed by the correct reader
|
# test to ensure the md extension is being processed by the correct reader
|
||||||
reader = readers.MarkdownReader({})
|
reader = readers.MarkdownReader({})
|
||||||
content, metadata = reader.read(_filename('article_with_md_extension.md'))
|
content, metadata = reader.read(_path('article_with_md_extension.md'))
|
||||||
expected = "<h1>Test Markdown File Header</h1>\n"\
|
expected = "<h1>Test Markdown File Header</h1>\n"\
|
||||||
"<h2>Used for pelican test</h2>\n"\
|
"<h2>Used for pelican test</h2>\n"\
|
||||||
"<p>The quick brown fox jumped over the lazy dog's back.</p>"
|
"<p>The quick brown fox jumped over the lazy dog's back.</p>"
|
||||||
|
|
@ -136,7 +136,7 @@ class MdReaderTest(unittest.TestCase):
|
||||||
def test_article_with_mkd_extension(self):
|
def test_article_with_mkd_extension(self):
|
||||||
# test to ensure the mkd extension is being processed by the correct reader
|
# test to ensure the mkd extension is being processed by the correct reader
|
||||||
reader = readers.MarkdownReader({})
|
reader = readers.MarkdownReader({})
|
||||||
content, metadata = reader.read(_filename('article_with_mkd_extension.mkd'))
|
content, metadata = reader.read(_path('article_with_mkd_extension.mkd'))
|
||||||
expected = "<h1>Test Markdown File Header</h1>\n"\
|
expected = "<h1>Test Markdown File Header</h1>\n"\
|
||||||
"<h2>Used for pelican test</h2>\n"\
|
"<h2>Used for pelican test</h2>\n"\
|
||||||
"<p>This is another markdown test file. Uses the mkd extension.</p>"
|
"<p>This is another markdown test file. Uses the mkd extension.</p>"
|
||||||
|
|
@ -147,7 +147,7 @@ class MdReaderTest(unittest.TestCase):
|
||||||
def test_article_with_markdown_markup_extension(self):
|
def test_article_with_markdown_markup_extension(self):
|
||||||
# test to ensure the markdown markup extension is being processed as expected
|
# test to ensure the markdown markup extension is being processed as expected
|
||||||
content, metadata = readers.read_file(
|
content, metadata = readers.read_file(
|
||||||
_filename('article_with_markdown_markup_extensions.md'),
|
_path('article_with_markdown_markup_extensions.md'),
|
||||||
settings={'MD_EXTENSIONS': ['toc', 'codehilite', 'extra']})
|
settings={'MD_EXTENSIONS': ['toc', 'codehilite', 'extra']})
|
||||||
expected = '<div class="toc">\n'\
|
expected = '<div class="toc">\n'\
|
||||||
'<ul>\n'\
|
'<ul>\n'\
|
||||||
|
|
@ -165,7 +165,7 @@ class MdReaderTest(unittest.TestCase):
|
||||||
@unittest.skipUnless(readers.Markdown, "markdown isn't installed")
|
@unittest.skipUnless(readers.Markdown, "markdown isn't installed")
|
||||||
def test_article_with_filename_metadata(self):
|
def test_article_with_filename_metadata(self):
|
||||||
content, metadata = readers.read_file(
|
content, metadata = readers.read_file(
|
||||||
_filename('2012-11-30_md_w_filename_meta#foo-bar.md'),
|
_path('2012-11-30_md_w_filename_meta#foo-bar.md'),
|
||||||
settings={})
|
settings={})
|
||||||
expected = {
|
expected = {
|
||||||
'category': 'yeah',
|
'category': 'yeah',
|
||||||
|
|
@ -175,7 +175,7 @@ class MdReaderTest(unittest.TestCase):
|
||||||
self.assertEquals(value, metadata[key], key)
|
self.assertEquals(value, metadata[key], key)
|
||||||
|
|
||||||
content, metadata = readers.read_file(
|
content, metadata = readers.read_file(
|
||||||
_filename('2012-11-30_md_w_filename_meta#foo-bar.md'),
|
_path('2012-11-30_md_w_filename_meta#foo-bar.md'),
|
||||||
settings={
|
settings={
|
||||||
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2}).*'
|
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2}).*'
|
||||||
})
|
})
|
||||||
|
|
@ -188,7 +188,7 @@ class MdReaderTest(unittest.TestCase):
|
||||||
self.assertEquals(value, metadata[key], key)
|
self.assertEquals(value, metadata[key], key)
|
||||||
|
|
||||||
content, metadata = readers.read_file(
|
content, metadata = readers.read_file(
|
||||||
_filename('2012-11-30_md_w_filename_meta#foo-bar.md'),
|
_path('2012-11-30_md_w_filename_meta#foo-bar.md'),
|
||||||
settings={
|
settings={
|
||||||
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2})'
|
'FILENAME_METADATA': '(?P<date>\d{4}-\d{2}-\d{2})'
|
||||||
'_(?P<Slug>.*)'
|
'_(?P<Slug>.*)'
|
||||||
|
|
@ -210,7 +210,7 @@ class AdReaderTest(unittest.TestCase):
|
||||||
def test_article_with_asc_extension(self):
|
def test_article_with_asc_extension(self):
|
||||||
# test to ensure the asc extension is being processed by the correct reader
|
# test to ensure the asc extension is being processed by the correct reader
|
||||||
reader = readers.AsciiDocReader({})
|
reader = readers.AsciiDocReader({})
|
||||||
content, metadata = reader.read(_filename('article_with_asc_extension.asc'))
|
content, metadata = reader.read(_path('article_with_asc_extension.asc'))
|
||||||
expected = '<hr>\n<h2><a name="_used_for_pelican_test"></a>Used for pelican test</h2>\n'\
|
expected = '<hr>\n<h2><a name="_used_for_pelican_test"></a>Used for pelican test</h2>\n'\
|
||||||
'<p>The quick brown fox jumped over the lazy dog’s back.</p>\n'
|
'<p>The quick brown fox jumped over the lazy dog’s back.</p>\n'
|
||||||
self.assertEqual(content, expected)
|
self.assertEqual(content, expected)
|
||||||
|
|
@ -241,7 +241,7 @@ class AdReaderTest(unittest.TestCase):
|
||||||
def test_article_with_asc_options(self):
|
def test_article_with_asc_options(self):
|
||||||
# test to ensure the ASCIIDOC_OPTIONS is being used
|
# test to ensure the ASCIIDOC_OPTIONS is being used
|
||||||
reader = readers.AsciiDocReader(dict(ASCIIDOC_OPTIONS=["-a revision=1.0.42"]))
|
reader = readers.AsciiDocReader(dict(ASCIIDOC_OPTIONS=["-a revision=1.0.42"]))
|
||||||
content, metadata = reader.read(_filename('article_with_asc_options.asc'))
|
content, metadata = reader.read(_path('article_with_asc_options.asc'))
|
||||||
expected = '<hr>\n<h2><a name="_used_for_pelican_test"></a>Used for pelican test</h2>\n'\
|
expected = '<hr>\n<h2><a name="_used_for_pelican_test"></a>Used for pelican test</h2>\n'\
|
||||||
'<p>version 1.0.42</p>\n'\
|
'<p>version 1.0.42</p>\n'\
|
||||||
'<p>The quick brown fox jumped over the lazy dog’s back.</p>\n'
|
'<p>The quick brown fox jumped over the lazy dog’s back.</p>\n'
|
||||||
|
|
|
||||||
|
|
@ -79,17 +79,17 @@ class TestUtils(unittest.TestCase):
|
||||||
"""Test if file changes are correctly detected
|
"""Test if file changes are correctly detected
|
||||||
Make sure to handle not getting any files correctly"""
|
Make sure to handle not getting any files correctly"""
|
||||||
|
|
||||||
path = os.path.join(os.path.dirname(__file__), 'content')
|
dirname = os.path.join(os.path.dirname(__file__), 'content')
|
||||||
filename = os.path.join(path, 'article_with_metadata.rst')
|
path = os.path.join(dirname, 'article_with_metadata.rst')
|
||||||
changed = utils.files_changed(path, 'rst')
|
changed = utils.files_changed(dirname, 'rst')
|
||||||
self.assertEquals(changed, True)
|
self.assertEquals(changed, True)
|
||||||
|
|
||||||
changed = utils.files_changed(path, 'rst')
|
changed = utils.files_changed(dirname, 'rst')
|
||||||
self.assertEquals(changed, False)
|
self.assertEquals(changed, False)
|
||||||
|
|
||||||
t = time.time()
|
t = time.time()
|
||||||
os.utime(filename, (t, t))
|
os.utime(path, (t, t))
|
||||||
changed = utils.files_changed(path, 'rst')
|
changed = utils.files_changed(dirname, 'rst')
|
||||||
self.assertEquals(changed, True)
|
self.assertEquals(changed, True)
|
||||||
self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1)
|
self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue