Implemented issue 2572, Query to find albums with/without embedded cover art#6451
Implemented issue 2572, Query to find albums with/without embedded cover art#6451Wouter2devries wants to merge 5 commits intobeetbox:masterfrom
Conversation
No test cases yet. Query to find albums with/without embedded cover art beetbox#2572
snejus
left a comment
There was a problem hiding this comment.
I love this, thank you! A couple of comments
beets/library/models.py
Outdated
| getters = plugins.item_field_getters() | ||
| getters["singleton"] = lambda i: i.album_id is None | ||
| getters["filesize"] = Item.try_filesize # In bytes. | ||
| getters["has_images"] = Item.has_cover_art |
There was a problem hiding this comment.
Let's use has_cover_art as we refer to images as cover_art everywhere
| getters["has_images"] = Item.has_cover_art | |
| getters["has_cover_art"] = Item.has_cover_art |
beets/library/models.py
Outdated
| If file unreadable or no images, return False. | ||
| """ | ||
| try: | ||
| mediafile = MediaFile(syspath(self.path)) |
There was a problem hiding this comment.
No need for syspath here, the value should already be standardized upon access. And I think you can simplify this to
| mediafile = MediaFile(syspath(self.path)) | |
| with suppress(OSError): | |
| return bool(MediaFile(self.path).images) | |
| return False |
docs/reference/query.rst
Outdated
|
|
||
| To find all tracks with embedded cover art: | ||
|
|
||
| :: |
There was a problem hiding this comment.
Best to use
| :: | |
| .. code-block: shell |
test/test_query.py
Outdated
| def test_has_images_getter_exists(self): | ||
| """Verify has_images in getters dict.""" | ||
| getters = Item._getters() | ||
| assert "has_images" in getters | ||
| assert getters["has_images"] == Item.has_cover_art | ||
|
|
||
| def test_has_images_returns_boolean(self): | ||
| """Method always return boolean.""" | ||
| item = _common.item() | ||
| result = item.has_cover_art() | ||
| assert isinstance(result, bool) No newline at end of file |
There was a problem hiding this comment.
These are implementation tests. Instead, test the behaviour:
- Create an item without an image
- Create an item with an image
- Assert that the query
lib.query("has_cover_art:false")returns the first item and vice versa.
Per suggestion as this is what used everywhere else
Removed the return boolean test as it already tests for both true and false.
|
Thank you for all the suggestions. Yeah found the tests a bit lacking myself aswell, did not look at the helper.py enough the first time. Hopefully these are better! |
| def test_has_cover_art_getter_exists(self): | ||
| """Verify has_cover_art in getters dict.""" | ||
| getters = Item._getters() | ||
| assert "has_cover_art" in getters | ||
| assert getters["has_cover_art"] == Item.has_cover_art | ||
|
|
There was a problem hiding this comment.
No need for this - the next test covers this explicitly :)
| def test_query_true(self, lib): | ||
| assert {i.title for i in lib.items("has_cover_art:true")} == {"with_art"} | ||
|
|
||
| def test_query_false(self, lib): | ||
| assert {i.title for i in lib.items("has_cover_art:false")} == {"without_art"} No newline at end of file |
There was a problem hiding this comment.
You can make use of pytest.mark.parametrize here, something like
@pytest.mark.parametrize("query, expected_titles", [("has_cover_art:true", ("with_art")), ...])
def test_has_cover_art_query(self, query, expected_titles):
...|
And note that the changelog has a merge conflict. |
Fixes #2572
Added has_images function to query items by embedded cover art presence.
User can now do beets list has_images:true or beets list has_images:false to find albums with our without cover art.
First time contributing, tried to follow the guidelines as closely as possible. If anything is not up to standard I will edit it as soon as possible.
To Do
The following 3 are included in the pull request: