From c3a8221d996c57ac7cfa15e6491c19edc93f2aed Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Mon, 18 Dec 2023 16:56:54 -0800 Subject: [PATCH] Return an empty object if an archive does not have the requested style --- comicapi/comicarchive.py | 6 ++++-- tests/integration_test.py | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/comicapi/comicarchive.py b/comicapi/comicarchive.py index ad7c1cf..1f7e517 100644 --- a/comicapi/comicarchive.py +++ b/comicapi/comicarchive.py @@ -167,8 +167,10 @@ class ComicArchive: def read_metadata(self, style: str) -> GenericMetadata: if style in self.md: return self.md[style] - md = metadata_styles[style].get_metadata(self.archiver) - md.apply_default_page_list(self.get_page_name_list()) + md = GenericMetadata() + if metadata_styles[style].has_metadata(self.archiver): + md = metadata_styles[style].get_metadata(self.archiver) + md.apply_default_page_list(self.get_page_name_list()) return md def read_metadata_string(self, style: str) -> str: diff --git a/tests/integration_test.py b/tests/integration_test.py index ae6d0f0..62658c4 100644 --- a/tests/integration_test.py +++ b/tests/integration_test.py @@ -85,9 +85,8 @@ def test_delete( # Read the CBZ md = tmp_comic.read_metadata("cr") - # Currently we set the default page list on load + # The default page list is set on load if the comic has the requested metadata style empty_md = comicapi.genericmetadata.GenericMetadata() - empty_md.apply_default_page_list(tmp_comic.get_page_name_list()) # Validate that we got an empty metadata back assert md == empty_md