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")