Skip to content

Commit 01219bd

Browse files
committed
Allow arbitrary Python object in YAML config
I'm not convinced this is a good idea, but MkDocs does it so we have to as well...
1 parent ac7b240 commit 01219bd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: mike/mkdocs_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def representer(dumper, data):
2828
return data.node
2929

3030

31-
class RoundTripLoader(yaml.SafeLoader):
31+
class RoundTripLoader(yaml.Loader):
3232
pass
3333

3434

Diff for: test/unit/test_mkdocs_utils.py

+16
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ def test_round_trip(self):
184184
'- baz:\n option: !ENV [variable, default]\n')
185185
self.assertEqual(self.out.getvalue(), expected)
186186

187+
def test_python_tag(self):
188+
cfg = 'plugins:\n - foo:\n option: !!python/none'
189+
with mock.patch('builtins.open',
190+
mock_open_files({'mkdocs.yml': cfg})), \
191+
mock.patch('mike.mkdocs_utils.NamedTemporaryFile',
192+
return_value=self.out), \
193+
mock.patch('os.remove') as mremove:
194+
with mkdocs_utils.inject_plugin('mkdocs.yml') as f:
195+
self.assertEqual(f, self.out.name)
196+
newcfg = yaml.safe_load(self.out.getvalue())
197+
mremove.assert_called_once()
198+
199+
self.assertEqual(newcfg, {'plugins': [
200+
'mike', {'foo': {'option': None}},
201+
]})
202+
187203
def test_inherit(self):
188204
main_cfg = 'INHERIT: mkdocs-base.yml\nplugins:\n foo: {}\n'
189205
base_cfg = 'plugins:\n bar: {}\n'

0 commit comments

Comments
 (0)