|
1 | 1 | """Unit test suite for the docx.text.paragraph module.""" |
2 | 2 |
|
3 | | -from typing import cast |
| 3 | +from typing import List, cast |
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
@@ -61,6 +61,27 @@ def it_provides_access_to_the_hyperlinks_it_contains( |
61 | 61 | expected = ["Hyperlink" for _ in range(count)] |
62 | 62 | assert actual == expected, f"expected: {expected}, got: {actual}" |
63 | 63 |
|
| 64 | + @pytest.mark.parametrize( |
| 65 | + ("p_cxml", "expected"), |
| 66 | + [ |
| 67 | + ("w:p", []), |
| 68 | + ("w:p/w:r", ["Run"]), |
| 69 | + ("w:p/w:hyperlink", ["Hyperlink"]), |
| 70 | + ("w:p/(w:r,w:hyperlink,w:r)", ["Run", "Hyperlink", "Run"]), |
| 71 | + ("w:p/(w:hyperlink,w:r,w:hyperlink)", ["Hyperlink", "Run", "Hyperlink"]), |
| 72 | + ], |
| 73 | + ) |
| 74 | + def it_can_iterate_its_inner_content_items( |
| 75 | + self, p_cxml: str, expected: List[str], fake_parent: t.StoryChild |
| 76 | + ): |
| 77 | + p = cast(CT_P, element(p_cxml)) |
| 78 | + paragraph = Paragraph(p, fake_parent) |
| 79 | + |
| 80 | + inner_content = paragraph.iter_inner_content() |
| 81 | + |
| 82 | + actual = [type(item).__name__ for item in inner_content] |
| 83 | + assert actual == expected, f"expected: {expected}, got: {actual}" |
| 84 | + |
64 | 85 | def it_knows_its_paragraph_style(self, style_get_fixture): |
65 | 86 | paragraph, style_id_, style_ = style_get_fixture |
66 | 87 | style = paragraph.style |
|
0 commit comments