From 38fa57e3488bad2aee1a0df1c756d0766f58930b Mon Sep 17 00:00:00 2001 From: Matteo Rosati Date: Thu, 23 Apr 2026 19:34:59 +0200 Subject: [PATCH] refactor rename add-data -> import --- chromy/cli.py | 11 +++++------ chromy/handlers/{add_data.py => import_data.py} | 2 +- tests/test_cli.py | 6 +++--- tests/test_handlers.py | 8 ++++---- 4 files changed, 13 insertions(+), 14 deletions(-) rename chromy/handlers/{add_data.py => import_data.py} (79%) diff --git a/chromy/cli.py b/chromy/cli.py index 801c0e0..8daa6a5 100644 --- a/chromy/cli.py +++ b/chromy/cli.py @@ -5,7 +5,7 @@ from typing import Annotated, Callable import typer from chromadb.errors import InternalError, NotFoundError -from chromy.handlers.add_data import handle_add_data +from chromy.handlers.import_data import handle_import from chromy.handlers.count_collection import handle_count_collection from chromy.handlers.create_collection import handle_create_collection from chromy.handlers.delete_collection import ( @@ -88,22 +88,21 @@ def count( @app.command( - "add-data", + "import", help="Chunk, embed, and add a file to a collection in the local Chroma database.", ) -def add_data( +def import_data( collection: Annotated[ str, typer.Argument(help="Name of the target collection."), ], 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: - _run(lambda: handle_add_data(collection, file)) + _run(lambda: handle_import(collection, file)) except NotFoundError: _fail(f"Collection '{collection}' does not exist.") except FileNotFoundError: diff --git a/chromy/handlers/add_data.py b/chromy/handlers/import_data.py similarity index 79% rename from chromy/handlers/add_data.py rename to chromy/handlers/import_data.py index e59b925..643d574 100644 --- a/chromy/handlers/add_data.py +++ b/chromy/handlers/import_data.py @@ -3,7 +3,7 @@ from __future__ import annotations from chromy.utilities import ingest_file -def handle_add_data(collection: str, file: str) -> int: +def handle_import(collection: str, file: str) -> int: records_added = ingest_file(collection, file) print(f"Added {records_added} records to collection '{collection}'.") return 0 diff --git a/tests/test_cli.py b/tests/test_cli.py index 910c560..f23c986 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -53,12 +53,12 @@ class CliTests(unittest.TestCase): self.assertEqual(result.exit_code, 0) self.assertEqual(result.stdout, "7\n") - def test_add_data(self) -> None: + def test_import_data(self) -> None: with patch( - "chromy.handlers.add_data.ingest_file", + "chromy.handlers.import_data.ingest_file", return_value=3, ) as ingest_file: - result = _invoke(["add-data", "notes", "romeo_and_juliet.txt"]) + result = _invoke(["import", "notes", "romeo_and_juliet.txt"]) ingest_file.assert_called_once_with("notes", "romeo_and_juliet.txt") self.assertEqual(result.exit_code, 0) diff --git a/tests/test_handlers.py b/tests/test_handlers.py index 5ebbedb..49fb01f 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -7,7 +7,7 @@ from contextlib import redirect_stdout from typing import TypeVar from unittest.mock import patch -from chromy.handlers.add_data import handle_add_data +from chromy.handlers.import_data import handle_import from chromy.handlers.count_collection import handle_count_collection from chromy.handlers.create_collection import handle_create_collection from chromy.handlers.delete_collection import ( @@ -83,13 +83,13 @@ class HandlerTests(unittest.TestCase): self.assertEqual(exit_code, 0) self.assertEqual(output, "7\n") - def test_add_data_uses_typed_input(self) -> None: + def test_import_data_uses_typed_input(self) -> None: with patch( - "chromy.handlers.add_data.ingest_file", + "chromy.handlers.import_data.ingest_file", return_value=3, ) as ingest_file: exit_code, output = _capture_output( - handle_add_data, + handle_import, "notes", "romeo_and_juliet.txt", )