Skip to content

Commit

Permalink
TagCoverArtImage(): properly set _repr() and _str() for this subclass
Browse files Browse the repository at this point in the history
Also add matching tests
  • Loading branch information
zas committed Sep 20, 2023
1 parent 3018d52 commit 60fd884
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
23 changes: 14 additions & 9 deletions picard/coverart/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,19 +469,24 @@ def source(self):
else:
return 'File %s' % (self.sourcefile)

def __repr__(self):
p = []
p.append('%r' % self.sourcefile)
def _repr(self):
yield '%r' % self.sourcefile
if self.tag is not None:
p.append("tag=%r" % self.tag)
yield 'tag=%r' % self.tag
if self.types:
p.append("types=%r" % self.types)
yield 'types=%r' % self.types
if self.is_front is not None:
p.append("is_front=%r" % self.is_front)
p.append('support_types=%r' % self.support_types)
yield 'is_front=%r' % self.is_front
yield 'support_types=%r' % self.support_types
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):
yield 'Image from %r' % self.sourcefile
if self.types:
yield "of type %s" % ','.join(self.types)
if self.comment:
yield "and comment '%s'" % self.comment


class LocalFileCoverArtImage(CoverArtImage):
Expand Down
25 changes: 24 additions & 1 deletion test/test_coverart_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
from picard.coverart.image import (
CoverArtImage,
LocalFileCoverArtImage,
TagCoverArtImage,
)
from picard.coverart.utils import (
Id3ImageType,
types_from_id3,
)
from picard.coverart.utils import Id3ImageType
from picard.metadata import Metadata
from picard.util import encode_filename
from picard.util.filenaming import WinPathTooLong
Expand All @@ -54,6 +58,25 @@ def create_image(extra_data, types=None, support_types=False,
)


class TagCoverArtImageTest(PicardTestCase):
def test_repr_str_1(self):
image_type = Id3ImageType.COVER_FRONT
image = TagCoverArtImage(
file='testfilename',
tag='tag',
types=types_from_id3(image_type),
comment='description',
support_types=True,
data=None,
id3_type=image_type,
is_front=True,
)
expected = "TagCoverArtImage('testfilename', tag='tag', types=['front'], is_front=True, support_types=True, comment='description')"
self.assertEqual(expected, repr(image))
expected = "Image from 'testfilename' of type front and comment 'description'"
self.assertEqual(expected, str(image))


class CoverArtImageTest(PicardTestCase):
def test_repr_str_1(self):
image = CoverArtImage(
Expand Down

0 comments on commit 60fd884

Please sign in to comment.