Skip to content
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

WIP: Improvements for networkless testing (#2128 revamped) #2174

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use vcrpy in more tests
Cache network responses to focus on testing our consumption of the API.
This makes the tests more robust to API rate-limiting and denoises them
from network problems.

- tests/console/test_entry_point.py::test_download_song
- tests/console/test_entry_point.py::test_preload_song
- tests/test_init.py::test_download
- tests/test_init.py::test_get_urls
- tests/test_matching.py::test_ytmusic_matching
- tests/utils/test_ffmpeg.py::test_convert
- tests/utils/test_m3u.py::test_create_m3u_content
- tests/utils/test_m3u.py::test_create_m3u_file
- tests/utils/test_metadata.py::test_embed_metadata
- tests/utils/test_search.py::test_parse_query
hseg authored and gesh gesh@gesh.uni.cx committed Dec 10, 2024
commit a7ede878ea1371c8503154aa37f3d03aabe3e405
2 changes: 2 additions & 0 deletions tests/console/test_entry_point.py
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ def test_show_version(capsys, monkeypatch, argument):
assert re.match(r"\d{1,2}\.\d{1,2}\.\d{1,3}", out) is not None


@pytest.mark.vcr()
def test_download_song(capsys, monkeypatch, tmpdir):
"""
This test checks if the song is downloaded correctly
@@ -82,6 +83,7 @@ def test_download_song(capsys, monkeypatch, tmpdir):
assert "Downloaded" in out


@pytest.mark.vcr()
def test_preload_song(capsys, monkeypatch, tmpdir):
"""
This test checks if the song is preloaded correctly.
2 changes: 2 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ def setup(tmp_path, monkeypatch):
yield data


@pytest.mark.vcr()
def test_get_urls(monkeypatch):
"""
Tests if spotdl can be initialized correctly.
@@ -48,6 +49,7 @@ def test_get_urls(monkeypatch):
assert len(urls) == 1


@pytest.mark.vcr()
def test_download(setup, monkeypatch, tmpdir):
"""
Tests if spotdl can be initialized correctly.
1 change: 1 addition & 0 deletions tests/test_matching.py
Original file line number Diff line number Diff line change
@@ -401,6 +401,7 @@
),
],
)
@pytest.mark.vcr()
def test_ytmusic_matching(monkeypatch, query, expected, capsys):
monkeypatch.setattr(SpotifyClient, "init", new_initialize)

1 change: 1 addition & 0 deletions tests/utils/test_ffmpeg.py
Original file line number Diff line number Diff line change
@@ -111,6 +111,7 @@ def test_download_ffmpeg(monkeypatch, tmpdir):
assert download_ffmpeg() is not None


@pytest.mark.vcr()
def test_convert(tmpdir, monkeypatch):
"""
Test convert function.
2 changes: 2 additions & 0 deletions tests/utils/test_m3u.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
PLAYLIST = "https://open.spotify.com/playlist/5LkNhFidYyyjRWwnkcMbQs"


@pytest.mark.vcr()
def test_create_m3u_content():
playlist = Playlist.from_url(PLAYLIST)
content = create_m3u_content(
@@ -17,6 +18,7 @@ def test_create_m3u_content():
assert content.split("\n")[0].endswith("mp3.mp3")


@pytest.mark.vcr()
def test_create_m3u_file(tmpdir, monkeypatch):
monkeypatch.chdir(tmpdir)
playlist = Playlist.from_url(PLAYLIST)
1 change: 1 addition & 0 deletions tests/utils/test_metadata.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
"m4a",
],
)
@pytest.mark.vcr()
def test_embed_metadata(tmpdir, monkeypatch, output_format):
"""
Test convert function.
1 change: 1 addition & 0 deletions tests/utils/test_search.py
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ def test_parse_saved():
parse_query(SAVED)


@pytest.mark.vcr()
def test_parse_query():
songs = parse_query(QUERY)