From 7d85f167de3332f72d67a1da5f96a39a613e35fa Mon Sep 17 00:00:00 2001 From: "Eli C. Lowry" <83078660+Enkidu93@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:44:02 -0400 Subject: [PATCH] Scripture range parser no error on empty string (#110) * Fixes issue when specifying PS2 or PS3 * Check for empty string --- machine/scripture/parse.py | 5 ++++- tests/scripture/test_parse.py | 5 +---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/machine/scripture/parse.py b/machine/scripture/parse.py index 1856c93..22675f3 100644 --- a/machine/scripture/parse.py +++ b/machine/scripture/parse.py @@ -101,9 +101,13 @@ def parse_selection(selection: str, versification: Versification) -> Dict[int, L def get_chapters( selections: Union[str, List[str]], versification: Versification = ORIGINAL_VERSIFICATION ) -> Dict[int, List[int]]: + chapters = {} if isinstance(selections, str): selections = selections.strip() + if len(selections) == 0: + return chapters + delimiter = ";" if ";" in selections: delimiter = ";" @@ -117,7 +121,6 @@ def get_chapters( selections = selections.split(delimiter) - chapters = {} for selection in selections: selection = selection.strip() diff --git a/tests/scripture/test_parse.py b/tests/scripture/test_parse.py index 1e9ce31..ac2e6ff 100644 --- a/tests/scripture/test_parse.py +++ b/tests/scripture/test_parse.py @@ -66,6 +66,7 @@ def test_get_chapters() -> None: test_bible[66] = test_chapters_rev assert get_chapters("NT;-MAT3-5,17;-REV21,22") == test_bible assert get_chapters("MAT-JHN;-MAT-LUK") == {43: []} + assert get_chapters("") == {} with raises(ValueError): # wrong order of chapters @@ -111,10 +112,6 @@ def test_get_chapters() -> None: # invalid book/length of book name in subtraction get_chapters("-MAT-FLUM") - with raises(ValueError): - # empty string - get_chapters("") - with raises(ValueError): # invalid name get_chapters("ABC")