fix tests
This commit is contained in:
@@ -7,11 +7,10 @@ Tests the functionality of SeriesApp including:
|
||||
- Download with progress callbacks
|
||||
- Directory scanning with progress reporting
|
||||
- Async versions of operations
|
||||
- Cancellation support
|
||||
- Error handling
|
||||
"""
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -35,62 +34,30 @@ class TestSeriesAppInitialization:
|
||||
|
||||
# Verify initialization
|
||||
assert app.directory_to_search == test_dir
|
||||
assert app._operation_status == OperationStatus.IDLE
|
||||
assert app._cancel_flag is False
|
||||
assert app._current_operation is None
|
||||
mock_loaders.assert_called_once()
|
||||
mock_scanner.assert_called_once()
|
||||
|
||||
@patch('src.core.SeriesApp.Loaders')
|
||||
@patch('src.core.SeriesApp.SerieScanner')
|
||||
@patch('src.core.SeriesApp.SerieList')
|
||||
def test_init_with_callbacks(
|
||||
self, mock_serie_list, mock_scanner, mock_loaders
|
||||
):
|
||||
"""Test initialization with progress and error callbacks."""
|
||||
def test_init_failure_raises_error(self, mock_loaders):
|
||||
"""Test that initialization failure raises error."""
|
||||
test_dir = "/test/anime"
|
||||
progress_callback = Mock()
|
||||
error_callback = Mock()
|
||||
|
||||
# Create app with callbacks
|
||||
app = SeriesApp(
|
||||
test_dir,
|
||||
progress_callback=progress_callback,
|
||||
error_callback=error_callback
|
||||
)
|
||||
|
||||
# Verify callbacks are stored
|
||||
assert app.progress_callback == progress_callback
|
||||
assert app.error_callback == error_callback
|
||||
|
||||
@patch('src.core.SeriesApp.Loaders')
|
||||
def test_init_failure_calls_error_callback(self, mock_loaders):
|
||||
"""Test that initialization failure triggers error callback."""
|
||||
test_dir = "/test/anime"
|
||||
error_callback = Mock()
|
||||
|
||||
# Make Loaders raise an exception
|
||||
mock_loaders.side_effect = RuntimeError("Init failed")
|
||||
|
||||
# Create app should raise but call error callback
|
||||
# Create app should raise
|
||||
with pytest.raises(RuntimeError):
|
||||
SeriesApp(test_dir, error_callback=error_callback)
|
||||
|
||||
# Verify error callback was called
|
||||
error_callback.assert_called_once()
|
||||
assert isinstance(
|
||||
error_callback.call_args[0][0],
|
||||
RuntimeError
|
||||
)
|
||||
SeriesApp(test_dir)
|
||||
|
||||
|
||||
class TestSeriesAppSearch:
|
||||
"""Test search functionality."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch('src.core.SeriesApp.Loaders')
|
||||
@patch('src.core.SeriesApp.SerieScanner')
|
||||
@patch('src.core.SeriesApp.SerieList')
|
||||
def test_search_success(
|
||||
async def test_search_success(
|
||||
self, mock_serie_list, mock_scanner, mock_loaders
|
||||
):
|
||||
"""Test successful search."""
|
||||
@@ -104,34 +71,32 @@ class TestSeriesAppSearch:
|
||||
]
|
||||
app.loader.search = Mock(return_value=expected_results)
|
||||
|
||||
# Perform search
|
||||
results = app.search("test anime")
|
||||
# Perform search (now async)
|
||||
results = await app.search("test anime")
|
||||
|
||||
# Verify results
|
||||
assert results == expected_results
|
||||
app.loader.search.assert_called_once_with("test anime")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch('src.core.SeriesApp.Loaders')
|
||||
@patch('src.core.SeriesApp.SerieScanner')
|
||||
@patch('src.core.SeriesApp.SerieList')
|
||||
def test_search_failure_calls_error_callback(
|
||||
async def test_search_failure_raises_error(
|
||||
self, mock_serie_list, mock_scanner, mock_loaders
|
||||
):
|
||||
"""Test search failure triggers error callback."""
|
||||
"""Test search failure raises error."""
|
||||
test_dir = "/test/anime"
|
||||
error_callback = Mock()
|
||||
app = SeriesApp(test_dir, error_callback=error_callback)
|
||||
app = SeriesApp(test_dir)
|
||||
|
||||
# Make search raise an exception
|
||||
app.loader.search = Mock(
|
||||
side_effect=RuntimeError("Search failed")
|
||||
)
|
||||
|
||||
# Search should raise and call error callback
|
||||
# Search should raise
|
||||
with pytest.raises(RuntimeError):
|
||||
app.search("test")
|
||||
|
||||
error_callback.assert_called_once()
|
||||
await app.search("test")
|
||||
|
||||
|
||||
class TestSeriesAppDownload:
|
||||
|
||||
Reference in New Issue
Block a user