From de084ffff96532984b97d1aa7d20478ba8ed4db1 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sat, 6 Apr 2024 12:00:17 -0700 Subject: [PATCH] Fix string value of GenericMetadata --- comicapi/genericmetadata.py | 67 +++++++++++++++++------------------ tests/genericmetadata_test.py | 45 +++++++++++++++++++++++ 2 files changed, 77 insertions(+), 35 deletions(-) diff --git a/comicapi/genericmetadata.py b/comicapi/genericmetadata.py index 74b0333..01326fc 100644 --- a/comicapi/genericmetadata.py +++ b/comicapi/genericmetadata.py @@ -376,48 +376,45 @@ class GenericMetadata: elif val is not None: vals.append((tag, val)) - def add_attr_string(tag: str) -> None: - add_string(tag, getattr(self, tag)) - - add_attr_string("series") - add_attr_string("issue") - add_attr_string("issue_count") - add_attr_string("title") - add_attr_string("publisher") - add_attr_string("year") - add_attr_string("month") - add_attr_string("day") - add_attr_string("volume") - add_attr_string("volume_count") + add_string("series", self.series) + add_string("issue", self.issue) + add_string("issue_count", self.issue_count) + add_string("title", self.title) + add_string("publisher", self.publisher) + add_string("year", self.year) + add_string("month", self.month) + add_string("day", self.day) + add_string("volume", self.volume) + add_string("volume_count", self.volume_count) add_string("genres", ", ".join(self.genres)) - add_attr_string("language") - add_attr_string("country") - add_attr_string("critical_rating") - add_attr_string("alternate_series") - add_attr_string("alternate_number") - add_attr_string("alternate_count") - add_attr_string("imprint") - add_attr_string("web_link") - add_attr_string("format") - add_attr_string("manga") + add_string("language", self.language) + add_string("country", self.country) + add_string("critical_rating", self.critical_rating) + add_string("alternate_series", self.alternate_series) + add_string("alternate_number", self.alternate_number) + add_string("alternate_count", self.alternate_count) + add_string("imprint", self.imprint) + add_string("web_links", [str(x) for x in self.web_links]) + add_string("format", self.format) + add_string("manga", self.manga) - add_attr_string("price") - add_attr_string("is_version_of") - add_attr_string("rights") - add_attr_string("identifier") - add_attr_string("last_mark") + add_string("price", self.price) + add_string("is_version_of", self.is_version_of) + add_string("rights", self.rights) + add_string("identifier", self.identifier) + add_string("last_mark", self.last_mark) if self.black_and_white: - add_attr_string("black_and_white") - add_attr_string("maturity_rating") - add_attr_string("story_arcs") - add_attr_string("series_groups") - add_attr_string("scan_info") + add_string("black_and_white", self.black_and_white) + add_string("maturity_rating", self.maturity_rating) + add_string("story_arcs", self.story_arcs) + add_string("series_groups", self.series_groups) + add_string("scan_info", self.scan_info) add_string("characters", ", ".join(self.characters)) add_string("teams", ", ".join(self.teams)) add_string("locations", ", ".join(self.locations)) - add_attr_string("description") - add_attr_string("notes") + add_string("description", self.description) + add_string("notes", self.notes) add_string("tags", ", ".join(self.tags)) diff --git a/tests/genericmetadata_test.py b/tests/genericmetadata_test.py index 984a370..38602ad 100644 --- a/tests/genericmetadata_test.py +++ b/tests/genericmetadata_test.py @@ -1,5 +1,7 @@ from __future__ import annotations +import textwrap + import pytest import comicapi.genericmetadata @@ -40,3 +42,46 @@ def test_add_credit_primary(): @pytest.mark.parametrize("md, role, expected", credits) def test_get_primary_credit(md, role, expected): assert md.get_primary_credit(role) == expected + + +def test_str(md): + expected = textwrap.dedent( + """\ + series: Cory Doctorow's Futuristic Tales of the Here and Now + issue: 1 + issue_count: 6 + title: Anda's Game + publisher: IDW Publishing + year: 2007 + month: 10 + day: 1 + volume: 1 + genres: Sci-Fi + language: en + critical_rating: 3.0 + alternate_series: Tales + alternate_number: 2 + alternate_count: 7 + imprint: craphound.com + web_links: ['https://comicvine.gamespot.com/cory-doctorows-futuristic-tales-of-the-here-and-no/4000-140529/'] + format: Series + manga: No + maturity_rating: Everyone 10+ + story_arcs: ['Here and Now'] + series_groups: ['Futuristic Tales'] + scan_info: (CC BY-NC-SA 3.0) + characters: Anda + teams: Fahrenheit + locations: lonely cottage + description: For 12-year-old Anda, getting paid real money to kill the characters of players who were cheating in her favorite online computer game was a win-win situation. Until she found out who was paying her, and what those characters meant to the livelihood of children around the world. + notes: Tagged with ComicTagger 1.3.2a5 using info from Comic Vine on 2022-04-16 15:52:26. [Issue ID 140529] + credit: Writer: Dara Naraghi + credit: Penciller: Esteve Polls + credit: Inker: Esteve Polls + credit: Letterer: Neil Uyetake + credit: Cover: Sam Kieth + credit: Editor: Ted Adams + """ + ) + + assert str(md) == expected