mirror of
https://github.com/getpelican/pelican.git
synced 2026-08-31 00:04:04 +02:00
Merge df9d95c379 into 3c69dc68d2
This commit is contained in:
commit
7f4cc14bcb
2 changed files with 10 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue