From d63123b77bc3ec7a4a0cd014bc67021ced0637ab Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sun, 28 Apr 2024 13:53:41 -0700 Subject: [PATCH] Add tests for prepare_metadata --- comictaggerlib/md.py | 22 +++++++++++++++------- testing/comicdata.py | 27 +++++++++++++++++++++++++++ tests/metadata_test.py | 8 ++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/comictaggerlib/md.py b/comictaggerlib/md.py index d4a7990..f3ea21f 100644 --- a/comictaggerlib/md.py +++ b/comictaggerlib/md.py @@ -19,15 +19,23 @@ def prepare_metadata(md: GenericMetadata, new_md: GenericMetadata, opts: Settngs final_md = GenericMetadata() final_md.overlay(new_md) - assert final_md.tag_origin - notes = ( - f"Tagged with ComicTagger {ctversion.version} using info from {final_md.tag_origin.name} on" - f" {datetime.now():%Y-%m-%d %H:%M:%S}. [Issue ID {final_md.issue_id}]" - ) + if final_md.tag_origin is not None: + notes = ( + f"Tagged with ComicTagger {ctversion.version} using info from {final_md.tag_origin.name} on" + + f" {datetime.now():%Y-%m-%d %H:%M:%S}. [Issue ID {final_md.issue_id}]" + ) + else: + notes = ( + f"Tagged with ComicTagger {ctversion.version} on" + + f" {datetime.now():%Y-%m-%d %H:%M:%S}. " + + (f"[Issue ID {final_md.issue_id}]" if final_md.issue_id else "") + ) if opts.Issue_Identifier__auto_imprint: final_md.fix_publisher() + return final_md.replace( - notes=utils.combine_notes(new_md.notes, notes, "Tagged with ComicTagger"), - description=cleanup_html(new_md.description, opts.Sources__remove_html_tables), + is_empty=False, + notes=utils.combine_notes(final_md.notes, notes, "Tagged with ComicTagger"), + description=cleanup_html(final_md.description, opts.Sources__remove_html_tables) or None, ) diff --git a/testing/comicdata.py b/testing/comicdata.py index 338969a..1f648a0 100644 --- a/testing/comicdata.py +++ b/testing/comicdata.py @@ -135,3 +135,30 @@ all_seed_imprints = { all_seed_imprints["Marvel"].update(additional_seed_imprints["Marvel"]) conflicting_seed_imprints = {"Marvel": {"test": "Never"}} + + +metadata_prepared = ( + ( + (comicapi.genericmetadata.GenericMetadata(), comicapi.genericmetadata.GenericMetadata()), + comicapi.genericmetadata.GenericMetadata(notes="Tagged with ComicTagger 1.3.2a5 on 2022-04-16 15:52:26."), + ), + ( + (comicapi.genericmetadata.GenericMetadata(issue_id="123"), comicapi.genericmetadata.GenericMetadata()), + comicapi.genericmetadata.GenericMetadata( + issue_id="123", notes="Tagged with ComicTagger 1.3.2a5 on 2022-04-16 15:52:26. [Issue ID 123]" + ), + ), + ( + ( + comicapi.genericmetadata.GenericMetadata( + issue_id="123", tag_origin=comicapi.genericmetadata.TagOrigin("SOURCE", "Source") + ), + comicapi.genericmetadata.GenericMetadata(), + ), + comicapi.genericmetadata.GenericMetadata( + issue_id="123", + tag_origin=comicapi.genericmetadata.TagOrigin("SOURCE", "Source"), + notes="Tagged with ComicTagger 1.3.2a5 using info from Source on 2022-04-16 15:52:26. [Issue ID 123]", + ), + ), +) diff --git a/tests/metadata_test.py b/tests/metadata_test.py index c59f205..82e2eeb 100644 --- a/tests/metadata_test.py +++ b/tests/metadata_test.py @@ -4,6 +4,8 @@ import pytest from importlib_metadata import entry_points import comicapi.genericmetadata +import testing.comicdata +from comictaggerlib.md import prepare_metadata metadata_styles = [] @@ -38,3 +40,9 @@ def test_metadata(mock_version, tmp_comic, md_saved, metadata): written_metadata = written_metadata.get_clean_metadata(*supported_attributes) assert written_metadata == md + + +@pytest.mark.parametrize("metadata, expected", testing.comicdata.metadata_prepared) +def test_prepare_metadata(mock_version, mock_now, config, metadata, expected): + new_md = prepare_metadata(metadata[0], metadata[1], config[0]) + assert new_md == expected