Skip to content

Commit

Permalink
test_pelican, CWD-independence
Browse files Browse the repository at this point in the history
  • Loading branch information
egberts committed Jul 22, 2024
1 parent 513abbf commit 13866b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions pelican/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,16 @@ def get_config(args):


def get_instance(args):
config_file = args.settings
if config_file is None and os.path.isfile(DEFAULT_CONFIG_NAME):
config_file = DEFAULT_CONFIG_NAME
args.settings = DEFAULT_CONFIG_NAME
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
else:
config_settings_file = "pelicanconf.py"
args.settings = "pelicanconf.py"

settings = read_settings(config_file, override=get_config(args))
settings = read_settings(config_settings_file, override=get_config(args))

cls = settings["PELICAN_CLASS"]
if isinstance(cls, str):
Expand Down
3 changes: 2 additions & 1 deletion pelican/tests/test_pelican.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,14 @@ def test_main_help(self):

def test_main_on_content(self):
"""Invoke main on simple_content directory."""
content_subdir = "pelican/tests/simple_content"
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"])
main(["-o", temp_dir, content_subdir])
self.assertIn("Processed 1 article", out.getvalue())
self.assertEqual("", err.getvalue())

Expand Down

0 comments on commit 13866b5

Please sign in to comment.