def test_run3(self): # Test3: Tests for strikethroughs docx_path = r'test3.docx' paragraphs = wth.retrieve_paragraphs(docx_path) correct_html_lines = self.convert_to_html_lines_from_paragraphs(paragraphs) paragraphs_again = wth.retrieve_paragraphs(docx_path) html_lines = wth.convert_to_html_lines_from_paragraphs(paragraphs_again) self.assertEqual(correct_html_lines, html_lines) wth.save_as_html(html_lines, "test3.html")
def test_run1(self): # Test1: Basic test of the formatting and html output # Also tests bold, italics, underline, and symbols # Saves HTML the normal way from paragraphs docx_path = r'test.docx' paragraphs = wth.retrieve_paragraphs(docx_path) correct_html_lines = self.convert_to_html_lines_from_paragraphs(paragraphs) paragraphs_again = wth.retrieve_paragraphs(docx_path) html_lines = wth.convert_to_html_lines_from_paragraphs(paragraphs_again) self.assertEqual(correct_html_lines, html_lines) wth.save_as_html(html_lines, "test1")
def test_run2(self): # Test2: Tests for linebreaks # Saves HTML the faster way directly from Path docx_path = r'test2.docx' paragraphs = wth.retrieve_paragraphs(docx_path) correct_html_lines = self.convert_to_html_lines_from_paragraphs(paragraphs) html_lines = wth.convert_to_html_lines_from_path(docx_path) self.assertEqual(correct_html_lines, html_lines) wth.save_as_html(html_lines, "test2.html")
def test_needs_linebreak_before(self): docx_path = r'test2.docx' paragraphs = wth.retrieve_paragraphs(docx_path) for paragraph in paragraphs: groups = paragraph.iter(self.NAMESPACE_GROUP) for group in groups: linebreaks = group.iter(self.NAMESPACE_LINEBREAK) needs_linebreak_before = False for linebreak in linebreaks: needs_linebreak_before = True self.assertEqual(needs_linebreak_before, wth.needs_linebreak_before(group))
def test_is_strike(self): docx_path = r'test3.docx' paragraphs = wth.retrieve_paragraphs(docx_path) for paragraph in paragraphs: groups = paragraph.iter(self.NAMESPACE_GROUP) for group in groups: strikes = group.iter(self.NAMESPACE_STRIKE) is_strike = False for strike in strikes: is_strike = True self.assertEqual(is_strike, wth.is_strike(group))
def setUp(self): self.NAMESPACE = "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}" self.NAMESPACE_GROUP = self.NAMESPACE + "r" self.NAMESPACE_BOLD = self.NAMESPACE + "b" self.NAMESPACE_ITALICS = self.NAMESPACE + "i" self.NAMESPACE_UNDERLINE = self.NAMESPACE + "u" self.NAMESPACE_LINEBREAK = self.NAMESPACE + "br" self.NAMESPACE_STRIKE = self.NAMESPACE + "strike" self.DOCX_PATH = r'test.docx' self.paragraphs = wth.retrieve_paragraphs(self.DOCX_PATH) self.text = "Hello"