Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
carschno committed Dec 3, 2024
1 parent ec9673d commit b87086b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tempo_embeddings/text/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def centroid(self, use_2d_embeddings: bool = True) -> np.ndarray:
"""The mean for all passage embeddings."""
embeddings = self._select_embeddings(use_2d_embeddings)

if embeddings is None:
raise RuntimeError("No embeddings available.")
assert embeddings is not None, "No embeddings available."

return embeddings.mean(axis=0)

def coordinates(self) -> pd.DataFrame:
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/text/test_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ def test_fit_umap(self, corpus):
with pytest.raises(RuntimeError):
corpus._fit_umap()

with pytest.raises(RuntimeError):
corpus.passages[0]._embedding = None
corpus._fit_umap()

def test_sum(self, corpus):
with pytest.raises(ValueError):
Corpus.sum(corpus, corpus)
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/text/test_passage.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ def test_to_dict(self, passage, expected):
def test_init(self, text, metadata, expected):
assert Passage(text, metadata) == expected

@pytest.mark.parametrize(
"embedding_compressed, exception",
[(None, None), ([1.0, 2.0], None), ([1, 2], pytest.raises(ValueError))],
)
def test_init_embeddings_compressed(self, embedding_compressed, exception):
with exception or does_not_raise():
passage = Passage("test", embedding_compressed=embedding_compressed)
assert passage.embedding_compressed == embedding_compressed

@pytest.mark.parametrize(
"passage,expected",
[
Expand Down

0 comments on commit b87086b

Please sign in to comment.