This commit is contained in:
Sai Asish Y 2026-08-26 02:58:55 -07:00 committed by GitHub
commit 7f4cc14bcb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View file

@ -16,7 +16,11 @@ from pelican.paginator import PaginationRule
def load_source(name: str, path: str) -> ModuleType:
if not os.path.isfile(path):
raise FileNotFoundError(f"Settings file not found: {path}")
spec = importlib.util.spec_from_file_location(name, path)
if spec is None or spec.loader is None:
raise ImportError(f"Could not load settings file: {path}")
mod = importlib.util.module_from_spec(spec)
sys.modules[name] = mod
spec.loader.exec_module(mod)

View file

@ -57,6 +57,12 @@ class TestSettingsConfiguration(unittest.TestCase):
self.maxDiff = None
self.assertDictEqual(settings, expected)
def test_read_settings_missing_file(self):
# A missing settings file should raise a clear FileNotFoundError
# rather than an obscure AttributeError from the import machinery.
missing = join(self.PATH, "does_not_exist")
self.assertRaises(FileNotFoundError, read_settings, missing)
def test_settings_return_independent(self):
# Make sure that the results from one settings call doesn't
# effect past or future instances.