Skip to content

Commit

Permalink
test for doc helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tranade committed Jul 30, 2024
1 parent 2f5a426 commit f161b7b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/sycamore/sycamore/tests/unit/functions/test_field_to_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from sycamore.data.document import Document

class TestFieldToValue:
def test_field_to_value(self):
doc = Document(
text_representation="hello",
doc_id=1,
properties={"letter": "A", "animal": "panda", "math": {"pi": 3.14, "e": 2.72, "tanx": "sinx/cosx"}},
)

assert doc.field_to_value("text_representation") == "hello"
assert doc.field_to_value("doc_id") == 1
assert doc.field_to_value("properties.letter") == "A"
assert doc.field_to_value("properties.animal") == "panda"
assert doc.field_to_value("properties.math.pi") == 3.14
assert doc.field_to_value("properties.math.e") == 2.72
assert doc.field_to_value("properties.math.tanx") == "sinx/cosx"

assert doc.field_to_value("properties.math.log") is None
assert doc.field_to_value("document_id") is None
assert doc.field_to_value("text_representation.text") is None
assert doc.field_to_value("document_id.text") is None

0 comments on commit f161b7b

Please sign in to comment.