Skip to content

Commit

Permalink
Added Doc.__hash__, with test (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza authored Mar 7, 2024
1 parent e8e4789 commit 104a652
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions paperqa/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Doc(Embeddable):
citation: str
dockey: DocKey

def __hash__(self) -> int:
return hash((self.docname, self.dockey))


class Text(Embeddable):
text: str
Expand Down
16 changes: 13 additions & 3 deletions tests/test_paperqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,21 +641,31 @@ async def my_callback(result):
assert len(my_results) > 1


def test_duplicate():
def test_duplicate() -> None:
"""Check Docs doesn't store duplicates, while checking nonduplicate docs are stored."""
docs = Docs()
assert docs.add_url(
"https://en.wikipedia.org/wiki/Frederick_Bates_(politician)",
citation="WikiMedia Foundation, 2023, Accessed now",
dockey="test",
dockey="test1",
)
assert (
docs.add_url(
"https://en.wikipedia.org/wiki/Frederick_Bates_(politician)",
citation="WikiMedia Foundation, 2023, Accessed now",
dockey="test",
dockey="test1",
)
is None
)
assert len(docs.docs) == 1, "Should have added only one document"
assert docs.add_url(
"https://en.wikipedia.org/wiki/National_Flag_of_Canada_Day",
citation="WikiMedia Foundation, 2023, Accessed now",
dockey="test2",
)
assert (
len(set(docs.docs.values())) == 2
), "Unique documents should be hashed as unique"


def test_custom_embedding():
Expand Down

0 comments on commit 104a652

Please sign in to comment.