-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for single meta dict in
TextFileToDocument
(#6606)
* add support for single meta dict * reno * reno * mypy * extract to function * docstring * mypy
- Loading branch information
Showing
4 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
releasenotes/notes/single-metadata-txt-converter-a02bf90c60262701.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
features: | ||
- | | ||
Adds support for single metadata dictionary input in `TextFileToDocument``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
from haystack.components.converters.utils import normalize_metadata | ||
|
||
|
||
def test_normalize_metadata_None(): | ||
assert normalize_metadata(None, sources_count=1) == [{}] | ||
assert normalize_metadata(None, sources_count=3) == [{}, {}, {}] | ||
|
||
|
||
def test_normalize_metadata_single_dict(): | ||
assert normalize_metadata({"a": 1}, sources_count=1) == [{"a": 1}] | ||
assert normalize_metadata({"a": 1}, sources_count=3) == [{"a": 1}, {"a": 1}, {"a": 1}] | ||
|
||
|
||
def test_normalize_metadata_list_of_right_size(): | ||
assert normalize_metadata([{"a": 1}], sources_count=1) == [{"a": 1}] | ||
assert normalize_metadata([{"a": 1}, {"b": 2}, {"c": 3}], sources_count=3) == [{"a": 1}, {"b": 2}, {"c": 3}] | ||
|
||
|
||
def test_normalize_metadata_list_of_wrong_size(): | ||
with pytest.raises(ValueError, match="The length of the metadata list must match the number of sources."): | ||
normalize_metadata([{"a": 1}], sources_count=3) | ||
with pytest.raises(ValueError, match="The length of the metadata list must match the number of sources."): | ||
assert normalize_metadata([{"a": 1}, {"b": 2}, {"c": 3}], sources_count=1) | ||
|
||
|
||
def test_normalize_metadata_other_type(): | ||
with pytest.raises(ValueError, match="meta must be either None, a dictionary or a list of dictionaries."): | ||
normalize_metadata(({"a": 1},), sources_count=1) |