Compare commits
3 Commits
65b3edda1c
...
6861636794
| Author | SHA1 | Date | |
|---|---|---|---|
| 6861636794 | |||
| 7ee58939a6 | |||
| 13d2f525a9 |
+2
-1
@@ -113,7 +113,8 @@ def import_data(
|
|||||||
],
|
],
|
||||||
file: Annotated[
|
file: Annotated[
|
||||||
str,
|
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:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
|
|||||||
+26
-1
@@ -5,6 +5,7 @@ from collections.abc import Sequence
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from chromadb.errors import InternalError, NotFoundError
|
||||||
from click.testing import Result
|
from click.testing import Result
|
||||||
from typer.testing import CliRunner
|
from typer.testing import CliRunner
|
||||||
|
|
||||||
@@ -47,6 +48,18 @@ class CliTests(unittest.TestCase):
|
|||||||
self.assertEqual(result.exit_code, 0)
|
self.assertEqual(result.exit_code, 0)
|
||||||
self.assertEqual(result.stdout, "Created collection 'notes'.\n")
|
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:
|
def test_delete_collection(self) -> None:
|
||||||
with patch(
|
with patch(
|
||||||
"chromy.handlers.delete_collection.delete_collection",
|
"chromy.handlers.delete_collection.delete_collection",
|
||||||
@@ -57,6 +70,17 @@ class CliTests(unittest.TestCase):
|
|||||||
self.assertEqual(result.exit_code, 0)
|
self.assertEqual(result.exit_code, 0)
|
||||||
self.assertEqual(result.stdout, "Deleted collection 'notes'.\n")
|
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:
|
def test_count(self) -> None:
|
||||||
with patch(
|
with patch(
|
||||||
"chromy.handlers.count_collection.count_collection",
|
"chromy.handlers.count_collection.count_collection",
|
||||||
@@ -80,7 +104,8 @@ class CliTests(unittest.TestCase):
|
|||||||
self._fixture_path("romeo_and_juliet.txt"),
|
self._fixture_path("romeo_and_juliet.txt"),
|
||||||
)
|
)
|
||||||
self.assertEqual(result.exit_code, 0)
|
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:
|
def test_query(self) -> None:
|
||||||
query_result = {"ids": [["1"]], "documents": [["hello"]]}
|
query_result = {"ids": [["1"]], "documents": [["hello"]]}
|
||||||
|
|||||||
Reference in New Issue
Block a user