|
2 | 2 |
|
3 | 3 | These tests use real MCP tools with the test environment instead of mocks. |
4 | 4 | """ |
| 5 | + |
5 | 6 | # Import the ensure_migrations function from main.py for testing |
6 | | -import asyncio |
7 | 7 | from basic_memory.cli.main import ensure_migrations |
8 | 8 |
|
9 | 9 | import io |
@@ -418,31 +418,35 @@ def test_continue_conversation_no_results(cli_env): |
418 | 418 | @patch("basic_memory.cli.main.db_run_migrations") |
419 | 419 | def test_ensure_migrations_runs_migrations(mock_run_migrations, test_config, monkeypatch): |
420 | 420 | """Test that ensure_migrations runs migrations.""" |
| 421 | + |
421 | 422 | # Configure mock |
422 | 423 | async def mock_async_success(*args, **kwargs): |
423 | 424 | return True |
424 | | - |
| 425 | + |
425 | 426 | mock_run_migrations.return_value = mock_async_success() |
426 | | - |
| 427 | + |
427 | 428 | # Call the function |
428 | 429 | ensure_migrations() |
429 | | - |
| 430 | + |
430 | 431 | # Check that run_migrations was called |
431 | 432 | mock_run_migrations.assert_called_once() |
432 | 433 |
|
433 | 434 |
|
434 | 435 | @patch("basic_memory.cli.main.db_run_migrations") |
435 | 436 | @patch("basic_memory.cli.main.logger") |
436 | | -def test_ensure_migrations_handles_errors(mock_logger, mock_run_migrations, test_config, monkeypatch): |
| 437 | +def test_ensure_migrations_handles_errors( |
| 438 | + mock_logger, mock_run_migrations, test_config, monkeypatch |
| 439 | +): |
437 | 440 | """Test that ensure_migrations handles errors gracefully.""" |
| 441 | + |
438 | 442 | # Configure mock to raise an exception when awaited |
439 | 443 | async def mock_async_error(*args, **kwargs): |
440 | 444 | raise Exception("Test error") |
441 | | - |
| 445 | + |
442 | 446 | mock_run_migrations.side_effect = mock_async_error |
443 | | - |
| 447 | + |
444 | 448 | # Call the function |
445 | 449 | ensure_migrations() |
446 | | - |
| 450 | + |
447 | 451 | # Check that error was logged |
448 | 452 | mock_logger.error.assert_called_once() |
0 commit comments