mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-22 13:28:00 +01:00
Prioritize existing flavor in meta format mapper
This commit is contained in:
parent
4ee0824230
commit
b590c60c3b
2 changed files with 15 additions and 1 deletions
|
@ -31,6 +31,7 @@ from arrow import api as arrow, Arrow
|
||||||
from fimfarchive.exceptions import InvalidStoryError
|
from fimfarchive.exceptions import InvalidStoryError
|
||||||
from fimfarchive.flavors import MetaFormat
|
from fimfarchive.flavors import MetaFormat
|
||||||
from fimfarchive.stories import Story
|
from fimfarchive.stories import Story
|
||||||
|
from fimfarchive.utils import find_flavor
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
@ -128,9 +129,13 @@ class MetaFormatMapper(Mapper[Optional[MetaFormat]]):
|
||||||
}
|
}
|
||||||
|
|
||||||
def __call__(self, story: Story) -> Optional[MetaFormat]:
|
def __call__(self, story: Story) -> Optional[MetaFormat]:
|
||||||
|
flavor = find_flavor(story, MetaFormat)
|
||||||
|
|
||||||
|
if flavor:
|
||||||
|
return flavor
|
||||||
|
|
||||||
items = self.spec.items()
|
items = self.spec.items()
|
||||||
meta = set(story.meta.keys())
|
meta = set(story.meta.keys())
|
||||||
|
|
||||||
matches = {fmt for fmt, spec in items if spec & meta}
|
matches = {fmt for fmt, spec in items if spec & meta}
|
||||||
|
|
||||||
if len(matches) == 1:
|
if len(matches) == 1:
|
||||||
|
|
|
@ -334,3 +334,12 @@ class TestMetaFormatMapper:
|
||||||
"""
|
"""
|
||||||
story = self.merge(story, alpha, beta)
|
story = self.merge(story, alpha, beta)
|
||||||
assert mapper(story) is None
|
assert mapper(story) is None
|
||||||
|
|
||||||
|
def test_existing_flavor(self, mapper, story, beta):
|
||||||
|
"""
|
||||||
|
Tests existing flavor takes precedence over meta.
|
||||||
|
"""
|
||||||
|
story = story.merge(flavors=[MetaFormat.ALPHA])
|
||||||
|
story = self.merge(story, beta, 'misc')
|
||||||
|
|
||||||
|
assert mapper(story) is MetaFormat.ALPHA
|
||||||
|
|
Loading…
Reference in a new issue