from mwparserfromhell import parse
-from wrpylib.lib_sledrun_wikitext_to_json import get_sledrun_description
+from wrpylib.lib_sledrun_wikitext_to_json import get_sledrun_description, optional_set
+
+
+class TestOptionalSet(unittest.TestCase):
+ def test_optional_set_string(self):
+ h = {'a': 3}
+ optional_set(h, 'b', 5)
+ expected = {'a': 3, 'b': 5}
+ self.assertDictEqual(expected, h)
+
+ def test_optional_set_none(self):
+ h = {'a': 3}
+ expected = h.copy()
+ optional_set(h, 'b', None)
+ self.assertDictEqual(expected, h)
class TestGetSledrunDescription(unittest.TestCase):
from mwparserfromhell.wikicode import Wikicode
+def optional_set(haystack: dict, key: str, value: Optional[Any]):
+ """Sets the key to value in haystack only if value is not None"""
+ if value is not None:
+ haystack[key] = value
+
+
def get_sledrun_description(sledrun: Wikicode) -> Optional[str]:
"""Get description from sledrun"""
for v in sledrun.get_sections(levels=[2], matches='Allgemeines', include_headings=False):