Fix clearing lists via the '-m' option Fixes #587
This commit is contained in:
parent
f75ee58ac0
commit
539aac1307
@ -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"])
|
||||
|
||||
|
26
tests/ctsettings_test.py
Normal file
26
tests/ctsettings_test.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user