refactor: use pathlib (#654)

* refactor: use pathlib

* fix size mock
This commit is contained in:
sigma67 2024-10-05 12:39:21 +02:00 • committed by GitHub
commit 77e40b7f7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 37 additions and 30 deletions

View file

@ -1,5 +1,4 @@
import json
import os
import tempfile
import time
from pathlib import Path
@ -62,7 +61,7 @@ class TestOAuth:
assert OAuthToken.is_oauth(oauth_token)
oauth_file.close()
os.unlink(oauth_filepath)
Path(oauth_file.name).unlink()
def test_oauth_tokens(self, oauth_filepath: str, yt_oauth: YTMusic):
# ensure instance initialized token

View file

@ -1,3 +1,5 @@
import os
import stat
import tempfile
import time
from unittest import mock
@ -53,8 +55,16 @@ class TestUploads:
response = yt_auth.upload_song(get_resource(config["uploads"]["file"]))
assert response.status_code == 409
def test_upload_song_file_too_large(self, config, yt_auth):
orig_os_stat = os.stat
def fake_stat(arg, **kwargs):
faked = list(orig_os_stat(arg))
faked[stat.ST_SIZE] = 4 * 10**9
return os.stat_result(faked)
with (
mock.patch("os.path.getsize", return_value=4 * 10**9),
mock.patch("os.stat", side_effect=fake_stat),
pytest.raises(YTMusicUserError, match="larger than the limit of 300MB"),
):
yt_auth.upload_song(get_resource(config["uploads"]["file"]))