|
2 | 2 | import pathlib
|
3 | 3 | import pytest
|
4 | 4 |
|
| 5 | +import pptx |
| 6 | + |
5 | 7 | from unstructured.partition.pptx import partition_pptx
|
6 |
| -from unstructured.documents.elements import ListItem, NarrativeText, Title |
| 8 | +from unstructured.documents.elements import ListItem, NarrativeText, Text, Title |
7 | 9 |
|
8 | 10 | DIRECTORY = pathlib.Path(__file__).parent.resolve()
|
9 | 11 | EXAMPLE_DOCS_DIRECTORY = os.path.join(DIRECTORY, "..", "..", "example-docs")
|
@@ -41,3 +43,47 @@ def test_partition_pptx_raises_with_both_specified():
|
41 | 43 | def test_partition_pptx_raises_with_neither():
|
42 | 44 | with pytest.raises(ValueError):
|
43 | 45 | partition_pptx()
|
| 46 | + |
| 47 | + |
| 48 | +def test_partition_pptx_orders_elements(tmpdir): |
| 49 | + filename = os.path.join(tmpdir, "test-ordering.pptx") |
| 50 | + |
| 51 | + presentation = pptx.Presentation() |
| 52 | + blank_slide_layout = presentation.slide_layouts[6] |
| 53 | + slide = presentation.slides.add_slide(blank_slide_layout) |
| 54 | + |
| 55 | + left = top = width = height = pptx.util.Inches(2) |
| 56 | + txBox = slide.shapes.add_textbox(left, top, width, height) |
| 57 | + tf = txBox.text_frame |
| 58 | + tf.text = "This is lower and should come second" |
| 59 | + |
| 60 | + left = top = width = height = pptx.util.Inches(1) |
| 61 | + left = top = pptx.util.Inches(-10) |
| 62 | + txBox = slide.shapes.add_textbox(left, top, width, height) |
| 63 | + tf = txBox.text_frame |
| 64 | + tf.text = "This is off the page and shouldn't appear" |
| 65 | + |
| 66 | + left = top = width = height = pptx.util.Inches(2) |
| 67 | + txBox = slide.shapes.add_textbox(left, top, width, height) |
| 68 | + tf = txBox.text_frame |
| 69 | + tf.text = "" |
| 70 | + |
| 71 | + left = top = width = height = pptx.util.Inches(1) |
| 72 | + txBox = slide.shapes.add_textbox(left, top, width, height) |
| 73 | + tf = txBox.text_frame |
| 74 | + tf.text = "This is higher and should come first" |
| 75 | + |
| 76 | + top = width = height = pptx.util.Inches(1) |
| 77 | + left = pptx.util.Inches(0.5) |
| 78 | + txBox = slide.shapes.add_textbox(left, top, width, height) |
| 79 | + tf = txBox.text_frame |
| 80 | + tf.text = "-------------TOP-------------" |
| 81 | + |
| 82 | + presentation.save(filename) |
| 83 | + |
| 84 | + elements = partition_pptx(filename=filename) |
| 85 | + assert elements == [ |
| 86 | + Text("-------------TOP-------------"), |
| 87 | + NarrativeText("This is higher and should come first"), |
| 88 | + NarrativeText("This is lower and should come second"), |
| 89 | + ] |
0 commit comments