Skip to content

Commit

Permalink
DocxDocument forward reference (#7852)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 committed Jun 13, 2024
1 parent c1c3399 commit 8de639b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions haystack/components/converters/docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DocxToDocument:
Converts Docx files to Documents.
Uses `python-docx` library to convert the Docx file to a document.
This component does not preserve page brakes in the original document.
This component does not preserve page breaks in the original document.
Usage example:
```python
Expand Down Expand Up @@ -115,7 +115,7 @@ def run(

return {"documents": documents}

def _get_docx_metadata(self, document: DocxDocument) -> Dict[str, Union[str, int, datetime]]:
def _get_docx_metadata(self, document: "DocxDocument") -> Dict[str, Union[str, int, datetime]]:
"""
Get all relevant data from the 'core_properties' attribute from a Docx Document.
Expand Down
9 changes: 4 additions & 5 deletions test/components/converters/test_docx_file_to_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ def test_run(self, test_files_path, docx_converter):
assert len(docs) == 1
assert "History" in docs[0].content

@pytest.mark.integration
def test_run_with_meta(self, test_files_path, docx_converter):
with patch("haystack.components.converters.docx.DocxToDocument"):
output = docx_converter.run(
sources=[test_files_path / "docx" / "sample_docx_1.docx"],
meta={"language": "it", "author": "test_author"},
)
output = docx_converter.run(
sources=[test_files_path / "docx" / "sample_docx_1.docx"], meta={"language": "it", "author": "test_author"}
)

# check that the metadata from the bytestream is merged with that from the meta parameter
assert output["documents"][0].meta["author"] == "test_author"
Expand Down

0 comments on commit 8de639b

Please sign in to comment.