|
1 | 1 | import os |
| 2 | +from pathlib import Path |
2 | 3 | import unittest |
3 | 4 | from docx import Document |
4 | 5 | from .context import HtmlToDocx, test_dir |
5 | 6 |
|
6 | 7 | class OutputTest(unittest.TestCase): |
7 | 8 |
|
| 9 | + @staticmethod |
| 10 | + def get_html_from_file(filename: str): |
| 11 | + file_path = Path(test_dir) / Path(filename) |
| 12 | + with open(file_path, 'r') as f: |
| 13 | + html = f.read() |
| 14 | + return html |
| 15 | + |
8 | 16 | @classmethod |
9 | 17 | def setUpClass(cls): |
10 | 18 | cls.document = Document() |
11 | | - textpath = os.path.join(test_dir, 'text1.html') |
12 | | - tablepath = os.path.join(test_dir, 'tables1.html') |
13 | | - with open(textpath, 'r') as tb: |
14 | | - cls.text1 = tb.read() |
15 | | - with open(tablepath, 'r') as tb: |
16 | | - cls.table_html = tb.read() |
| 19 | + cls.text1 = cls.get_html_from_file('text1.html') |
| 20 | + cls.table_html = cls.get_html_from_file('tables1.html') |
| 21 | + cls.table2_html = cls.get_html_from_file('tables2.html') |
17 | 22 |
|
18 | 23 | @classmethod |
19 | 24 | def tearDownClass(cls): |
@@ -54,6 +59,40 @@ def test_add_html_with_tables(self): |
54 | 59 | ) |
55 | 60 | self.parser.add_html_to_document(self.table_html, self.document) |
56 | 61 |
|
| 62 | + def test_add_html_with_tables_accent_style(self): |
| 63 | + self.document.add_heading( |
| 64 | + 'Test: add html with tables with accent', |
| 65 | + ) |
| 66 | + self.parser.table_style = 'Light Grid Accent 6' |
| 67 | + self.parser.add_html_to_document(self.table_html, self.document) |
| 68 | + |
| 69 | + def test_add_html_with_tables_basic_style(self): |
| 70 | + self.document.add_heading( |
| 71 | + 'Test: add html with tables with basic style', |
| 72 | + ) |
| 73 | + self.parser.table_style = 'TableGrid' |
| 74 | + self.parser.add_html_to_document(self.table_html, self.document) |
| 75 | + |
| 76 | + def test_add_nested_tables(self): |
| 77 | + self.document.add_heading( |
| 78 | + 'Test: add nested tables', |
| 79 | + ) |
| 80 | + self.parser.add_html_to_document(self.table2_html, self.document) |
| 81 | + |
| 82 | + def test_add_nested_tables_basic_style(self): |
| 83 | + self.document.add_heading( |
| 84 | + 'Test: add nested tables with basic style', |
| 85 | + ) |
| 86 | + self.parser.table_style = 'TableGrid' |
| 87 | + self.parser.add_html_to_document(self.table2_html, self.document) |
| 88 | + |
| 89 | + def test_add_nested_tables_accent_style(self): |
| 90 | + self.document.add_heading( |
| 91 | + 'Test: add nested tables with accent style', |
| 92 | + ) |
| 93 | + self.parser.table_style = 'Light Grid Accent 6' |
| 94 | + self.parser.add_html_to_document(self.table2_html, self.document) |
| 95 | + |
57 | 96 | def test_add_html_skip_tables(self): |
58 | 97 | # broken until feature readded |
59 | 98 | self.document.add_heading( |
|
0 commit comments