From b27e444a505857332ffd6a9640f31984f570e64a Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 22 Mar 2026 16:21:32 +0000 Subject: [PATCH] Add conftest.py and remaining test files --- tests/integration/test_cli.py | 91 +++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/integration/test_cli.py diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py new file mode 100644 index 0000000..dede93f --- /dev/null +++ b/tests/integration/test_cli.py @@ -0,0 +1,91 @@ +"""Integration tests for CLI commands.""" + +import os +import pytest +from click.testing import CliRunner +from memory_manager.cli.main import cli + +TEST_DB_PATH = ".memory/test_cli_memory.db" + + +def clean_test_db(): + if os.path.exists(TEST_DB_PATH): + os.remove(TEST_DB_PATH) + db_dir = os.path.dirname(TEST_DB_PATH) + if db_dir and not os.path.exists(db_dir): + os.makedirs(db_dir, exist_ok=True) + + +@pytest.fixture(autouse=True) +def reset_env(): + clean_test_db() + os.environ["MEMORY_DB_PATH"] = TEST_DB_PATH + yield + clean_test_db() + + +@pytest.fixture +def runner(): + return CliRunner() + + +def test_cli_version(runner): + result = runner.invoke(cli, ["--version"]) + assert result.exit_code == 0 + assert "0.1.0" in result.output + + +def test_add_command_no_tags(runner): + result = runner.invoke(cli, [ + "add", + "--title", "Test Decision", + "--content", "We decided to use PostgreSQL", + "--category", "decision", + ]) + assert result.exit_code == 0 + + +def test_add_command_invalid_category(runner): + result = runner.invoke(cli, [ + "add", + "--title", "Test", + "--content", "Content", + "--category", "invalid_category", + ]) + assert result.exit_code != 0 + + +def test_list_command_empty(runner): + result = runner.invoke(cli, ["list"]) + assert result.exit_code == 0 + assert "No entries found" in result.output + + +def test_get_command_empty(runner): + result = runner.invoke(cli, ["get", "1"]) + assert result.exit_code == 0 + assert "not found" in result.output + + +def test_delete_command_not_found(runner): + result = runner.invoke(cli, ["delete", "1"]) + assert result.exit_code == 0 + assert "not found" in result.output + + +def test_commit_command_empty(runner): + result = runner.invoke(cli, ["commit", "--message", "Initial commit"]) + assert result.exit_code == 0 + assert "Created commit" in result.output + + +def test_log_command(runner): + runner.invoke(cli, ["commit", "--message", "Test commit"]) + result = runner.invoke(cli, ["log"]) + assert result.exit_code == 0 + assert "commit" in result.output + + +def test_diff_command_no_commits(runner): + result = runner.invoke(cli, ["diff", "abc123", "def456"]) + assert result.exit_code == 0