-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Refactor lyrics tests, do not search for empty metadata #5452
base: master
Are you sure you want to change the base?
Conversation
626bf91
to
273e39b
Compare
beetsplug/lyrics.py | ||
test/plugins/test_lyrics.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely comfortable with this mode of testing-as-needed. These files necessarily reference many other parts of the codebase and it's always possible that they can break tests (even if they're pretty independent of the rest of the codebase right now, that can and probably will change in the future).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently these integration tests only run once a week, and no one finds out about failures 😟
200cd19
to
9e67a56
Compare
b4d78da
to
038ca48
Compare
2fb6682
to
d02e017
Compare
54f06f9
to
19dff1c
Compare
@bal-e added a pair of additional commits as I noticed that LRCLib integrated tests have been testing no-op logic and failed once I configured it correctly. I also added lyrics texts that we're expecting to receive from each of the sources we're testing. These will be helpful to have when changes are made in the backends' scraping logic. |
19dff1c
to
e70f61b
Compare
e70f61b
to
278279e
Compare
Two google sources failed to return the expected output. I looked into each case why parsing failed: - lyrics on musica.com contain <aside> Google Ads - each lyrics line on lacoccinelle.net is wrapped within alternating <em> and <strong> tags Thus remove these tags as part of the HTML cleanup logic.
Create 'helpers.ConfigMixin' which sets up testing configuration. This is helpful for tests (e.g. test_lyrics.py) that only need the configuration and do not require temp dir. (#5102) Refactor lyrics tests to fix the issue global beets config issue. Additionally, add 'integration_test' mark that can be used to mark tests that should only run once a week.
- Replaced unittest.mock with pytest fixtures for better test isolation and readability. - Simplified test cases by using parameterized tests. - Added `requests-mock` dependency to `pyproject.toml` and `poetry.lock`. - Removed redundant helper functions and classes.
The test for GeniusLyrics was heavily patched and no longer provided useful coverage. It has been removed to clean up the test suite.
- Consolidated multiple test cases into parameterized tests for better readability and maintainability. - Simplified assertions by comparing lists of actual and expected artists/titles. - Added `unexpected_empty_artist` marker to handle cases which unexpectedly return an empty artist. This seems to be happen when `artist_sort` field is empty.
Modified `search_pairs` function in `lyrics.py` to: * Firstly strip each of `artist`, `artist_sort` and `title` fields * Only generate alternatives if both `artist` and `title` are not empty * Ensure that `artist_sort` is not empty and not equal to artist (ignoring case) before appending it to the artists Extended tests to cover the changes.
Since at least one Backend requires album` and `duration` arguments (`LRCLib`), the caller (`LyricsPlugin.fetch_item_lyrics`) must always provide them. Since they need to provided, we need to enforce this by defining them as positional arguments. Why is this important? I found that integrated `LRCLib` tests have been passing, but they called `LRCLib.fetch` with values for `artist` and `title` fields only, while the actual functionality *always* provides values for `album` and `duration` fields too. When I adjusted the test to provide values for the missing fields, I found that it failed. This makes sense: Lib `album` and `duration` filters are strict on LRCLib, so I was not surprised the lyrics could not be found. Thus I adjusted `LRCLib` backend implementation to only filter by each of these fields when their values are truthy.
Add explicit checks for lyrics texts fetched from the tested sources. - Introduced `LyricsPage` class to represent lyrics pages for integrated tests. - Configured expected lyrics for each of the URLs that are being fetched. - Consolidated integrated tests in a new `TestLyricsSources` class. - Mocked Google Search API to return the lyrics page under test.
278279e
to
4970dda
Compare
Description
Fixes #2635
Fixes #5133
I realised that #5406 has gotten too big, thus I'm splitting it into several smaller PRs.
This PR refactors lyrics plugin tests and fixes an empty metadata issue in the lyrics logic.
CI
--extras=lyrics
to the Poetry install command to include the lyrics plugin dependencies.LYRICS_UPDATED
environment variable based on changes detected in the lyrics files.Test setup
ConfigMixin
to centralize configuration setup for tests, reducing redundancy. This can be used by tests based onpytest
.Lyrics logic
item.title
,item.artist
, anditem.artist_sort
insearch_pairs
function._scrape_strip_cruft
function to remove Google Ads tags and unnecessary HTML tags.Lyrics tests overhaul
pytest
for better isolation and configuration management.LYRICS_UPDATED
is set from the CI) using theon_lyrics_update
marker.Documentation and Dependencies
requests-mock
version1.12.1
topyproject.toml
andpoetry.lock
for mocking HTTP requests in tests.setup.cfg
to include a new markeron_lyrics_update
.