diff --git a/fimfarchive/mappers.py b/fimfarchive/mappers.py index 0fa4172..24ac378 100644 --- a/fimfarchive/mappers.py +++ b/fimfarchive/mappers.py @@ -31,6 +31,7 @@ from arrow import api as arrow, Arrow from fimfarchive.exceptions import InvalidStoryError from fimfarchive.flavors import MetaFormat from fimfarchive.stories import Story +from fimfarchive.utils import find_flavor __all__ = ( @@ -128,9 +129,13 @@ class MetaFormatMapper(Mapper[Optional[MetaFormat]]): } def __call__(self, story: Story) -> Optional[MetaFormat]: + flavor = find_flavor(story, MetaFormat) + + if flavor: + return flavor + items = self.spec.items() meta = set(story.meta.keys()) - matches = {fmt for fmt, spec in items if spec & meta} if len(matches) == 1: diff --git a/tests/test_mappers.py b/tests/test_mappers.py index 82b14d5..ac2a550 100644 --- a/tests/test_mappers.py +++ b/tests/test_mappers.py @@ -334,3 +334,12 @@ class TestMetaFormatMapper: """ story = self.merge(story, alpha, beta) 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