Fix tests

This commit is contained in:
Timmy Welch 2024-08-16 12:50:14 -07:00
parent db3d5d6a01
commit ffdf7d71e1
4 changed files with 39 additions and 10 deletions

View File

@ -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__())

View File

@ -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 =

View File

@ -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):

View File

@ -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