From 9832d9e17aeb0a5300e707674cde70e6292c480d Mon Sep 17 00:00:00 2001 From: UlrichB22 <97119703+UlrichB22@users.noreply.github.com> Date: Sat, 17 Feb 2024 20:29:08 +0100 Subject: [PATCH] Raise ValueError when block macros are used inline --- src/moin/macros/_base.py | 5 ++--- src/moin/macros/_tests/test__base.py | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/moin/macros/_base.py b/src/moin/macros/_base.py index e9107d85e..a52e439b6 100644 --- a/src/moin/macros/_base.py +++ b/src/moin/macros/_base.py @@ -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 diff --git a/src/moin/macros/_tests/test__base.py b/src/moin/macros/_tests/test__base.py index 36e1ba35e..80c74183a 100644 --- a/src/moin/macros/_tests/test__base.py +++ b/src/moin/macros/_tests/test__base.py @@ -1,4 +1,5 @@ # Copyright: 2011 Prashant Kumar +# Copyright: 2024 MoinMoin:UlrichB # License: GNU GPL v2 (or any later version), see LICENSE.txt for details. """ @@ -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 """