From b590c60c3b82c070287d5fa18a69acbd4e758916 Mon Sep 17 00:00:00 2001 From: Joakim Soderlund Date: Sat, 11 Nov 2017 00:06:05 +0100 Subject: [PATCH] Prioritize existing flavor in meta format mapper --- fimfarchive/mappers.py | 7 ++++++- tests/test_mappers.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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