mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-24 22:27:59 +01:00
Add flavor stamper
This commit is contained in:
parent
c4ba2e8983
commit
9ca1872343
2 changed files with 56 additions and 4 deletions
|
@ -26,7 +26,7 @@ from typing import Any, Callable, Dict, Optional, Set
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
|
|
||||||
from fimfarchive.flavors import UpdateStatus
|
from fimfarchive.flavors import Flavor, UpdateStatus
|
||||||
from fimfarchive.stories import Story
|
from fimfarchive.stories import Story
|
||||||
from fimfarchive.utils import find_flavor
|
from fimfarchive.utils import find_flavor
|
||||||
|
|
||||||
|
@ -108,6 +108,27 @@ class UpdateStamper(Stamper):
|
||||||
archive[key] = None
|
archive[key] = None
|
||||||
|
|
||||||
|
|
||||||
|
class FlavorStamper(Stamper):
|
||||||
|
"""
|
||||||
|
Adds flavors to stories.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, mapper: Callable[[Story], Optional[Flavor]]) -> None:
|
||||||
|
"""
|
||||||
|
Constructor.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
mapper: Callable returning the flavor to stamp with.
|
||||||
|
"""
|
||||||
|
self.map = mapper
|
||||||
|
|
||||||
|
def __call__(self, story: Story) -> None:
|
||||||
|
flavor = self.map(story)
|
||||||
|
|
||||||
|
if flavor:
|
||||||
|
story.flavors.add(flavor)
|
||||||
|
|
||||||
|
|
||||||
class PathStamper(Stamper):
|
class PathStamper(Stamper):
|
||||||
"""
|
"""
|
||||||
Adds archive paths to stories.
|
Adds archive paths to stories.
|
||||||
|
@ -118,7 +139,7 @@ class PathStamper(Stamper):
|
||||||
Constructor.
|
Constructor.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
mapper: Callable returning the path to stamp.
|
mapper: Callable returning the path to stamp with.
|
||||||
"""
|
"""
|
||||||
self.map = mapper
|
self.map = mapper
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,11 @@ from typing import Dict
|
||||||
import arrow
|
import arrow
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from fimfarchive.flavors import UpdateStatus
|
from fimfarchive.flavors import DataFormat, MetaFormat, UpdateStatus
|
||||||
from fimfarchive.mappers import StaticMapper
|
from fimfarchive.mappers import StaticMapper
|
||||||
from fimfarchive.stampers import Stamper, PathStamper, UpdateStamper
|
from fimfarchive.stampers import (
|
||||||
|
Stamper, FlavorStamper, PathStamper, UpdateStamper,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestStamper:
|
class TestStamper:
|
||||||
|
@ -190,6 +192,35 @@ class TestUpdateStamper:
|
||||||
assert archive['date_updated'] == prev
|
assert archive['date_updated'] == prev
|
||||||
|
|
||||||
|
|
||||||
|
class TestFlavorStamper:
|
||||||
|
"""
|
||||||
|
FlavorStamper tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('value', (None, ''))
|
||||||
|
def test_ignored_blank_value(self, story, value):
|
||||||
|
"""
|
||||||
|
Tests blank values are ignored.
|
||||||
|
"""
|
||||||
|
stamp = FlavorStamper(StaticMapper(value))
|
||||||
|
stamp(story)
|
||||||
|
|
||||||
|
assert value not in story.flavors
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('value', (
|
||||||
|
DataFormat.EPUB,
|
||||||
|
MetaFormat.ALPHA,
|
||||||
|
))
|
||||||
|
def test_stamped_value(self, story, value):
|
||||||
|
"""
|
||||||
|
Tests values are stamped to stories.
|
||||||
|
"""
|
||||||
|
stamp = FlavorStamper(StaticMapper(value))
|
||||||
|
stamp(story)
|
||||||
|
|
||||||
|
assert value in story.flavors
|
||||||
|
|
||||||
|
|
||||||
class TestPathStamper:
|
class TestPathStamper:
|
||||||
"""
|
"""
|
||||||
PathStamper tests.
|
PathStamper tests.
|
||||||
|
|
Loading…
Reference in a new issue