Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise ValueError when block macros are used inline #1606

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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