def test_base_download_with_excessive_values(self): download_path = './tmp/test_base_download_with_excessive_values/' static_path = '{0}/test_base_download_with_excessive_values'.format( self.get_test_directory()) branching_paths = [ '{0}/Chapter-1'.format(download_path), '{0}/Chapter1000'.format(download_path), '{0}/Chapter5'.format(download_path), ] bible = BaseDownloader(file_writing_function=yaml_file_interface.write, default_directory=branching_paths[0], translation=self.get_test_translation()) # This should obtain the first passage of the first chapter bible.download_passage_range('1 John', -1, -1, -1, -1) downloaded_file = yaml_file_interface.read('{0}/1 John'.format( bible.default_directory)) static_file = yaml_file_interface.read( '{0}/Chapter-1/1 John.yaml'.format(static_path)) self.assertEqual(downloaded_file['1 John'], static_file['1 John'], 'Passage contents do not match') # This does NOT get the last passage of the last chapter, but is instead deemed invalid. # This is consistent with how the Bible Gateway site handles when the starting passage is too high. bible.default_directory = branching_paths[1] self.assertRaises(InvalidSearchError, bible.download_passage_range, '1 John', 1000, 1000, 1000, 1000) # Gets the last chapter of the book. # This is valid because the starting passage is a correct number from the chapter. bible.default_directory = branching_paths[2] bible.download_passage_range('1 John', 1000, 1, 1000, 1000) downloaded_file = yaml_file_interface.read('{0}/1 John'.format( bible.default_directory)) static_file = yaml_file_interface.read( '{0}/Chapter5/1 John.yaml'.format(static_path)) self.assertEqual(downloaded_file['1 John'], static_file['1 John'], 'Passage contents do not match')
def test_base_download_kjv(self): download_path = './tmp/test_base_download_kjv/' bible = BaseDownloader(file_writing_function=yaml_file_interface.write, default_directory=download_path, translation='kjv') bible.download_book('Philemon') downloaded_file = yaml_file_interface.read( '{0}/Philemon'.format(download_path)) static_file_path = '{0}/test_base_download_kjv.yaml'.format( self.get_test_directory('KJV')) static_file = yaml_file_interface.read(static_file_path) self.assertEqual(downloaded_file['Philemon'], static_file['Philemon'], 'Passage contents do not match')
def test_base_download_passage_range(self): download_path = './tmp/test_base_download_passage_range/' bible = BaseDownloader(file_writing_function=yaml_file_interface.write, default_directory=download_path, translation=self.get_test_translation()) bible.download_passage_range('1 John', 1, 3, 1, 5) downloaded_file = yaml_file_interface.read( '{0}/1 John'.format(download_path)) static_file_path = '{0}/test_base_download_passage_range.yaml'.format( self.get_test_directory()) static_file = yaml_file_interface.read(static_file_path) self.assertEqual(downloaded_file['1 John'], static_file['1 John'], 'Passage contents do not match')
def test_base_download_with_stripped_whitespaces(self): download_path = './tmp/test_base_download_with_stripped_whitespaces/' bible = BaseDownloader(file_writing_function=yaml_file_interface.write, default_directory=download_path, strip_excess_whitespace=True, translation=self.get_test_translation()) bible.download_book('Philemon') downloaded_file = yaml_file_interface.read( '{0}/Philemon'.format(download_path)) static_file_path = '{0}/test_base_download_with_stripped_whitespaces.yaml'.format( self.get_test_directory()) static_file = yaml_file_interface.read(static_file_path) self.assertEqual(downloaded_file['Philemon'], static_file['Philemon'], 'Passage contents do not match')
def test_base_download_with_ascii_punctuation(self): download_path = './tmp/test_base_download_with_ascii_punctuation' static_file_path = '{0}/test_base_download_with_ascii_punctuation.yaml'.format( self.get_test_directory()) bible = BaseDownloader(file_writing_function=yaml_file_interface.write, default_directory=download_path, translation=self.get_test_translation(), use_ascii_punctuation=True) bible.download_book('Ecclesiastes') downloaded_file = yaml_file_interface.read( '{0}/Ecclesiastes'.format(download_path)) static_file = yaml_file_interface.read(static_file_path) self.assertEqual(downloaded_file['Ecclesiastes'], static_file['Ecclesiastes'], 'Passage contents do not match')
def test_base_download_omitted_passage(self): download_path = './tmp/test_base_download_omitted_passage/' bible = BaseDownloader(file_writing_function=yaml_file_interface.write, default_directory=download_path, translation='NLT') bible.download_book('Romans') text = yaml_file_interface.read( '{0}/Romans'.format(download_path))['Romans'][16][24] self.assertEqual('', text, 'Files do not match')
def test_read(self): document = yaml_file_interface.read( self.get_static_file('test_read.yaml')) self.assertEqual(list(document.keys()), ['Disco'], 'Main keys are incorrect') self.assertEqual(document['Disco'][1], 'Beatdown', 'First entry is incorrect') self.assertEqual(document['Disco'][2], 'Elysium', 'Second entry is incorrect')
def test_base_download_with_misc_info(self): download_path = './tmp/test_base_download_with_misc_info/NIV' bible = BaseDownloader(file_writing_function=yaml_file_interface.write, default_directory=download_path) bible.download_passage('Philemon', 1, 1) document = yaml_file_interface.read( '{0}/Philemon'.format(download_path)) # For some reason, the misc. info is always placed after the passage contents in these tests? self.assertEqual('English', document['Info']['Language'], 'Language info is not correct') self.assertEqual('NIV', document['Info']['Translation'], 'Translation info is not correct')
def test_read_empty_file(self): document = yaml_file_interface.read( self.get_static_file('test_read_empty_file.yaml')) self.assertEqual(document, None, 'Empty file was not handled correctly')