diff --git a/picard/coverart/image.py b/picard/coverart/image.py index b45b9c81d6..ae31000188 100644 --- a/picard/coverart/image.py +++ b/picard/coverart/image.py @@ -228,7 +228,6 @@ def __repr__(self): return "%s(%s)" % (self.__class__.__name__, ", ".join(self._repr())) def _str(self): - yield 'Image' if self.url is not None: yield "from %s" % self.url.toString() if self.types: @@ -237,7 +236,11 @@ def _str(self): yield "and comment '%s'" % self.comment def __str__(self): - return ' '.join(self._str()) + output = self.__class__.__name__ + s = tuple(self._str()) + if s: + output += ' ' + ' '.join(s) + return output def __eq__(self, other): if self and other: @@ -469,19 +472,15 @@ 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) - if self.types: - p.append("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) - if self.comment: - p.append("comment=%r" % self.comment) - return "%s(%s)" % (self.__class__.__name__, ", ".join(p)) + yield 'tag=%r' % self.tag + yield from super()._repr() + + def _str(self): + yield 'from %r' % self.sourcefile + yield from super()._str() class LocalFileCoverArtImage(CoverArtImage): diff --git a/test/test_coverart_image.py b/test/test_coverart_image.py index 50573d87ee..5ea0fd2108 100644 --- a/test/test_coverart_image.py +++ b/test/test_coverart_image.py @@ -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 @@ -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'], support_types=True, support_multi_types=False, is_front=True, comment='description')" + self.assertEqual(expected, repr(image)) + expected = "TagCoverArtImage from 'testfilename' of type front and comment 'description'" + self.assertEqual(expected, str(image)) + + class CoverArtImageTest(PicardTestCase): def test_repr_str_1(self): image = CoverArtImage( @@ -63,14 +86,14 @@ def test_repr_str_1(self): ) 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'" + expected = "CoverArtImage 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" + expected = "CoverArtImage" self.assertEqual(expected, str(image)) def test_is_front_image_no_types(self):