def test_get_base_passage_with_ascii_punctuation(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation(), use_ascii_punctuation=True) text = bible.get_passage('Ecclesiastes', 1, 2) eccl = '\u00b2 "Vanity of vanities," says the Preacher; "Vanity of vanities, all is vanity."' self.assertEqual(eccl, text, 'Passages do not match')
def test_get_base_passage_lowercase_translation(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), translation='KJV', default_directory=self.get_test_directory('KJV')) text1 = bible.get_passage('Ecclesiastes', 2, 26) bible.translation = 'kjv' text2 = bible.get_passage('Ecclesiastes', 2, 26) # Translations should be case insensitive under the hood self.assertEqual(text1, text2, 'Passages do not match')
def test_get_base_passage_kjv(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), translation='KJV', default_directory=self.get_test_directory('KJV')) text = bible.get_passage('Ecclesiastes', 2, 26) self.assertEqual( '\u00b2\u2076 For God giveth to a man that is good in his sight wisdom, and knowledge, ' 'and joy: but to the sinner he giveth travail, to gather and to heap up, that ' 'he may give to him that is good before God. This also is vanity and vexation ' 'of spirit.', text, 'Passage is incorrect')
def test_get_base_chapters(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_chapters('Ecclesiastes', 11, 12) static_file = '{0}/test_get_base_chapters.txt'.format( self.get_test_directory()) with open(static_file, 'r', encoding='utf-8') as file: eccl = file.read() self.assertEqual(eccl, text, 'Passage is incorrect')
def test_get_base_passage_range_reverse_parameters(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passage_range('Ecclesiastes', 10, 1, 9, 18) # Chapter 10 is after chapter 9, so this should not work self.assertEqual('', text, 'Passage is incorrect') text = bible.get_passage_range('Ecclesiastes', 9, 2, 9, 1) # Verse 2 is after verse 1, so this should not work either self.assertEqual('', text, 'Passage is incorrect')
def test_get_base_book(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_book('Philemon') static_file = '{0}/test_get_base_book.txt'.format( self.get_test_directory()) with open(static_file, 'r', encoding='utf-8') as file: phil = file.read() self.assertEqual(phil, text, 'Passage is incorrect')
def test_get_base_passage(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passage('Ecclesiastes', 2, 26) self.assertEqual( '\u00b2\u2076 For to the man who pleases him, God gives wisdom, knowledge, and joy; but ' 'to the sinner he gives travail, to gather and to heap up, that he may give to ' 'him who pleases God. This also is vanity and a chasing after wind.', text, 'Passage is incorrect')
def test_get_base_passage_list(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), output_as_list=True, default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passage('1 John', 1, 8) john = [ '\u2078 If we say that we have no sin, we deceive ourselves, and the truth is not in us. ' ] self.assertEqual(john, text, 'Passage is incorrect')
def test_get_base_passage_range_negative_numbers(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passage_range('Ecclesiastes', 1, -1, 1, 1) eccl = '\u00b9 The words of the Preacher, the son of David, king in Jerusalem:' # This should apply value normalisation logic to ensure that negative values don't break the execution flow self.assertEqual(eccl, text, 'Passage is incorrect') text = bible.get_passage_range('Ecclesiastes', -1, 1, 1, 1) # Same normalisation should also apply for negative chapter numbers as well self.assertEqual(eccl, text, 'Passage is incorrect')
def test_get_base_book_list(self): online_bible = WebExtractor(output_as_list=True, translation=self.get_test_translation()) bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), output_as_list=True, default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_book('Philemon') eccl = online_bible.get_book('Philemon') # Results should be identical between the web and base extractor self.assertEqual(eccl, text, 'Passage is incorrect')
def test_get_base_passage_buffered_first_passage(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), translation=self.get_test_translation()) eccl = '\u00b2 \u201cVanity of vanities,\u201d says the Preacher; ' \ '\u201cVanity of vanities, all is vanity.\u201d' custom_file = '{0}/{1}'.format( self.get_test_directory(), 'test_get_base_passage_buffered_first_passage.yaml') text = bible.get_passage('Ecclesiastes', 1, 2, file_path=custom_file) # Custom file only contains one chapter and one passage, but doesn't start on the first passage self.assertEqual(text, eccl, 'Passages do not match')
def test_get_base_passage_buffered_first_chapter(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), translation=self.get_test_translation()) eccl = '\u00b2 I said of laughter, \u201cIt is foolishness;\u201d and of mirth, ' \ '\u201cWhat does it accomplish?\u201d' custom_file = '{0}/{1}'.format( self.get_test_directory(), 'test_get_base_passage_buffered_first_chapter.yaml') text = bible.get_passage('Ecclesiastes', 2, 2, file_path=custom_file) # Custom file only contains one chapter and one passage, but doesn't start on the first passage or chapter self.assertEqual(text, eccl, 'Passages do not match')
def test_get_base_passages(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passages('Ecclesiastes', 2, 24, 25) self.assertEqual( '\u00b2\u2074 There is nothing better for a man than that he should eat and drink, and ' 'make his soul enjoy good in his labor. This also I saw, that it is from the ' 'hand of God. ' '\u00b2\u2075 For who can eat, or who can have enjoyment, more than I?', text, 'Passage is incorrect')
def test_get_base_passage_range_with_file_path_param(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text1 = bible.get_passage('Ecclesiastes', 2, 26) # File path parameter should overwrite the default directory, regardless of what it was set to bible.default_directory = '../' file = '{0}/{1}'.format(self.get_test_directory(), 'Ecclesiastes.yaml') text2 = bible.get_passage('Ecclesiastes', 2, 26, file) # Translations should be case insensitive under the hood self.assertEqual(text1, text2, 'Passages do not match')
def test_get_base_passage_range(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passage_range('Ecclesiastes', 9, 18, 10, 1) eccl = [ '\u00b9\u2078 Wisdom is better than weapons of war; but one sinner destroys much good.', '\u00b9 Dead flies cause the oil of the perfumer to produce an evil odor;', ' so does a little folly outweigh wisdom and honor.' ] # This passage selection is on a chapter boundary, which means Ecclesiastes 9:18 has the trailing line character self.assertEqual('\n'.join(eccl), text, 'Passage is incorrect')
def test_get_base_passages_list(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), output_as_list=True, default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passages('1 John', 1, 8, 9) john = [ '\u2078 If we say that we have no sin, we deceive ourselves, and the truth is not in us. ', '\u2079 If we confess our sins, he is faithful and righteous to forgive us the sins, ' 'and to cleanse us from all unrighteousness. ' ] self.assertEqual(john, text, 'Passage is incorrect')
def test_get_base_passage_range_without_passage_numbers(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), show_passage_numbers=False, default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passage_range('Ecclesiastes', 9, 18, 10, 1) eccl = [ 'Wisdom is better than weapons of war; but one sinner destroys much good.', 'Dead flies cause the oil of the perfumer to produce an evil odor;', ' so does a little folly outweigh wisdom and honor.' ] self.assertEqual('\n'.join(eccl), text, 'Passage is incorrect')
def test_get_base_passage_range_list(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), output_as_list=True, default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passage_range('Ecclesiastes', 9, 18, 10, 1) eccl = [ '\u00b9\u2078 Wisdom is better than weapons of war; but one sinner destroys much good.', '\u00b9 Dead flies cause the oil of the perfumer to produce an evil odor;\n' ' so does a little folly outweigh wisdom and honor.\n' ] self.assertEqual(eccl, text, 'Passage is incorrect')
def test_get_base_passage_with_string_keys_mismatch(self): # Extractor should fail to work, since the JSON file interface can only read keys as strings bible1 = BaseExtractor(file_reading_function=json_file_interface.read, file_extension='.json', default_directory=self.get_test_directory(), translation=self.get_test_translation(), read_key_as_string=False) # Extractor should fail to work, since the YAML file interface can only read keys as integers bible2 = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation(), read_key_as_string=True) self.assertRaises(KeyError, bible1.get_passage, 'Ecclesiastes', 1, 2) self.assertRaises(KeyError, bible2.get_passage, 'Ecclesiastes', 1, 2)
def test_get_base_chapters_list(self): online_bible = WebExtractor(output_as_list=True, show_passage_numbers=False, translation=self.get_test_translation()) bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), output_as_list=True, show_passage_numbers=False, default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_chapters('Ecclesiastes', 11, 12) eccl = online_bible.get_chapters('Ecclesiastes', 11, 12) # Results should be identical between the web and base extractor # Ignoring passage numbers, as the web extractor omits this for the first passage of each chapter self.assertEqual(eccl, text, 'Passage is incorrect')
def test_get_base_passage_range_list_with_stripped_whitespace(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), output_as_list=True, strip_excess_whitespace_from_list=True, default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passage_range('Ecclesiastes', 10, 1, 10, 2) eccl = [ '\u00b9 Dead flies cause the oil of the perfumer to produce an evil odor;\n' ' so does a little folly outweigh wisdom and honor.', '\u00b2 A wise man\u2019s heart is at his right hand,\n' 'but a fool\u2019s heart at his left.' ] self.assertEqual(eccl, text, 'Passage is incorrect')
def test_get_base_book_list_with_ascii_punctuation(self): online_bible = WebExtractor(output_as_list=True, translation=self.get_test_translation(), show_passage_numbers=False, use_ascii_punctuation=True) bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), output_as_list=True, default_directory=self.get_test_directory(), translation=self.get_test_translation(), show_passage_numbers=False, use_ascii_punctuation=True) text = bible.get_book('Ecclesiastes') eccl = online_bible.get_book('Ecclesiastes') # Results should be identical between the web and base extractor self.assertEqual(eccl, text, 'Passage is incorrect')
def test_get_base_passage_invalid_translation(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), translation='LOL', default_directory=self.get_test_directory()) self.assertRaises(UnsupportedTranslationError, bible.get_passage, 'Ecclesiastes', 2, 26)
def test_get_base_book_ascii_punctuation_count(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation(), use_ascii_punctuation=False) text1 = bible.get_book('Ecclesiastes') bible.use_ascii_punctuation = True text2 = bible.get_book('Ecclesiastes') # Check that the punctuation conversion is a 1:1 translation self.assertEqual( text1.count('\u201c') + text1.count('\u201d'), text2.count('"'), 'Double quotes are unequal') self.assertEqual( text1.count('\u2018') + text1.count('\u2019'), text2.count("'"), 'Single quotes are unequal') self.assertEqual(text1.count('\u2014'), text2.count('-'), 'Dashes are unequal')
def test_get_base_passage_range_excessive_numbers(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text = bible.get_passage_range('Ecclesiastes', 9000, 1, 9000, 2) sample1 = [ '\u00b9 Remember also your Creator in the days of your youth,', ' before the evil days come, and the years draw near,', ' when you will say, \u201cI have no pleasure in them;\u201d', '\u00b2 Before the sun, the light, the moon, and the stars are darkened,', ' and the clouds return after the rain;' ] # Excessive chapters should just default to the last chapter of the book self.assertEqual('\n'.join(sample1), text, 'Passage is incorrect') text = bible.get_passage_range('Ecclesiastes', 1, 9000, 1, 9001) sample2 = '\u00b9\u2078 For in much wisdom is much grief; and he who increases knowledge increases sorrow.' # Excessive passages should just default to the last passage of the given chapter self.assertEqual(sample2, text, 'Passage is incorrect')
def test_get_base_passage_with_string_keys(self): # Use the JSON file interface, which will only work if the keys are strings and not integers bible1 = BaseExtractor(file_reading_function=json_file_interface.read, file_extension='.json', default_directory=self.get_test_directory(), translation=self.get_test_translation(), read_key_as_string=True) bible2 = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory(), translation=self.get_test_translation()) text1 = bible1.get_passage('Ecclesiastes', 1, 2) text2 = bible2.get_passage('Ecclesiastes', 1, 2) # Result should be the same when extracting the same passage from a file with string keys (with relevant # extractor settings) and from a file with integer keys self.assertEqual(text1, text2, 'Passages do not match')
def test_get_base_passage_range_invalid(self): bible = BaseExtractor(file_reading_function=yaml_file_interface.read, file_extension=self.get_test_file_extension(), default_directory=self.get_test_directory()) self.assertRaises(FileNotFoundError, bible.get_passage_range, 'Barnabas', 2, 3, 2, 4)