stream: Move scanner to backend, port tests to pytest
This commit is contained in:
parent
fcb61e3551
commit
f373d071ea
@ -20,21 +20,23 @@ class StreamBackend(pykka.ThreadingActor, backend.Backend):
|
||||
super(StreamBackend, self).__init__()
|
||||
|
||||
self.library = StreamLibraryProvider(
|
||||
backend=self, timeout=config['stream']['timeout'],
|
||||
blacklist=config['stream']['metadata_blacklist'],
|
||||
proxy=config['proxy'])
|
||||
backend=self, blacklist=config['stream']['metadata_blacklist'])
|
||||
self.playback = backend.PlaybackProvider(audio=audio, backend=self)
|
||||
self.playlists = None
|
||||
|
||||
self.uri_schemes = audio_lib.supported_uri_schemes(
|
||||
config['stream']['protocols'])
|
||||
|
||||
self._scanner = scan.Scanner(
|
||||
timeout=config['stream']['timeout'],
|
||||
proxy_config=config['proxy'])
|
||||
|
||||
|
||||
class StreamLibraryProvider(backend.LibraryProvider):
|
||||
|
||||
def __init__(self, backend, timeout, blacklist, proxy):
|
||||
def __init__(self, backend, blacklist):
|
||||
super(StreamLibraryProvider, self).__init__(backend)
|
||||
self._scanner = scan.Scanner(timeout=timeout, proxy_config=proxy)
|
||||
self._scanner = backend._scanner
|
||||
self._blacklist_re = re.compile(
|
||||
r'^(%s)$' % '|'.join(fnmatch.translate(u) for u in blacklist))
|
||||
|
||||
|
||||
@ -1,16 +1,10 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import unittest
|
||||
|
||||
import gobject
|
||||
gobject.threads_init()
|
||||
|
||||
import mock
|
||||
|
||||
import pygst
|
||||
pygst.require('0.10')
|
||||
import gst # noqa: pygst magic is needed to import correct gst
|
||||
import pytest
|
||||
|
||||
from mopidy.audio import scan
|
||||
from mopidy.internal import path
|
||||
from mopidy.models import Track
|
||||
from mopidy.stream import actor
|
||||
@ -18,27 +12,44 @@ from mopidy.stream import actor
|
||||
from tests import path_to_data_dir
|
||||
|
||||
|
||||
class LibraryProviderTest(unittest.TestCase):
|
||||
@pytest.fixture
|
||||
def scanner():
|
||||
return scan.Scanner(timeout=100, proxy_config={})
|
||||
|
||||
def setUp(self): # noqa: N802
|
||||
self.backend = mock.Mock()
|
||||
self.backend.uri_schemes = ['file']
|
||||
self.uri = path.path_to_uri(path_to_data_dir('song1.wav'))
|
||||
|
||||
def test_lookup_ignores_unknown_scheme(self):
|
||||
library = actor.StreamLibraryProvider(self.backend, 1000, [], {})
|
||||
self.assertFalse(library.lookup('http://example.com'))
|
||||
@pytest.fixture
|
||||
def backend(scanner):
|
||||
backend = mock.Mock()
|
||||
backend.uri_schemes = ['file']
|
||||
backend._scanner = scanner
|
||||
return backend
|
||||
|
||||
def test_lookup_respects_blacklist(self):
|
||||
library = actor.StreamLibraryProvider(self.backend, 10, [self.uri], {})
|
||||
self.assertEqual([Track(uri=self.uri)], library.lookup(self.uri))
|
||||
|
||||
def test_lookup_respects_blacklist_globbing(self):
|
||||
blacklist = [path.path_to_uri(path_to_data_dir('')) + '*']
|
||||
library = actor.StreamLibraryProvider(self.backend, 100, blacklist, {})
|
||||
self.assertEqual([Track(uri=self.uri)], library.lookup(self.uri))
|
||||
@pytest.fixture
|
||||
def track_uri():
|
||||
return path.path_to_uri(path_to_data_dir('song1.wav'))
|
||||
|
||||
def test_lookup_converts_uri_metadata_to_track(self):
|
||||
library = actor.StreamLibraryProvider(self.backend, 100, [], {})
|
||||
self.assertEqual([Track(length=4406, uri=self.uri)],
|
||||
library.lookup(self.uri))
|
||||
|
||||
def test_lookup_ignores_unknown_scheme(backend):
|
||||
library = actor.StreamLibraryProvider(backend, [])
|
||||
|
||||
assert library.lookup('http://example.com') == []
|
||||
|
||||
|
||||
def test_lookup_respects_blacklist(backend, track_uri):
|
||||
library = actor.StreamLibraryProvider(backend, [track_uri])
|
||||
|
||||
assert library.lookup(track_uri) == [Track(uri=track_uri)]
|
||||
|
||||
|
||||
def test_lookup_respects_blacklist_globbing(backend, track_uri):
|
||||
blacklist = [path.path_to_uri(path_to_data_dir('')) + '*']
|
||||
library = actor.StreamLibraryProvider(backend, blacklist)
|
||||
|
||||
assert library.lookup(track_uri) == [Track(uri=track_uri)]
|
||||
|
||||
|
||||
def test_lookup_converts_uri_metadata_to_track(backend, track_uri):
|
||||
library = actor.StreamLibraryProvider(backend, [])
|
||||
|
||||
assert library.lookup(track_uri) == [Track(length=4406, uri=track_uri)]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user