Skip to content

Commit

Permalink
Merge pull request #2314 from zas/fix_image_repr
Browse files Browse the repository at this point in the history
Fix CoverArtImage repr
  • Loading branch information
phw authored Sep 14, 2023
2 parents 1ec3379 + 9cbc2b4 commit e2f1940
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
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

0 comments on commit e2f1940

Please sign in to comment.