Compare commits

...

3 Commits

Author SHA1 Message Date
Matteo Rosati 6861636794 add test test_delete_non_existent_collection
build / build (push) Successful in 10s
pytest / pytest (push) Successful in 24s
2026-04-23 21:13:35 +02:00
Matteo Rosati 7ee58939a6 add test test_create_collection_with_same_name 2026-04-23 21:06:41 +02:00
Matteo Rosati 13d2f525a9 fix syntax 2026-04-23 21:06:31 +02:00
2 changed files with 28 additions and 2 deletions
+2 -1
View File
@@ -113,7 +113,8 @@ def import_data(
],
file: Annotated[
str,
typer.Argument(help="Path to the file to chunk and add to the collection."),
typer.Argument(
help="Path to the file to chunk and add to the collection."),
],
) -> None:
try:
+26 -1
View File
@@ -5,6 +5,7 @@ from collections.abc import Sequence
from pathlib import Path
from unittest.mock import patch
from chromadb.errors import InternalError, NotFoundError
from click.testing import Result
from typer.testing import CliRunner
@@ -47,6 +48,18 @@ class CliTests(unittest.TestCase):
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Created collection 'notes'.\n")
def test_create_collection_with_same_name(self) -> None:
with patch(
"chromy.handlers.create_collection.create_collection",
side_effect=InternalError()
) as create_collection:
result = _invoke(["create-collection", "notes"])
create_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 1)
self.assertEqual(result.stdout, "Collection 'notes' already exists.\n")
def test_delete_collection(self) -> None:
with patch(
"chromy.handlers.delete_collection.delete_collection",
@@ -57,6 +70,17 @@ class CliTests(unittest.TestCase):
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Deleted collection 'notes'.\n")
def test_delete_non_existent_collection(self) -> None:
with patch(
"chromy.handlers.delete_collection.delete_collection",
side_effect=NotFoundError()
) as delete_collection:
result = _invoke(["delete-collection", "notes"])
delete_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 1)
self.assertEqual(result.stdout, "Collection 'notes' does not exist.\n")
def test_count(self) -> None:
with patch(
"chromy.handlers.count_collection.count_collection",
@@ -80,7 +104,8 @@ class CliTests(unittest.TestCase):
self._fixture_path("romeo_and_juliet.txt"),
)
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Added 3 records to collection 'notes'.\n")
self.assertEqual(
result.stdout, "Added 3 records to collection 'notes'.\n")
def test_query(self) -> None:
query_result = {"ids": [["1"]], "documents": [["hello"]]}