Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CoverArtImage repr #2314

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions picard/coverart/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,29 +214,32 @@ def imageinfo_as_string(self):
self.datalength,
self.tempfile_filename)

def __repr__(self):
p = []
def _repr(self):
if self.url is not None:
p.append("url=%r" % self.url.toString())
yield "url=%r" % self.url.toString()
if self.types:
p.append("types=%r" % self.types)
p.append('support_types=%r' % self.support_types)
p.append('support_multi_types=%r' % self.support_types)
yield "types=%r" % self.types
yield 'support_types=%r' % self.support_types
yield 'support_multi_types=%r' % self.support_multi_types
if self.is_front is not None:
p.append("is_front=%r" % self.is_front)
yield "is_front=%r" % self.is_front
if self.comment:
p.append("comment=%r" % self.comment)
return "%s(%s)" % (self.__class__.__name__, ", ".join(p))
yield "comment=%r" % self.comment

def __str__(self):
p = ['Image']
def __repr__(self):
return "%s(%s)" % (self.__class__.__name__, ", ".join(self._repr()))

def _str(self):
yield 'Image'
if self.url is not None:
p.append("from %s" % self.url.toString())
yield "from %s" % self.url.toString()
if self.types:
p.append("of type %s" % ','.join(self.types))
yield "of type %s" % ','.join(self.types)
if self.comment:
p.append("and comment '%s'" % self.comment)
return ' '.join(p)
yield "and comment '%s'" % self.comment

def __str__(self):
return ' '.join(self._str())

def __eq__(self, other):
if self and other:
Expand Down
17 changes: 17 additions & 0 deletions test/test_coverart_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ def create_image(extra_data, types=None, support_types=False,


class CoverArtImageTest(PicardTestCase):
def test_repr_str_1(self):
image = CoverArtImage(
url='url', types=["booklet", "front"],
comment='comment', support_types=True,
support_multi_types=True
)
expected = "CoverArtImage(url='url', types=['booklet', 'front'], support_types=True, support_multi_types=True, comment='comment')"
self.assertEqual(expected, repr(image))
expected = "Image from url of type booklet,front and comment 'comment'"
self.assertEqual(expected, str(image))

def test_repr_str_2(self):
image = CoverArtImage()
expected = "CoverArtImage(support_types=False, support_multi_types=False)"
self.assertEqual(expected, repr(image))
expected = "Image"
self.assertEqual(expected, str(image))

def test_is_front_image_no_types(self):
image = create_image(b'a')
Expand Down