forked from github/pelican
Merge pull request #3321 from boxydog/warn_about_markdown
This commit is contained in:
commit
f89f8894cc
7 changed files with 119 additions and 13 deletions
|
|
@ -9,10 +9,11 @@ import unittest
|
|||
from collections.abc import Sequence
|
||||
from shutil import rmtree
|
||||
from tempfile import TemporaryDirectory, mkdtemp
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import PropertyMock, patch
|
||||
|
||||
from rich.console import Console
|
||||
|
||||
import pelican.readers
|
||||
from pelican import Pelican, __version__, main
|
||||
from pelican.generators import StaticGenerator
|
||||
from pelican.settings import read_settings
|
||||
|
|
@ -303,3 +304,24 @@ class TestPelican(LoggedTestCase):
|
|||
main(["-o", temp_dir, "pelican/tests/simple_content"])
|
||||
self.assertIn("Processed 1 article", out.getvalue())
|
||||
self.assertEqual("", err.getvalue())
|
||||
|
||||
def test_main_on_content_markdown_disabled(self):
|
||||
"""Invoke main on simple_content directory."""
|
||||
with patch.object(
|
||||
pelican.readers.MarkdownReader, "enabled", new_callable=PropertyMock
|
||||
) as attr_mock:
|
||||
attr_mock.return_value = False
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
with TemporaryDirectory() as temp_dir:
|
||||
# Don't highlight anything.
|
||||
# See https://rich.readthedocs.io/en/stable/highlighting.html
|
||||
with patch("pelican.console", new=Console(highlight=False)):
|
||||
main(["-o", temp_dir, "pelican/tests/simple_content"])
|
||||
self.assertIn("Processed 0 articles", out.getvalue())
|
||||
self.assertLogCountEqual(
|
||||
1,
|
||||
".*article_with_md_extension.md: "
|
||||
"Could not import markdown.Markdown. "
|
||||
"Have you installed the markdown package?",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import PropertyMock, patch
|
||||
|
||||
from pelican import readers
|
||||
from pelican.tests.support import get_settings, unittest
|
||||
|
|
@ -32,6 +32,19 @@ class ReaderTest(unittest.TestCase):
|
|||
else:
|
||||
self.fail(f"Expected {key} to have value {value}, but was not in Dict")
|
||||
|
||||
def test_markdown_disabled(self):
|
||||
with patch.object(
|
||||
readers.MarkdownReader, "enabled", new_callable=PropertyMock
|
||||
) as attr_mock:
|
||||
attr_mock.return_value = False
|
||||
readrs = readers.Readers(settings=get_settings())
|
||||
self.assertEqual(
|
||||
set(readers.MarkdownReader.file_extensions),
|
||||
readrs.disabled_readers.keys(),
|
||||
)
|
||||
for val in readrs.disabled_readers.values():
|
||||
self.assertEqual(readers.MarkdownReader, val.__class__)
|
||||
|
||||
|
||||
class TestAssertDictHasSubset(ReaderTest):
|
||||
def setUp(self):
|
||||
|
|
|
|||
|
|
@ -966,3 +966,10 @@ class TestMemoized(unittest.TestCase):
|
|||
container.get.cache.clear()
|
||||
self.assertEqual("bar", container.get("bar"))
|
||||
get_mock.assert_called_once_with("bar")
|
||||
|
||||
|
||||
class TestStringUtils(unittest.TestCase):
|
||||
def test_file_suffix(self):
|
||||
self.assertEqual("", utils.file_suffix(""))
|
||||
self.assertEqual("", utils.file_suffix("foo"))
|
||||
self.assertEqual("md", utils.file_suffix("foo.md"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue