Skip to content

Commit 0a92926

Browse files
authored
tests and fix for Issue #118 (#121)
* tests and fix for Issue #118 * add missing link for 0.11.1 and update "unreleased" link
1 parent 16d387b commit 0a92926

File tree

7 files changed

+89
-5
lines changed

7 files changed

+89
-5
lines changed

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.11.1] - 2023-10-02
11+
12+
The goal of this release was to address [Issue #118] (When trying to get the scripture text for a verse that is in a book that is not included in the given version, the entire scripture text for that version was returned.)
13+
14+
### Added
15+
16+
- VersionMissingVerseError exception
17+
18+
### Fixed
19+
20+
- Raise an error when trying to get scripture text for a verse that is in a book that is not included in the given version.
21+
1022
## [0.11.0] - 2023-06-27
1123

1224
### Changed
@@ -102,7 +114,8 @@ The goal of this release was to address [Issue #90], and to make things related
102114

103115
## [0.0.1] - 2020-10-08
104116

105-
[unreleased]: https://github.com/avendesora/pythonbible/compare/v0.11.0...HEAD
117+
[unreleased]: https://github.com/avendesora/pythonbible/compare/v0.11.1...HEAD
118+
[0.11.1]: https://github.com/avendesora/pythonbible/compare/v0.11.0...v0.11.1
106119
[0.11.0]: https://github.com/avendesora/pythonbible/compare/v0.10.0...v0.11.0
107120
[0.10.0]: https://github.com/avendesora/pythonbible/compare/v0.9.1...v0.10.0
108121
[0.9.1]: https://github.com/avendesora/pythonbible/compare/v0.9.0...v0.9.1
@@ -135,3 +148,4 @@ The goal of this release was to address [Issue #90], and to make things related
135148
[0.0.1]: https://github.com/avendesora/pythonbible
136149

137150
[issue #90]: https://github.com/avendesora/pythonbible/issues/90
151+
[issue #118]: https://github.com/avendesora/pythonbible/issues/118

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
author = "Nathan Patton"
2424

2525
# The full version, including alpha/beta/rc tags
26-
release = "0.11.0"
26+
release = "0.11.1"
2727

2828

2929
# -- General configuration ---------------------------------------------------

pythonbible/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from __future__ import annotations
1010

11-
__version__ = "0.11.0"
11+
__version__ = "0.11.1"
1212

1313
from .bible.bible import Bible
1414
from .book_groups import BOOK_GROUPS
@@ -26,6 +26,7 @@
2626
from .errors import InvalidVerseError
2727
from .errors import MissingBookFileError
2828
from .errors import MissingVerseFileError
29+
from .errors import VersionMissingVerseError
2930
from .formatter import format_scripture_references
3031
from .formatter import format_scripture_text
3132
from .formatter import format_single_reference

pythonbible/bible/bible.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import TYPE_CHECKING
66

77
from pythonbible.errors import InvalidVerseError
8+
from pythonbible.errors import VersionMissingVerseError
89
from pythonbible.validator import is_valid_verse_id
910

1011
if TYPE_CHECKING:
@@ -58,10 +59,29 @@ def get_scripture(
5859
)
5960

6061
end_verse_id = end_verse_id or start_verse_id
62+
start_index, end_index = self._get_start_and_end_indices(
63+
start_verse_id,
64+
end_verse_id,
65+
)
66+
67+
return _clean(self.scripture_content[start_index:end_index], self.is_html)
68+
69+
def _get_start_and_end_indices(
70+
self: Bible,
71+
start_verse_id: int,
72+
end_verse_id: int,
73+
) -> tuple[int, int]:
6174
start_index = self.verse_start_indices.get(start_verse_id)
75+
76+
if start_index is None:
77+
raise VersionMissingVerseError(start_verse_id, self.version.value)
78+
6279
end_index = self.verse_end_indices.get(end_verse_id)
6380

64-
return _clean(self.scripture_content[start_index:end_index], self.is_html)
81+
if end_index is None:
82+
raise VersionMissingVerseError(end_verse_id, self.version.value)
83+
84+
return start_index, end_index
6585

6686

6787
@lru_cache()

pythonbible/errors.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,19 @@ class MissingVerseFileError(Exception):
5858

5959
class MissingBookFileError(Exception):
6060
"""Raised when the book file for a given version is not found."""
61+
62+
63+
class VersionMissingVerseError(Exception):
64+
"""Raised when the verse for a given version is missing from the version."""
65+
66+
def __init__(
67+
self: VersionMissingVerseError,
68+
version: str,
69+
verse_id: int,
70+
) -> None:
71+
"""Initialize VersionMissingVerseError.
72+
73+
:param version: version string
74+
:param verse_id: verse id
75+
"""
76+
super().__init__(f"{version} is missing verse {verse_id}.")

tests/bible_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ def test_get_scripture_cross_book() -> None:
3636
def test_get_scripture_missing_verse_in_version() -> None:
3737
scripture = asv_html_readers_bible.get_scripture(40017021, 40017021)
3838
assert not scripture
39+
40+
41+
def test_get_scripture_missing_book_in_version_start_index() -> None:
42+
with pytest.raises(bible.VersionMissingVerseError):
43+
asv_html_readers_bible.get_scripture(67001001, 67001001)
44+
45+
46+
def test_get_scripture_missing_book_in_version_end_index() -> None:
47+
with pytest.raises(bible.VersionMissingVerseError):
48+
asv_html_readers_bible.get_scripture(66001001, 67001001)

tests/formatter_test.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,35 @@ def test_get_verse_text_no_version_file(verse_id: int) -> None:
180180
# Given a valid verse id and a version that doesn't have a file
181181
version: bible.Version = bible.Version.MESSAGE
182182

183-
# When using that verse id and version to the get the verse text
183+
# When using that verse id and version to get the verse text
184184
# Then a MissingVerseFileError is raised.
185185
with pytest.raises(bible.MissingVerseFileError):
186186
bible.get_verse_text(verse_id, version=version)
187187

188188

189+
def test_get_verse_text_verse_omitted_from_version() -> None:
190+
# Given a valid verse id for a verse that has been omitted from the given version
191+
version: bible.Version = bible.Version.AMERICAN_STANDARD
192+
verse_id: int = 40018011
193+
194+
# When using that verse id and version to get the verse text
195+
verse_text: str = bible.get_verse_text(verse_id, version=version)
196+
197+
# Then the verse text is empty.
198+
assert not verse_text
199+
200+
201+
def test_get_verse_text_version_not_include_book() -> None:
202+
# Given a valid verse id for a verse in a book not included in the given version
203+
version: bible.Version = bible.Version.AMERICAN_STANDARD
204+
verse_id: int = 67001009
205+
206+
# When using that verse id and version to get the verse text
207+
# Then a VersionMissingVerseError is raised.
208+
with pytest.raises(bible.VersionMissingVerseError):
209+
bible.get_verse_text(verse_id, version=version)
210+
211+
189212
def test_verse_text_caching() -> None:
190213
# Given a lengthy reference
191214
references: list[bible.NormalizedReference] = bible.get_references("Jeremiah 29")

0 commit comments

Comments
 (0)