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

Python3 #233

Merged
merged 16 commits into from Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions mopidy_spotify/backend.py
Expand Up @@ -105,11 +105,11 @@ def _get_spotify_config(self, config):
)

if config["spotify"]["allow_cache"]:
spotify_config.cache_location = ext.get_cache_dir(config)
spotify_config.cache_location = bytes(ext.get_cache_dir(config))
else:
spotify_config.cache_location = None

spotify_config.settings_location = ext.get_data_dir(config)
spotify_config.settings_location = bytes(ext.get_data_dir(config))

proxy_uri = httpclient.format_proxy(config["proxy"], auth=False)
if proxy_uri is not None:
Expand Down
12 changes: 6 additions & 6 deletions mopidy_spotify/translator.py
Expand Up @@ -14,7 +14,7 @@ def __init__(self, func):

def __call__(self, *args, **kwargs):
# NOTE Only args, not kwargs, are part of the memoization key.
if not isinstance(args, collections.Hashable):
if not isinstance(args, collections.abc.Hashable):
return self.func(*args, **kwargs)
if args in self.cache:
return self.cache[args]
Expand Down Expand Up @@ -103,14 +103,14 @@ def to_track(sp_track, bitrate=None):
return

artists = [to_artist(sp_artist) for sp_artist in sp_track.artists]
artists = filter(None, artists)
artists = [a for a in artists if a]

album = to_album(sp_track.album)

return models.Track(
uri=sp_track.link.uri,
name=sp_track.name,
artists=artists,
artists=list(artists),
kingosticks marked this conversation as resolved.
Show resolved Hide resolved
album=album,
date=album.date,
length=sp_track.duration,
Expand Down Expand Up @@ -167,10 +167,10 @@ def to_playlist(
to_track(sp_track, bitrate=bitrate)
for sp_track in sp_playlist.tracks
]
tracks = filter(None, tracks)
tracks = [t for t in tracks if t]
if name is None:
# Use same starred order as the Spotify client
tracks = list(reversed(tracks))
tracks = reversed(tracks)

if name is None:
name = "Starred"
Expand All @@ -183,7 +183,7 @@ def to_playlist(
return models.Ref.playlist(uri=sp_playlist.link.uri, name=name)
else:
return models.Playlist(
uri=sp_playlist.link.uri, name=name, tracks=tracks
uri=sp_playlist.link.uri, name=name, tracks=list(tracks)
kingosticks marked this conversation as resolved.
Show resolved Hide resolved
)


Expand Down
18 changes: 12 additions & 6 deletions mopidy_spotify/web.py
Expand Up @@ -147,7 +147,7 @@ def _request_with_retries(self, method, url, *args, **kwargs):
try_until = time.time() + self._timeout

result = None
backoff_time = None
backoff_time = 0

for i in range(self._number_of_retries):
remaining_timeout = max(try_until - time.time(), 1)
Expand All @@ -165,7 +165,7 @@ def _request_with_retries(self, method, url, *args, **kwargs):
except requests.RequestException as e:
logger.debug("Fetching %s failed: %s", prepared_request.url, e)
status_code = None
backoff_time = None
backoff_time = 0
result = None
else:
status_code = response.status_code
Expand Down Expand Up @@ -216,15 +216,19 @@ def _prepare_url(self, url, *args, **kwargs):
scheme, netloc = b.scheme, b.netloc
path = os.path.normpath(os.path.join(b.path, u.path))
query = urllib.parse.parse_qsl(b.query, keep_blank_values=True)
query.extend(urllib.parse.parse_qsl(u.query, keep_blank_values=True))
query.extend(
urllib.parse.parse_qsl(u.query, keep_blank_values=True)
)

for key, value in kwargs.items():
if isinstance(value, unicode):
if isinstance(value, str):
value = value.encode("utf-8")
kingosticks marked this conversation as resolved.
Show resolved Hide resolved
query.append((key, value))

encoded_query = urllib.parse.urlencode(dict(query))
return urllib.parse.urlunsplit((scheme, netloc, path, encoded_query, ""))
return urllib.parse.urlunsplit(
(scheme, netloc, path, encoded_query, "")
)

def _normalise_query_string(self, url, params=None):
u = urllib.parse.urlsplit(url)
Expand All @@ -235,7 +239,9 @@ def _normalise_query_string(self, url, params=None):
query.update(params)
sorted_unique_query = sorted(query.items())
encoded_query = urllib.parse.urlencode(sorted_unique_query)
return urllib.parse.urlunsplit((scheme, netloc, path, encoded_query, ""))
return urllib.parse.urlunsplit(
(scheme, netloc, path, encoded_query, "")
)

def _parse_retry_after(self, response):
"""Parse Retry-After header from response if it is set."""
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Expand Up @@ -14,11 +14,11 @@ def caplog(caplog):


@pytest.fixture
def config(tmpdir):
def config(tmp_path):
return {
"core": {
"cache_dir": "%s" % tmpdir.join("cache"),
"data_dir": "%s" % tmpdir.join("data"),
"cache_dir": "%s" % (tmp_path / "cache"),
"data_dir": "%s" % (tmp_path / "data"),
kingosticks marked this conversation as resolved.
Show resolved Hide resolved
},
"proxy": {},
"spotify": {
Expand Down
6 changes: 3 additions & 3 deletions tests/test_backend.py
Expand Up @@ -45,7 +45,7 @@ def test_init_disables_playlists_provider_if_not_allowed(spotify_mock, config):
assert backend.playlists is None


def test_on_start_creates_configured_session(tmpdir, spotify_mock, config):
def test_on_start_creates_configured_session(tmp_path, spotify_mock, config):
cache_location_mock = mock.PropertyMock()
settings_location_mock = mock.PropertyMock()
config_mock = spotify_mock.Config.return_value
Expand All @@ -57,10 +57,10 @@ def test_on_start_creates_configured_session(tmpdir, spotify_mock, config):
spotify_mock.Config.assert_called_once_with()
config_mock.load_application_key_file.assert_called_once_with(mock.ANY)
cache_location_mock.assert_called_once_with(
"%s" % tmpdir.join("cache", "spotify")
bytes(tmp_path / "cache" / "spotify")
)
settings_location_mock.assert_called_once_with(
"%s" % tmpdir.join("data", "spotify")
bytes(tmp_path / "data" / "spotify")
)
spotify_mock.Session.assert_called_once_with(config_mock)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_images.py
Expand Up @@ -177,7 +177,7 @@ def test_invalid_uri_fails(img_provider):
with pytest.raises(ValueError) as exc:
img_provider.get_images(["foo:bar"])

assert str(exc.value) == "Could not parse u'foo:bar' as a Spotify URI"
assert str(exc.value) == "Could not parse 'foo:bar' as a Spotify URI"


def test_no_uris_gives_no_results(img_provider):
Expand Down