From c3e6d3f7767f45e036bf8e5904dcaef07d680f17 Mon Sep 17 00:00:00 2001 From: Ee Savior <2930438-eSavior@users.noreply.gitlab.com> Date: Tue, 3 Dec 2019 19:54:57 +0000 Subject: [PATCH] Test improvements for bible ref parsing --- .../bibles/test_lib_parse_reference.py | 97 +++++++++++++++---- 1 file changed, 79 insertions(+), 18 deletions(-) diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py index 62d8dcbeb..cc3935f36 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py @@ -70,58 +70,58 @@ class TestBibleManager(TestCase, TestMixin): del self.manager self.destroy_settings() - def test_parse_reference_one(self): + def test_parse_reference_numbered_book_single_chapter_no_verse_reference(self): """ Test the parse_reference method with 1 Timothy 1 """ # GIVEN given a bible in the bible manager # WHEN asking to parse the bible reference results = parse_reference('1 Timothy 1', self.manager.db_cache['tests'], MagicMock(), 54) - # THEN a verse array should be returned - assert [(54, 1, 1, -1)] == results, "The bible verses should matches the expected results" + # THEN a one tuple verse array should be returned + assert [(54, 1, 1, -1)] == results, "The bible verses should match the expected results" - def test_parse_reference_two(self): + def test_parse_reference_numbered_book_single_range_single_chapter_multiple_verses(self): """ Test the parse_reference method with 1 Timothy 1:1-2 """ # GIVEN given a bible in the bible manager # WHEN asking to parse the bible reference results = parse_reference('1 Timothy 1:1-2', self.manager.db_cache['tests'], MagicMock(), 54) - # THEN a verse array should be returned - assert [(54, 1, 1, 2)] == results, "The bible verses should matches the expected results" + # THEN a one tuple verse array should be returned + assert [(54, 1, 1, 2)] == results, "The bible verses should match the expected results" - def test_parse_reference_three(self): + def test_parse_reference_numbered_book_single_range_multiple_chapters_specific_verses(self): """ Test the parse_reference method with 1 Timothy 1:1-2 """ # GIVEN given a bible in the bible manager # WHEN asking to parse the bible reference results = parse_reference('1 Timothy 1:1-2:1', self.manager.db_cache['tests'], MagicMock(), 54) - # THEN a verse array should be returned + # THEN a two tuple verse array should be returned assert [(54, 1, 1, -1), (54, 2, 1, 1)] == results, \ "The bible verses should match the expected results" - def test_parse_reference_four(self): + def test_parse_reference_invalid_book(self): """ - Test the parse_reference method with non existence book + Test the parse_reference method with non existent book """ # GIVEN given a bible in the bible manager # WHEN asking to parse the bible reference results = parse_reference('Raoul 1', self.manager.db_cache['tests'], MagicMock()) - # THEN a verse array should be returned - assert [] == results, "The bible Search should return an empty list" + # THEN an empty verse array should be returned + assert [] == results, "The bible search should return an empty list" - def test_parse_reference_five(self): + def test_parse_reference_numbered_book_single_range_single_chapter_with_end_reference(self): """ Test the parse_reference method with 1 Timothy 1:3-end """ # GIVEN given a bible in the bible manager # WHEN asking to parse the bible reference results = parse_reference('1 Timothy 1:3-end', self.manager.db_cache['tests'], MagicMock(), 54) - # THEN a verse array should be returned - assert [(54, 1, 3, -1)] == results, "The bible verses should matches the expected results" + # THEN a one tuple verse array should be returned + assert [(54, 1, 3, -1)] == results, "The bible verses should match the expected results" - def test_parse_reference_six(self): + def test_parse_reference_numbered_book_single_range_single_chapter_with_end_reference_no_bible_ref_id(self): """ Test the parse_reference method with 1 Timothy 1:3-end without a bible ref id to match how the GUI does the search. This is logged in issue #282 @@ -129,5 +129,66 @@ class TestBibleManager(TestCase, TestMixin): # GIVEN given a bible in the bible manager # WHEN asking to parse the bible reference in Language 0 (english) results = parse_reference('1 Timothy 1:3-end', self.manager.db_cache['tests'], 0) - # THEN a verse array should be returned - assert [(54, 1, 3, -1)] == results, "The bible verses should matches the expected results" + # THEN a one tuple verse array should be returned + assert [(54, 1, 3, -1)] == results, "The bible verses should match the expected results" + + def test_parse_reference_book_ref_id_invalid(self): + """ + Test the parse_reference method with 1 Timothy 1:1 with an invalid bible ref id + """ + # GIVEN given a bible in the bible manager + # WHEN asking to parse the bible reference with an invalid bible reference id + results = parse_reference('1 Timothy 1:1', self.manager.db_cache['tests'], MagicMock(), -666) + # THEN an empty verse array should be returned + assert [] == results, "The bible verse list should be empty" + + def test_parse_reference_no_from_chapter_in_second_range(self): + """ + Test the parse_reference method with 1 Timothy 1:1,3 + """ + # GIVEN given a bible in the bible manager + # WHEN asking to parse the bible reference that has no from_chapter in the second range + results = parse_reference('1 Timothy 1:1,3', self.manager.db_cache['tests'], MagicMock(), 54) + # THEN a two tuple verse array should be returned + assert [(54, 1, 1, 1), (54, 1, 3, 3)] == results, "The bible verses should match the expected results" + + def test_parse_reference_to_chapter_less_than_from_chapter(self): + """ + Test the parse_reference method with 1 Timothy 2:1-1:1 + """ + # GIVEN given a bible in the bible manager + # WHEN asking to parse the bible reference with a to_chapter less than the from_chapter + results = parse_reference('1 Timothy 2:1-1:1', self.manager.db_cache['tests'], MagicMock(), 54) + # THEN an empty verse array should be returned + assert [] == results, "The bible verse list should be empty" + + def test_parse_reference_no_from_chapter_specified(self): + """ + Test the parse_reference method with 1 Timothy :1-2 + """ + # GIVEN given a bible in the bible manager + # WHEN asking to parse the bible reference with no from_chapter specified + results = parse_reference('1 Timothy :1-2', self.manager.db_cache['tests'], MagicMock(), 54) + # THEN a two tuple verse array should be returned with the bible verse references treated as chapter references + assert [(54, 1, 1, -1), (54, 2, 1, -1)] == results, "The bible verses should match the expected results" + + def test_parse_reference_three_chapters(self): + """ + Test the parse_reference method with 1 Timothy 1-3 + """ + # GIVEN given a bible in the bible manager + # WHEN asking to parse the bible reference with three chapters + results = parse_reference('1 Timothy 1-3', self.manager.db_cache['tests'], MagicMock(), 54) + # THEN a three tuple verse array should be returned + assert [(54, 1, 1, -1), (54, 2, 1, -1), (54, 3, 1, -1)] == results, \ + "The bible verses should match the expected results" + + def test_parse_reference_non_regexp_matching_reference(self): + """ + Test the parse_reference method with 1 Timothy + """ + # GIVEN given a bible in the bible manager + # WHEN asking to parse the bible reference that fails the regexp matching + results = parse_reference('1 Timothy', self.manager.db_cache['tests'], MagicMock(), 54) + # THEN an empty verse array should be returned + assert [] == results, "The bible verse list should be empty"