mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fix test_pelican.py #3374
Make it work from any directory within the Pelican package. Also fixes parallelism.
This commit is contained in:
parent
13866b5742
commit
b6bce8d78b
3 changed files with 33 additions and 6 deletions
|
|
@ -550,11 +550,12 @@ def get_instance(args):
|
|||
config_settings_file = args.settings
|
||||
if config_settings_file is None:
|
||||
if os.path.isfile(DEFAULT_CONFIG_NAME):
|
||||
config_settings_file = DEFAULT_CONFIG_NAME
|
||||
args.settings = DEFAULT_CONFIG_NAME
|
||||
config_settings_file = DEFAULT_CONFIG_NAME # relative path to $CWD
|
||||
args.settings = DEFAULT_CONFIG_NAME # relative path to $CWD
|
||||
else:
|
||||
config_settings_file = "pelicanconf.py"
|
||||
args.settings = "pelicanconf.py"
|
||||
err_msg = f"Configuration {config_settings_file} file is not found."
|
||||
logger.error(err_msg)
|
||||
raise FileNotFoundError(err_msg)
|
||||
|
||||
settings = read_settings(config_settings_file, override=get_config(args))
|
||||
|
||||
|
|
|
|||
1
pelican/tests/settings/pelicanconf.py
Normal file
1
pelican/tests/settings/pelicanconf.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
PATH = "content"
|
||||
|
|
@ -272,11 +272,19 @@ class TestPelican(LoggedTestCase):
|
|||
|
||||
def test_module_load(self):
|
||||
"""Test loading via python -m pelican --help displays the help"""
|
||||
tests_subdir = os.path.dirname(__file__) # anchor to 'tests' directory
|
||||
pelican_srcdir = os.path.dirname(tests_subdir)
|
||||
pelican_pkgdir = os.path.dirname(pelican_srcdir)
|
||||
original_cwd = os.getcwd()
|
||||
os.chdir(pelican_pkgdir)
|
||||
output = subprocess.check_output(
|
||||
[sys.executable, "-m", "pelican", "--help"]
|
||||
).decode("ascii", "replace")
|
||||
|
||||
assert "usage:" in output
|
||||
|
||||
os.chdir(original_cwd)
|
||||
|
||||
def test_main_version(self):
|
||||
"""Run main --version."""
|
||||
out = io.StringIO()
|
||||
|
|
@ -295,19 +303,32 @@ class TestPelican(LoggedTestCase):
|
|||
|
||||
def test_main_on_content(self):
|
||||
"""Invoke main on simple_content directory."""
|
||||
content_subdir = "pelican/tests/simple_content"
|
||||
tests_subdir = os.path.dirname(__file__) # anchor to 'tests' directory
|
||||
pelican_srcdir = os.path.dirname(tests_subdir)
|
||||
pelican_pkgdir = os.path.dirname(pelican_srcdir)
|
||||
original_cwd = os.getcwd()
|
||||
os.chdir(pelican_pkgdir)
|
||||
content_subdir = "pelican/tests/simple_content" # from pelican_pkgdir POV
|
||||
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, content_subdir])
|
||||
|
||||
self.assertIn("Processed 1 article", out.getvalue())
|
||||
self.assertEqual("", err.getvalue())
|
||||
|
||||
os.chdir(original_cwd)
|
||||
|
||||
def test_main_on_content_markdown_disabled(self):
|
||||
"""Invoke main on simple_content directory."""
|
||||
tests_subdir = os.path.dirname(__file__) # anchor to 'tests' directory
|
||||
settings_subdir = tests_subdir + os.sep + "settings"
|
||||
settings_file = settings_subdir + os.sep + "pelicanconf.py"
|
||||
content_subdir = tests_subdir + os.sep + "simple_content"
|
||||
with patch.object(
|
||||
pelican.readers.MarkdownReader, "enabled", new_callable=PropertyMock
|
||||
) as attr_mock:
|
||||
|
|
@ -318,7 +339,7 @@ class TestPelican(LoggedTestCase):
|
|||
# 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"])
|
||||
main(["-o", temp_dir, "-s", settings_file, content_subdir])
|
||||
self.assertIn("Processed 0 articles", out.getvalue())
|
||||
self.assertLogCountEqual(
|
||||
1,
|
||||
|
|
@ -326,3 +347,7 @@ class TestPelican(LoggedTestCase):
|
|||
"Could not import 'markdown.Markdown'. "
|
||||
"Have you installed the 'markdown' package?",
|
||||
)
|
||||
|
||||
|
||||
if __file__ == "main":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue