Skip to content

Commit

Permalink
Fix get_passage_range in Web Extractor incorrectly capping passages…
Browse files Browse the repository at this point in the history
… to 100

The max passage number should be based on the chapter end helper function instead of using the default value
  • Loading branch information
daniel-tran committed Jan 28, 2024
1 parent 437700a commit 7861272
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions meaningless/bible_web_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ def get_passage_range(self, book, chapter_from, passage_from, chapter_to, passag
# the web request to stagger if this manages to be long enough.
capped_chapter_from = common.get_capped_integer(chapter_from,
max_value=common.get_chapter_count(book, self.translation))
capped_passage_from = common.get_capped_integer(passage_from)
capped_passage_from = common.get_capped_integer(passage_from, max_value=common.get_end_of_chapter())
capped_chapter_to = common.get_capped_integer(chapter_to,
max_value=common.get_chapter_count(book, self.translation))
capped_passage_to = common.get_capped_integer(passage_to)
capped_passage_to = common.get_capped_integer(passage_to, max_value=common.get_end_of_chapter())
# Defer to a direct search invocation when sourcing passages from the same chapter
if capped_chapter_from == capped_chapter_to:
return self.search(f'{book} {capped_chapter_from}:{capped_passage_from} - {capped_passage_to}')
Expand Down
26 changes: 19 additions & 7 deletions test/unit_tests_bible_web_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,18 @@ def test_get_online_passage_with_excessive_values(self):
text2 = bible.get_passage('Ecclesiastes', -1, -1)
self.assertEqual(text1, text2, 'Passage is incorrect')
# Starting passage is not valid
self.assertRaises(InvalidSearchError, bible.get_passage, 'Ecclesiastes', 1000, 1000)
self.assertRaises(InvalidSearchError, bible.get_passage, 'Ecclesiastes', 10000, 10000)

def test_get_online_passages_with_excessive_values(self):
bible = WebExtractor()
text1 = bible.search('Ecclesiastes 1:1')
text2 = bible.get_passages('Ecclesiastes', -1, -1, -1)
self.assertEqual(text1, text2, 'Passage is incorrect')
# Starting passage is not valid
self.assertRaises(InvalidSearchError, bible.get_passages, 'Ecclesiastes', 1000, 1000, 1000)
self.assertRaises(InvalidSearchError, bible.get_passages, 'Ecclesiastes', 10000, 10000, 10000)
# Starting passage is valid again
text1 = bible.search('Ecclesiastes 12')
text2 = bible.get_passages('Ecclesiastes', 1000, 1, 1000)
text2 = bible.get_passages('Ecclesiastes', 10000, 1, 10000)
self.assertEqual(text1, text2, 'Passage is incorrect')

def test_get_online_chapter_with_excessive_values(self):
Expand All @@ -431,7 +431,7 @@ def test_get_online_chapter_with_excessive_values(self):
self.assertEqual(text1, text2, 'Passage is incorrect')
# This should scale down to the last chapter number of the book
text1 = bible.search('Ecclesiastes 12')
text2 = bible.get_chapter('Ecclesiastes', 1000)
text2 = bible.get_chapter('Ecclesiastes', 10000)
self.assertEqual(text1, text2, 'Passage is incorrect')

def test_get_online_chapters_with_excessive_values(self):
Expand All @@ -441,7 +441,7 @@ def test_get_online_chapters_with_excessive_values(self):
self.assertEqual(text1, text2, 'Passage is incorrect')
# This should scale down to the last chapter number of the book
text1 = bible.search('Ecclesiastes 12')
text2 = bible.get_chapters('Ecclesiastes', 1000, 1000)
text2 = bible.get_chapters('Ecclesiastes', 10000, 10000)
self.assertEqual(text1, text2, 'Passage is incorrect')

def test_get_online_passage_range_with_excessive_values(self):
Expand All @@ -450,12 +450,24 @@ def test_get_online_passage_range_with_excessive_values(self):
text2 = bible.get_passage_range('Ecclesiastes', -1, -1, -1, -1)
self.assertEqual(text1, text2, 'Passage is incorrect')
# Starting passage is not valid
self.assertRaises(InvalidSearchError, bible.get_passage_range, 'Ecclesiastes', 1000, 1000, 1000, 1000)
self.assertRaises(InvalidSearchError, bible.get_passage_range, 'Ecclesiastes', 10000, 10000, 10000, 10000)
# Starting passage is valid again
text1 = bible.search('Ecclesiastes 12')
text2 = bible.get_passage_range('Ecclesiastes', 1000, -1, 1000, 1000)
text2 = bible.get_passage_range('Ecclesiastes', 10000, -1, 10000, 10000)
self.assertEqual(text1, text2, 'Passage is incorrect')

def test_get_online_passage_range_with_values_over_100(self):
bible = WebExtractor(translation='NASB1995')
# All chapter and passage parameters are over 100 and are still valid, so check that these are not being capped
text1 = ['¹⁰¹ I have restrained my feet from every evil way,',
'That I may keep Your word.',
'¹⁰² I have not turned aside from Your ordinances,',
'For You Yourself have taught me.',
'¹⁰³ How sweet are Your words to my taste!',
'Yes, sweeter than honey to my mouth!']
text2 = bible.get_passage_range("Psalms", 119, 101, 119, 103)
self.assertEqual('\n'.join(text1), text2, 'Passage is incorrect')

# -------------- Tests for multiple passage searching --------------

def test_search_multiple(self):
Expand Down

0 comments on commit 7861272

Please sign in to comment.