|
2 | 2 |
|
3 | 3 | from haystack.components.evaluators.document_recall import DocumentRecallEvaluator, RecallMode
|
4 | 4 | from haystack.dataclasses import Document
|
| 5 | +from haystack import default_from_dict |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def test_init_with_unknown_mode_string():
|
@@ -78,6 +79,21 @@ def test_run_with_different_lengths(self, evaluator):
|
78 | 79 | retrieved_documents=[[Document(content="Berlin")]],
|
79 | 80 | )
|
80 | 81 |
|
| 82 | + def test_to_dict(self, evaluator): |
| 83 | + data = evaluator.to_dict() |
| 84 | + assert data == { |
| 85 | + "type": "haystack.components.evaluators.document_recall.DocumentRecallEvaluator", |
| 86 | + "init_parameters": {"mode": "single_hit"}, |
| 87 | + } |
| 88 | + |
| 89 | + def test_from_dict(self): |
| 90 | + data = { |
| 91 | + "type": "haystack.components.evaluators.document_recall.DocumentRecallEvaluator", |
| 92 | + "init_parameters": {"mode": "single_hit"}, |
| 93 | + } |
| 94 | + new_evaluator = default_from_dict(DocumentRecallEvaluator, data) |
| 95 | + assert new_evaluator.mode == RecallMode.SINGLE_HIT |
| 96 | + |
81 | 97 |
|
82 | 98 | class TestDocumentRecallEvaluatorMultiHit:
|
83 | 99 | @pytest.fixture
|
@@ -152,3 +168,18 @@ def test_run_with_different_lengths(self, evaluator):
|
152 | 168 | ground_truth_documents=[[Document(content="Berlin")], [Document(content="Paris")]],
|
153 | 169 | retrieved_documents=[[Document(content="Berlin")]],
|
154 | 170 | )
|
| 171 | + |
| 172 | + def test_to_dict(self, evaluator): |
| 173 | + data = evaluator.to_dict() |
| 174 | + assert data == { |
| 175 | + "type": "haystack.components.evaluators.document_recall.DocumentRecallEvaluator", |
| 176 | + "init_parameters": {"mode": "multi_hit"}, |
| 177 | + } |
| 178 | + |
| 179 | + def test_from_dict(self): |
| 180 | + data = { |
| 181 | + "type": "haystack.components.evaluators.document_recall.DocumentRecallEvaluator", |
| 182 | + "init_parameters": {"mode": "multi_hit"}, |
| 183 | + } |
| 184 | + new_evaluator = default_from_dict(DocumentRecallEvaluator, data) |
| 185 | + assert new_evaluator.mode == RecallMode.MULTI_HIT |
0 commit comments