def get_netilt_xml(self, use_spine_as_toc): self.epub_archive = EpubArchive(self.epub_filename, use_spine_as_toc) document = etree.Element("document") add_element_with_text(document, "title", self.epub_archive.title) add_element_with_text(document, "authors", ", ".join(self.epub_archive.authors)) for page in self.epub_archive.pages: page_root_elem = self.chapter_elements.get(page.parent_page, document) page_elem = etree.Element("page") if page.children_pages: add_element_with_text(page_elem, "title", "Overview") chapter_elem = etree.Element("chapter") if page.get_page_title() is not None: add_element_with_text(chapter_elem, "title", page.get_page_title()) page_root_elem.append(chapter_elem) self.chapter_elements[page] = chapter_elem page_root_elem = chapter_elem else: if page.get_page_title() is not None: add_element_with_text(page_elem, "title", page.get_page_title()) page_root_elem.append(page_elem) for index, section in enumerate(page.sections): page_elem.append( epub_page_section_to_netilt(section, "section", index)) return document
def test_very_last_page_in_doc(self): archive = EpubArchive("test_data/nested_navpoints.epub", False) page = archive.pages[18] self.assertEqual( page.get_page_title(), "Side-by-Side Migration" ) self.assertTrue( page.page_content_parsed.find(".//body").text_content().strip().endswith( "after the migration is complete." ))
def test_middle_page(self): archive = EpubArchive("test_data/nested_navpoints.epub", False) page = archive.pages[11] self.assertEqual( page.get_page_title(), "Additional SQL Server 2008 R2 Enhancements for DBAs" ) self.assertEqual( len(page.page_content_parsed.find(".//body")), 3 # h4, p, ul ) self.assertTrue( page.page_content_parsed.find(".//body").text_content().strip().endswith( "operating systems that support Extended Protection." ))
def test_very_first_page_in_doc(self): archive = EpubArchive("test_data/nested_navpoints.epub", False) page = archive.pages[8] self.assertEqual( page.get_page_title(), "CHAPTER 1 SQL Server 2008 R2 Editions and Enhancements" ) self.assertEqual( len(page.page_content_parsed.find(".//body")), 3 # h2, p, p ) self.assertTrue( page.page_content_parsed.find(".//body").text_content().strip().endswith( "installation strategies are also identified." ))
def test_nested_pages(self): archive = EpubArchive("test_data/nested_navpoints.epub", False) self.assertEqual(len(archive.pages), 29) self.assertEqual( archive.pages[11].get_page_title(), 'Additional SQL Server 2008 R2 Enhancements for DBAs' ) self.assertEqual( archive.pages[11].parent_page.get_page_title(), 'SQL Server 2008 R2 Enhancements for DBAs' ) self.assertEqual( archive.pages[11].parent_page, archive.pages[9] ) self.assertEqual( archive.pages[9].parent_page.get_page_title(), "CHAPTER 1 SQL Server 2008 R2 Editions and Enhancements" ) self.assertEqual( archive.pages[9].parent_page, archive.pages[8] ) self.assertEqual( len(archive.pages[8].sections), 1 ) self.assertEqual( len(archive.pages[8].sections[0].children_sections), 0 ) self.assertEqual( archive.pages[8].parent_page.get_page_title(), "Part I Database Administration" ) self.assertEqual( archive.pages[8].parent_page, archive.pages[7] ) self.assertEqual( archive.pages[7].parent_page, None ) self.assertEqual( [p.get_page_title() for p in archive.pages[7].children_pages], ["CHAPTER 1 SQL Server 2008 R2 Editions and Enhancements", "CHAPTER 10 Self-Service Analysis with PowerPivot"] )
def test_search_headers_by_text(self): archive = EpubArchive("test_data/sicp.epub", False) page = archive.pages[5] self.assertEqual( page.get_page_title(), "1.1.2 Naming and the Environment" ) self.assertTrue( page.page_content_parsed.find(".//body").text_content().strip().startswith( "1.1.2 Naming and the Environment A critical aspect of a programming language" )) self.assertTrue( page.page_content_parsed.find(".//body").text_content().strip().endswith( "a number of different environments).9" )) self.assertEqual( len(page.sections), 1 ) self.assertEqual( len(page.sections[0].children_sections), 0 )
def test_nav_alice_short(self): simple_archive = EpubArchive("test_data/in1.epub", False) self.assertEqual(len(simple_archive.pages), 4) # all pages besides Cover
def test_alice_short(self): archive = EpubArchive("test_data/in1.epub") self.assertEqual(len(archive.pages), 5)