mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 18:08:31 +07:00
Rework SubConfig so it doesn't share mutable state (#2916)
This commit is contained in:
@@ -49,19 +49,17 @@ class BaseConfigOption:
|
||||
"""
|
||||
|
||||
|
||||
class SubConfig(BaseConfigOption, Config):
|
||||
class SubConfig(BaseConfigOption):
|
||||
def __init__(self, *config_options):
|
||||
BaseConfigOption.__init__(self)
|
||||
Config.__init__(self, config_options)
|
||||
super().__init__()
|
||||
self.default = {}
|
||||
|
||||
def validate(self, value):
|
||||
self.load_dict(value)
|
||||
return self.run_validation(value)
|
||||
self.config_options = config_options
|
||||
|
||||
def run_validation(self, value):
|
||||
Config.validate(self)
|
||||
return self
|
||||
config = Config(self.config_options)
|
||||
config.load_dict(value)
|
||||
config.validate()
|
||||
return config
|
||||
|
||||
|
||||
class ConfigItems(BaseConfigOption):
|
||||
|
||||
@@ -283,6 +283,26 @@ class ConfigTests(unittest.TestCase):
|
||||
self.assertEqual(len(errors), 1)
|
||||
self.assertEqual(warnings, [])
|
||||
|
||||
SUBCONFIG_TEST_SCHEMA = {
|
||||
"items": mkdocs.config.config_options.ConfigItems(
|
||||
("value", mkdocs.config.config_options.Type(str)),
|
||||
),
|
||||
}.items()
|
||||
|
||||
def test_subconfig_with_multiple_items(self):
|
||||
# This had a bug where subsequent items would get merged into the same dict.
|
||||
conf = config.Config(schema=self.SUBCONFIG_TEST_SCHEMA)
|
||||
conf.load_dict(
|
||||
{
|
||||
'items': [
|
||||
{'value': 'a'},
|
||||
{'value': 'b'},
|
||||
]
|
||||
}
|
||||
)
|
||||
conf.validate()
|
||||
self.assertEqual(conf['items'], [{'value': 'a'}, {'value': 'b'}])
|
||||
|
||||
def test_multiple_markdown_config_instances(self):
|
||||
# This had a bug where an extension config would persist to separate
|
||||
# config instances that didn't specify extensions.
|
||||
|
||||
Reference in New Issue
Block a user