diff options
| author | 2021-02-03 19:17:50 -0500 | |
|---|---|---|
| committer | 2021-02-03 19:17:50 -0500 | |
| commit | 475d074fd74425efbe783fad08f97f2df0c4909f (patch) | |
| tree | 2acdae53999b3c74b716efa4edb5b40311fa356a /tests/test_config.py | |
| parent | cd502d52787f666fff3254d7d7e7578930c813c2 (diff) | |
| parent | 3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 (diff) | |
Update upstream source from tag 'upstream/8.1.2'
Update to upstream version '8.1.2'
with Debian dir e5e966a9e6010ef70618dc9a61558fa4db35aceb
Diffstat (limited to 'tests/test_config.py')
| -rw-r--r-- | tests/test_config.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..c67929d --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,63 @@ +import os +import re + +import pytest + +from nikola import __main__ as nikola + + +def test_simple_config(simple_config, metadata_option): + """Check whether configuration-files without ineritance are interpreted correctly.""" + assert simple_config[metadata_option]["ID"] == "conf" + + +def test_inherited_config(simple_config, metadata_option, complex_config): + """Check whether configuration-files with ineritance are interpreted correctly.""" + check_base_equality(simple_config, metadata_option, complex_config) + assert complex_config[metadata_option]["ID"] == "prod" + + +def test_config_with_illegal_filename( + simple_config, metadata_option, complex_filename_config +): + """Check whether files with illegal module-name characters can be set as config-files, too.""" + check_base_equality(simple_config, metadata_option, complex_filename_config) + assert complex_filename_config[metadata_option]["ID"] == "illegal" + + +@pytest.fixture(scope="module") +def simple_config(data_dir): + nikola.main(["--conf=" + os.path.join(data_dir, "conf.py")]) + return nikola.config + + +@pytest.fixture(scope="module") +def data_dir(test_dir): + return os.path.join(test_dir, "data", "test_config") + + +@pytest.fixture +def metadata_option(): + return "ADDITIONAL_METADATA" + + +@pytest.fixture(scope="module") +def complex_config(data_dir): + nikola.main(["--conf=" + os.path.join(data_dir, "prod.py")]) + return nikola.config + + +@pytest.fixture(scope="module") +def complex_filename_config(data_dir): + config_path = os.path.join( + data_dir, "config.with+illegal(module)name.characters.py" + ) + nikola.main(["--conf=" + config_path]) + return nikola.config + + +def check_base_equality(base_config, metadata_option, config): + """Check whether the specified `config` equals the base config.""" + for option in base_config.keys(): + if re.match("^[A-Z]+(_[A-Z]+)*$", option) and option != metadata_option: + assert base_config[option] == config[option] |
