From ffdf7d71e1f5875e19bb72044dde1884c07213e8 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Fri, 16 Aug 2024 12:50:14 -0700 Subject: [PATCH] Fix tests --- comicapi/genericmetadata.py | 24 +++++++++++++++++++++++- setup.cfg | 4 ++-- tests/comicarchive_test.py | 2 +- tests/tags_test.py | 19 +++++++++++++------ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/comicapi/genericmetadata.py b/comicapi/genericmetadata.py index ce79f97..c6a4e1e 100644 --- a/comicapi/genericmetadata.py +++ b/comicapi/genericmetadata.py @@ -94,6 +94,19 @@ class PageMetadata: return False return self.archive_index == other.archive_index + def _get_clean_metadata(self, *attributes: str) -> PageMetadata: + return PageMetadata( + filename=self.filename if "filename" in attributes else "", + type=self.type if "type" in attributes else "", + bookmark=self.bookmark if "bookmark" in attributes else "", + display_index=self.display_index if "display_index" in attributes else 0, + archive_index=self.archive_index if "archive_index" in attributes else 0, + double_page=self.double_page if "double_page" in attributes else None, + byte_size=self.byte_size if "byte_size" in attributes else None, + height=self.height if "height" in attributes else None, + width=self.width if "width" in attributes else None, + ) + Credit = merge.Credit @@ -206,14 +219,23 @@ class GenericMetadata: tmp.__dict__.update(kwargs) return tmp - def get_clean_metadata(self, *attributes: str) -> GenericMetadata: + def _get_clean_metadata(self, *attributes: str) -> GenericMetadata: new_md = GenericMetadata() + list_handled = [] for attr in sorted(attributes): if "." in attr: lst, _, name = attr.partition(".") + if lst in list_handled: + continue old_value = getattr(self, lst) new_value = getattr(new_md, lst) if old_value: + if hasattr(old_value[0], "_get_clean_metadata"): + list_attributes = [x.removeprefix(lst + ".") for x in attributes if x.startswith(lst)] + for x in old_value: + new_value.append(x._get_clean_metadata(*list_attributes)) + list_handled.append(lst) + continue if not new_value: for x in old_value: new_value.append(x.__class__()) diff --git a/setup.cfg b/setup.cfg index 88de046..eb48d5a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -88,7 +88,7 @@ QTW = all = PyQt5 PyQtWebEngine - comicinfoxml>=0.2.0 + comicinfoxml==0.4.* gcd-talker>0.1.0 metron-talker>0.1.5 pillow-avif-plugin>=1.4.1 @@ -99,7 +99,7 @@ all = avif = pillow-avif-plugin>=1.4.1 cix = - comicinfoxml>=0.2.0 + comicinfoxml==0.4.* gcd = gcd-talker>=0.1.0 jxl = diff --git a/tests/comicarchive_test.py b/tests/comicarchive_test.py index 299a457..ad60166 100644 --- a/tests/comicarchive_test.py +++ b/tests/comicarchive_test.py @@ -89,7 +89,7 @@ def test_save_cbi_rar(tmp_path, md_saved): md = tmp_comic.read_tags("cbi") supported_attributes = comicapi.comicarchive.tags["cbi"].supported_attributes - assert md.get_clean_metadata(*supported_attributes) == md_saved.get_clean_metadata(*supported_attributes) + assert md._get_clean_metadata(*supported_attributes) == md_saved._get_clean_metadata(*supported_attributes) def test_page_type_write(tmp_comic): diff --git a/tests/tags_test.py b/tests/tags_test.py index 0b11c2a..b8ae55f 100644 --- a/tests/tags_test.py +++ b/tests/tags_test.py @@ -9,12 +9,15 @@ from comictaggerlib.md import prepare_metadata tags = [] -for x in entry_points(group="comicapi.tag"): +for x in entry_points(group="comicapi.tags"): tag = x.load() supported = tag.enabled exe_found = True tags.append(pytest.param(tag, marks=pytest.mark.xfail(not supported, reason="tags not enabled"))) +if not tags: + raise Exception("No tags found") + @pytest.mark.parametrize("tag_type", tags) def test_metadata(mock_version, tmp_comic, md_saved, tag_type): @@ -22,20 +25,24 @@ def test_metadata(mock_version, tmp_comic, md_saved, tag_type): supported_attributes = tag.supported_attributes tag.write_tags(comicapi.genericmetadata.md_test, tmp_comic.archiver) written_metadata = tag.read_tags(tmp_comic.archiver) - md = md_saved.get_clean_metadata(*supported_attributes) + md = md_saved._get_clean_metadata(*supported_attributes) # Hack back in the pages variable because CoMet supports identifying the cover by the filename if tag.id == "comet": md.pages = [ - comicapi.genericmetadata.ImageMetadata( - image_index=0, filename="!cover.jpg", type=comicapi.genericmetadata.PageType.FrontCover + comicapi.genericmetadata.PageMetadata( + archive_index=0, + bookmark="", + display_index=0, + filename="!cover.jpg", + type=comicapi.genericmetadata.PageType.FrontCover, ) ] - written_metadata = written_metadata.get_clean_metadata(*supported_attributes).replace( + written_metadata = written_metadata._get_clean_metadata(*supported_attributes).replace( pages=written_metadata.pages ) else: - written_metadata = written_metadata.get_clean_metadata(*supported_attributes) + written_metadata = written_metadata._get_clean_metadata(*supported_attributes) assert written_metadata == md