diff --git a/comicapi/genericmetadata.py b/comicapi/genericmetadata.py index 765ac28..faa3d00 100644 --- a/comicapi/genericmetadata.py +++ b/comicapi/genericmetadata.py @@ -211,7 +211,10 @@ class GenericMetadata: def assign(cur: str, new: Any) -> None: if new is not None: if isinstance(new, str) and len(new) == 0: - setattr(self, cur, None) + if isinstance(getattr(self, cur), (list, set)): + getattr(self, cur).clear() + else: + setattr(self, cur, None) elif isinstance(new, (list, set)) and len(new) == 0: pass else: @@ -275,6 +278,8 @@ class GenericMetadata: assign("_alternate_images", new_md._alternate_images) def overlay_credits(self, new_credits: list[Credit]) -> None: + if isinstance(new_credits, str) and len(new_credits) == 0: + self.credits = [] for c in new_credits: primary = bool("primary" in c and c["primary"]) diff --git a/tests/ctsettings_test.py b/tests/ctsettings_test.py new file mode 100644 index 0000000..59d69b0 --- /dev/null +++ b/tests/ctsettings_test.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +import pytest + +import comicapi.genericmetadata +import comictaggerlib.ctsettings.types + +md_strings = ( + ("", comicapi.genericmetadata.md_test.replace()), + ("year=", comicapi.genericmetadata.md_test.replace(year=None)), + ("year=2009", comicapi.genericmetadata.md_test.replace(year="2009")), + ("series=", comicapi.genericmetadata.md_test.replace(series=None)), + ("series_aliases=", comicapi.genericmetadata.md_test.replace(series_aliases=set())), + ("black_and_white=", comicapi.genericmetadata.md_test.replace(black_and_white=None)), + ("credits=", comicapi.genericmetadata.md_test.replace(credits=[])), + ("story_arcs=", comicapi.genericmetadata.md_test.replace(story_arcs=[])), +) + + +@pytest.mark.parametrize("string,expected", md_strings) +def test_parse_metadata_from_string(string, expected, md): + parsed_md = comictaggerlib.ctsettings.types.parse_metadata_from_string(string) + + md.overlay(parsed_md) + + assert md == expected