Skip to content

Commit

Permalink
Merge pull request #1606 from UlrichB22/fix_itemlist
Browse files Browse the repository at this point in the history
Raise ValueError when block macros are used inline
  • Loading branch information
RogerHaase authored Feb 17, 2024
2 parents 85707b9 + 9832d9e commit b6457bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/moin/macros/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ class MacroBlockBase(MacroBase):
"""
Macro base class for block element macros.
The macro gets only expanded in block context. In inline context the
alternative text is used instead.
The macro gets only expanded in block context.
"""
def __call__(self, content, arguments, page_url, alternative, context_block):
if context_block:
return self.macro(content, arguments, page_url, alternative)
return self.alt
raise ValueError(_("Block macros cannot be used inline"))

def macro(self, content, arguments, page_url, alternative):
raise NotImplementedError
Expand Down
9 changes: 4 additions & 5 deletions src/moin/macros/_tests/test__base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright: 2011 Prashant Kumar <contactprashantat AT gmail DOT com>
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand All @@ -23,14 +24,12 @@ def test_MacroBlockBase(self):
""" test for MacroBlockBase class """
class Test_MacroBlockBase(MacroBlockBase):
""" inherited class from MacroBlockBase """
def __init__(self):
self.alt = 'alt returned'

macroblockbase_obj = Test_MacroBlockBase()
result = macroblockbase_obj.__call__('content', 'arguments', 'page_url', 'alternative', context_block=False)
assert result == 'alt returned'
with pytest.raises(ValueError):
macroblockbase_obj.__call__('content', 'arguments', 'page_url', 'alternative', context_block=False)
with pytest.raises(NotImplementedError):
result = macroblockbase_obj.__call__('content', 'arguments', 'page_url', 'alternative', 'context_block')
macroblockbase_obj.__call__('content', 'arguments', 'page_url', 'alternative', 'context_block')

def test_MacroInlineBase(self):
""" test for MacroInlineBase class """
Expand Down

0 comments on commit b6457bb

Please sign in to comment.