mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-29 00:07:58 +01:00
Improve performance of Fimfarchive fetcher tests
This commit is contained in:
parent
254ed38608
commit
7a9191cf36
1 changed files with 21 additions and 2 deletions
|
@ -25,13 +25,14 @@ Fimfarchive fetcher tests.
|
||||||
import json
|
import json
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
from unittest.mock import patch, MagicMock
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from fimfarchive.exceptions import InvalidStoryError, StorySourceError
|
from fimfarchive.exceptions import InvalidStoryError, StorySourceError
|
||||||
from fimfarchive.fetchers import Fetcher, FimfarchiveFetcher
|
from fimfarchive.fetchers import fimfarchive, Fetcher, FimfarchiveFetcher
|
||||||
from fimfarchive.stories import Story
|
from fimfarchive.stories import Story
|
||||||
from fimfarchive.utils import JayWalker
|
from fimfarchive.utils import JayWalker
|
||||||
|
|
||||||
|
@ -171,6 +172,16 @@ def serialize(obj: Dict) -> str:
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
class PoolMock(MagicMock):
|
||||||
|
"""
|
||||||
|
Mocks the multiprocessing pool.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def imap(func, iterable, chunksize):
|
||||||
|
yield from map(func, iterable)
|
||||||
|
|
||||||
|
|
||||||
class TestFimfarchiveFetcher:
|
class TestFimfarchiveFetcher:
|
||||||
"""
|
"""
|
||||||
FimfarchiveFetcher tests.
|
FimfarchiveFetcher tests.
|
||||||
|
@ -196,8 +207,16 @@ class TestFimfarchiveFetcher:
|
||||||
|
|
||||||
return stream
|
return stream
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pool(self):
|
||||||
|
"""
|
||||||
|
Yields a multiprocessing pool mock.
|
||||||
|
"""
|
||||||
|
with patch.object(fimfarchive, 'Pool', PoolMock) as mock:
|
||||||
|
yield mock
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def fetcher(self, archive):
|
def fetcher(self, archive, pool):
|
||||||
"""
|
"""
|
||||||
Returns the fetcher instance to test.
|
Returns the fetcher instance to test.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue