Skip to content

Commit

Permalink
Allow arbitrary Python object in YAML config
Browse files Browse the repository at this point in the history
I'm not convinced this is a good idea, but MkDocs does it so we have to as
well...
  • Loading branch information
jimporter committed Apr 4, 2024
1 parent ac7b240 commit 01219bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mike/mkdocs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def representer(dumper, data):
return data.node


class RoundTripLoader(yaml.SafeLoader):
class RoundTripLoader(yaml.Loader):
pass


Expand Down
16 changes: 16 additions & 0 deletions test/unit/test_mkdocs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ def test_round_trip(self):
'- baz:\n option: !ENV [variable, default]\n')
self.assertEqual(self.out.getvalue(), expected)

def test_python_tag(self):
cfg = 'plugins:\n - foo:\n option: !!python/none'
with mock.patch('builtins.open',
mock_open_files({'mkdocs.yml': cfg})), \
mock.patch('mike.mkdocs_utils.NamedTemporaryFile',
return_value=self.out), \
mock.patch('os.remove') as mremove:
with mkdocs_utils.inject_plugin('mkdocs.yml') as f:
self.assertEqual(f, self.out.name)
newcfg = yaml.safe_load(self.out.getvalue())
mremove.assert_called_once()

self.assertEqual(newcfg, {'plugins': [
'mike', {'foo': {'option': None}},
]})

def test_inherit(self):
main_cfg = 'INHERIT: mkdocs-base.yml\nplugins:\n foo: {}\n'
base_cfg = 'plugins:\n bar: {}\n'
Expand Down

0 comments on commit 01219bd

Please sign in to comment.