Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions tests/console/test_entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +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


def test_download_song(capsys, monkeypatch, tmpdir):
def test_download_song(capsys, monkeypatch, tmp_path):
"""
This test checks if the song is downloaded correctly
"""
Expand All @@ -73,7 +73,7 @@ def test_download_song(capsys, monkeypatch, tmpdir):

monkeypatch.setattr(sys, "argv", cli_args)
monkeypatch.setattr(SpotifyClient, "init", new_initialize)
monkeypatch.chdir(tmpdir)
monkeypatch.chdir(tmp_path)

console_entry_point()

Expand All @@ -82,7 +82,7 @@ def test_download_song(capsys, monkeypatch, tmpdir):
assert "Downloaded" in out


def test_preload_song(capsys, monkeypatch, tmpdir):
def test_preload_song(capsys, monkeypatch, tmp_path):
"""
This test checks if the song is preloaded correctly.
"""
Expand All @@ -106,7 +106,7 @@ def test_preload_song(capsys, monkeypatch, tmpdir):

monkeypatch.setattr(sys, "argv", cli_args)
monkeypatch.setattr(SpotifyClient, "init", new_initialize)
monkeypatch.chdir(tmpdir)
monkeypatch.chdir(tmp_path)

console_entry_point()

Expand Down
4 changes: 2 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def test_get_urls(monkeypatch):
assert len(urls) == 1


def test_download(setup, monkeypatch, tmpdir):
def test_download(setup, monkeypatch, tmp_path):
"""
Tests if spotdl can be initialized correctly.
"""

monkeypatch.chdir(tmpdir)
monkeypatch.chdir(tmp_path)

monkeypatch.setattr(SpotifyClient, "init", new_initialize)

Expand Down
6 changes: 3 additions & 3 deletions tests/utils/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from spotdl.utils.archive import Archive


def test_load_archive(tmpdir, monkeypatch):
monkeypatch.chdir(tmpdir)
def test_load_archive(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
archive1 = Archive(["a", "b", "c"])
assert archive1.save("archive.txt") is True
assert tmpdir.join("archive.txt").isfile() is True
assert tmp_path.join("archive.txt").isfile() is True
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmp_path is a pathlib.Path object and does not have a join() method. Use the / operator instead: assert (tmp_path / "archive.txt").is_file() is True. Also note that pathlib.Path uses is_file() instead of isfile().

Suggested change
assert tmp_path.join("archive.txt").isfile() is True
assert (tmp_path / "archive.txt").is_file() is True

Copilot uses AI. Check for mistakes.
archive2 = Archive()
assert archive2.load("archive.txt") is True
assert len(archive2) == len(archive1)
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@


@pytest.fixture()
def setup(tmpdir, monkeypatch):
monkeypatch.setattr(os.path, "expanduser", lambda *_: tmpdir)
def setup(tmp_path, monkeypatch):
monkeypatch.setattr(os.path, "expanduser", lambda *_: tmp_path)
data = SimpleNamespace()
data.directory = tmpdir
data.directory = tmp_path
yield data


Expand Down
16 changes: 8 additions & 8 deletions tests/utils/test_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,23 @@ def test_get_local_ffmpeg(monkeypatch):
assert str(local_ffmpeg).endswith("ffmpeg.exe")


def test_download_ffmpeg(monkeypatch, tmpdir):
def test_download_ffmpeg(monkeypatch, tmp_path):
"""
Test download_ffmpeg function.
"""

monkeypatch.setattr(spotdl.utils.ffmpeg, "get_spotdl_path", lambda *_: tmpdir)
monkeypatch.setattr(spotdl.utils.ffmpeg, "get_spotdl_path", lambda *_: tmp_path)

assert download_ffmpeg() is not None


def test_convert(tmpdir, monkeypatch):
def test_convert(tmp_path, monkeypatch):
"""
Test convert function.
"""

monkeypatch.chdir(tmpdir)
monkeypatch.setattr(spotdl.utils.ffmpeg, "get_spotdl_path", lambda *_: tmpdir)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(spotdl.utils.ffmpeg, "get_spotdl_path", lambda *_: tmp_path)

yt = YoutubeDL(
{
Expand All @@ -134,12 +134,12 @@ def test_convert(tmpdir, monkeypatch):

assert convert(
input_file=(download_info["url"], download_info["ext"]),
output_file=Path(tmpdir, "test.mp3"),
output_file=Path(tmp_path, "test.mp3"),
) == (True, None)

assert convert(
input_file=Path(tmpdir, "test.mp3"),
output_file=Path(tmpdir, "test.m4a"),
input_file=Path(tmp_path, "test.mp3"),
output_file=Path(tmp_path, "test.m4a"),
output_format="m4a",
bitrate="320K",
) == (True, None)
6 changes: 3 additions & 3 deletions tests/utils/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def test_create_github_url():


@pytest.mark.vcr()
def test_download_github_dir(tmpdir, monkeypatch):
monkeypatch.chdir(tmpdir)
def test_download_github_dir(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
download_github_dir(WEB_APP_URL, False)
download_dir = tmpdir.listdir()[0]
download_dir = tmp_path.listdir()[0]
assert download_dir.isdir() is True
assert download_dir.join("index.html").isfile() is True
Comment on lines +52 to 54
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmp_path is a pathlib.Path object and does not have listdir(), isdir(), or join() methods. Use list(tmp_path.iterdir()) to list contents, is_dir() to check if it's a directory, and the / operator for path joining: download_dir = list(tmp_path.iterdir())[0], assert download_dir.is_dir() is True, and assert (download_dir / "index.html").is_file() is True.

Suggested change
download_dir = tmp_path.listdir()[0]
assert download_dir.isdir() is True
assert download_dir.join("index.html").isfile() is True
download_dir = list(tmp_path.iterdir())[0]
assert download_dir.is_dir() is True
assert (download_dir / "index.html").is_file() is True

Copilot uses AI. Check for mistakes.
6 changes: 3 additions & 3 deletions tests/utils/test_m3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def test_create_m3u_content():
assert content.split("\n")[1].startswith("#EXTINF:")
assert content.split("\n")[2].endswith(".mp3")

def test_create_m3u_file(tmpdir, monkeypatch):
monkeypatch.chdir(tmpdir)
def test_create_m3u_file(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
playlist = Playlist.from_url(PLAYLIST)
create_m3u_file("test.m3u", playlist.songs, "", "mp3")
assert tmpdir.join("test.m3u").isfile() is True
assert tmp_path.join("test.m3u").isfile() is True
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmp_path is a pathlib.Path object and does not have a join() method. Use the / operator instead: assert (tmp_path / "test.m3u").is_file() is True. Also note that pathlib.Path uses is_file() instead of isfile().

Suggested change
assert tmp_path.join("test.m3u").isfile() is True
assert (tmp_path / "test.m3u").is_file() is True

Copilot uses AI. Check for mistakes.
8 changes: 4 additions & 4 deletions tests/utils/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"m4a",
],
)
def test_embed_metadata(tmpdir, monkeypatch, output_format):
def test_embed_metadata(tmp_path, monkeypatch, output_format):
"""
Test convert function.
"""

monkeypatch.chdir(tmpdir)
monkeypatch.setattr(spotdl.utils.ffmpeg, "get_spotdl_path", lambda *_: tmpdir)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(spotdl.utils.ffmpeg, "get_spotdl_path", lambda *_: tmp_path)

youtube = YoutubeDL(
{
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_embed_metadata(tmpdir, monkeypatch, output_format):
}

song = Song.from_dict(song_obj)
output_file = Path(tmpdir / f"test.{output_format}")
output_file = Path(tmp_path / f"test.{output_format}")

assert download_info is not None
assert convert(
Expand Down
Loading