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

Fix library.lookup with an empty uri list #1620

Merged
Merged
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
5 changes: 3 additions & 2 deletions mopidy/core/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ def lookup(self, uri=None, uris=None):

# TODO: lookup(uris) to backend APIs
for backend, backend_uris in self._get_backends_to_uris(uris).items():
for u in backend_uris:
futures[(backend, u)] = backend.library.lookup(u)
if backend_uris:
Copy link
Member

Choose a reason for hiding this comment

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

Could also be for u in backend_uris or [] I think, but either way is fine with me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hehe, Yeh, but I've gone from super obfuscated to super obvious here - no middle ground!

for u in backend_uris:
futures[(backend, u)] = backend.library.lookup(u)

for (backend, u), future in futures.items():
with _backend_error_handling(backend):
Expand Down
3 changes: 3 additions & 0 deletions tests/core/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def test_browse_dir_returns_subdirs_and_tracks(self):
Ref.track(uri='dummy1:track:/foo/baz.mp3', name='Baz'),
])

def test_lookup_returns_empty_dict_for_no_uris(self):
self.assertEqual({}, self.core.library.lookup(uris=[]))

def test_lookup_fails_with_uri_and_uris_set(self):
with self.assertRaises(ValueError):
self.core.library.lookup('dummy1:a', ['dummy2:a'])
Expand Down