def test_book_save(self): book_001 = epub.Book() book_001.load('../geroi_nashego_vremeni.epub') paths_to_delete_001 = book_001.clear() book_001.save('book_save_test.epub', paths_to_delete_001) book_002 = epub.Book() book_002.load('book_save_test.epub') produced = book_002.get_descr().save() expected = read_file('new_meta4.xml') self.assertEqual(produced, expected)
def test_chapters(self): book = epub.Book(self.epub_file) self.assertEquals(len(book.chapters), 6) for chapter in book.chapters: self.assertIsNotNone(chapter) self.assertIsInstance(chapter, epub.BookChapter)
def test_metadata_contributors(self): name = 'Johnson Cave' role = 'oth' file_as = 'Cave, Johnson' self.epub_file.opf.metadata.add_contributor(name, role, file_as) book = epub.Book(self.epub_file) self.assertIn((name, role, file_as), book.contributors)
def __init__(self, filePath, removeFileWhenComplete=False): EBookBase.__init__(self, filePath, removeFileWhenComplete) self.bookFile = None self.book = None try: self.bookFile = epub.open_epub(self.filePath) self.book = epub.Book(self.bookFile) except: log("EPubEBook: Failed to process eBook %s with error: %s" % (self.filePath, traceback.format_exc()), xbmc.LOGERROR)
def test_source(self): self.epub_file.opf.metadata.source = 'test_source' book = epub.Book(self.epub_file) self.assertEquals(book.source, 'test_source')
def test_identifiers(self): book = epub.Book(self.epub_file) self.assertEquals(book.identifiers, [('urn:uuid:477d1a82-a70d-4ee5-a0ff-0dddc60fd2bb', 'BookId', 'UUID')])
def test_dc_format(self): self.epub_file.opf.metadata.format = 'test_format' book = epub.Book(self.epub_file) self.assertEquals(book.dc_format, 'test_format')
def test_titles(self): title = 'New test title' lang = 'fra_alt' self.epub_file.opf.metadata.add_title(title, lang) book = epub.Book(self.epub_file) self.assertIn((title, lang), book.titles)
def test_metas(self): name = 'meta_name' content = 'meta_content' self.epub_file.opf.metadata.add_meta(name, content) book = epub.Book(self.epub_file) self.assertIn((name, content), book.metas)
def test_coverage(self): self.epub_file.opf.metadata.coverage = 'test_coverage' book = epub.Book(self.epub_file) self.assertEquals(book.coverage, 'test_coverage')
def test_metadata_isbn(self): isbn = '7814-54654-4354-43545' self.epub_file.opf.metadata.add_identifier(isbn, 'ID_ISBN', 'isbn') book = epub.Book(self.epub_file) self.assertEquals(book.isbn, isbn)
def test_metadata_description(self): description = self.epub_file.opf.metadata.description book = epub.Book(self.epub_file) self.assertEquals(book.description, description)
def test_extra_chapters(self): book = epub.Book(self.epub_file) self.assertEquals(len(list(book.extra_chapters)), 0)
def test_book_load(self): book = epub.Book() book.load('../geroi_nashego_vremeni.epub') produced = book.get_descr().save() expected = read_file('meta4.xml') self.assertEqual(produced, expected)
def test_languages(self): lang = 'test_lang' self.epub_file.opf.metadata.add_language(lang) book = epub.Book(self.epub_file) self.assertIn(lang, book.languages)
def test_relation(self): self.epub_file.opf.metadata.relation = 'test_relation' book = epub.Book(self.epub_file) self.assertEquals(book.relation, 'test_relation')
def test_metadata_publisher(self): publisher = 'TEST_PUBLISHER' self.epub_file.opf.metadata.publisher = publisher book = epub.Book(self.epub_file) self.assertEquals(book.publisher, publisher)
def test_right(self): self.epub_file.opf.metadata.right = 'test_right' book = epub.Book(self.epub_file) self.assertEquals(book.right, 'test_right')
def test_dates(self): date = '2032-08-04' event = 'publication' self.epub_file.opf.metadata.add_date(date, event) book = epub.Book(self.epub_file) self.assertIn((date, event), book.dates)
def test_subjects(self): title = 'New test subject' self.epub_file.opf.metadata.add_subject(title) book = epub.Book(self.epub_file) self.assertIn(title, book.subjects)
def test_dc_type(self): self.epub_file.opf.metadata.dc_type = 'test_type' book = epub.Book(self.epub_file) self.assertEquals(book.dc_type, 'test_type')
def setUp(self): self.epub_file = epub.open_epub(self.epub_path) self.book = epub.Book(self.epub_file)
def get_book(query): book = epub.Book() book.load(query['epub_file'][0]) epub_zip = zipfile.ZipFile(query['epub_file'][0]) return book, epub_zip