<s> from __future__ import absolute_import , unicode_literals <EOL> import os <EOL> import shutil <EOL> import tempfile <EOL> import unittest <EOL> import mock <EOL> import pykka <EOL> from mopidy import core , exceptions <EOL> from mopidy . local import actor , json <EOL> from mopidy . models import Album , Artist , Image , Track <EOL> from tests import path_to_data_dir <EOL> class LocalLibraryProviderTest ( unittest . TestCase ) : <EOL> artists = [ <EOL> Artist ( name = '<STR_LIT>' ) , <EOL> Artist ( name = '<STR_LIT>' ) , <EOL> Artist ( name = '<STR_LIT>' ) , <EOL> Artist ( name = '<STR_LIT>' ) , <EOL> Artist ( name = '<STR_LIT>' ) , <EOL> Artist ( name = '<STR_LIT>' ) , <EOL> Artist ( ) , <EOL> ] <EOL> albums = [ <EOL> Album ( name = '<STR_LIT>' , artists = [ artists [ <NUM_LIT:0> ] ] ) , <EOL> Album ( name = '<STR_LIT>' , artists = [ artists [ <NUM_LIT:1> ] ] ) , <EOL> Album ( name = '<STR_LIT>' , artists = [ artists [ <NUM_LIT:2> ] ] ) , <EOL> Album ( name = '<STR_LIT>' ) , <EOL> Album ( artists = [ artists [ - <NUM_LIT:1> ] ] ) , <EOL> ] <EOL> tracks = [ <EOL> Track ( <EOL> uri = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> artists = [ artists [ <NUM_LIT:0> ] ] , album = albums [ <NUM_LIT:0> ] , <EOL> date = '<STR_LIT>' , length = <NUM_LIT> , track_no = <NUM_LIT:1> ) , <EOL> Track ( <EOL> uri = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> artists = [ artists [ <NUM_LIT:1> ] ] , album = albums [ <NUM_LIT:1> ] , <EOL> date = '<STR_LIT>' , length = <NUM_LIT> , track_no = <NUM_LIT:2> ) , <EOL> Track ( <EOL> uri = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> artists = [ artists [ <NUM_LIT:3> ] ] , album = albums [ <NUM_LIT:2> ] , <EOL> date = '<STR_LIT>' , length = <NUM_LIT> , track_no = <NUM_LIT:3> ) , <EOL> Track ( <EOL> uri = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> artists = [ artists [ <NUM_LIT:2> ] ] , album = albums [ <NUM_LIT:3> ] , <EOL> date = '<STR_LIT>' , length = <NUM_LIT> , track_no = <NUM_LIT:4> , <EOL> comment = '<STR_LIT>' ) , <EOL> Track ( <EOL> uri = '<STR_LIT>' , name = '<STR_LIT>' , genre = '<STR_LIT>' , <EOL> album = albums [ <NUM_LIT:3> ] , length = <NUM_LIT> , composers = [ artists [ <NUM_LIT:4> ] ] ) , <EOL> Track ( <EOL> uri = '<STR_LIT>' , name = '<STR_LIT>' , genre = '<STR_LIT>' , <EOL> album = albums [ <NUM_LIT:3> ] , length = <NUM_LIT> , performers = [ artists [ <NUM_LIT:5> ] ] ) , <EOL> Track ( uri = '<STR_LIT>' , album = albums [ - <NUM_LIT:1> ] ) , <EOL> ] <EOL> config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : path_to_data_dir ( '<STR_LIT>' ) , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : path_to_data_dir ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } <EOL> def setUp ( self ) : <EOL> actor . LocalBackend . libraries = [ json . JsonLibrary ] <EOL> self . backend = actor . LocalBackend . start ( <EOL> config = self . config , audio = None ) . proxy ( ) <EOL> self . core = core . Core ( backends = [ self . backend ] ) <EOL> self . library = self . core . library <EOL> def tearDown ( self ) : <EOL> pykka . ActorRegistry . stop_all ( ) <EOL> actor . LocalBackend . libraries = [ ] <EOL> def find_exact ( self , ** query ) : <EOL> return self . library . search ( query = query , exact = True ) <EOL> def search ( self , ** query ) : <EOL> return self . library . search ( query = query ) <EOL> def test_refresh ( self ) : <EOL> self . library . refresh ( ) <EOL> @ unittest . SkipTest <EOL> def test_refresh_uri ( self ) : <EOL> pass <EOL> def test_refresh_missing_uri ( self ) : <EOL> tmpdir = tempfile . mkdtemp ( ) <EOL> try : <EOL> tmpdir_local = os . path . join ( tmpdir , '<STR_LIT>' ) <EOL> shutil . copytree ( path_to_data_dir ( '<STR_LIT>' ) , tmpdir_local ) <EOL> config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : tmpdir , <EOL> } , <EOL> '<STR_LIT>' : self . config [ '<STR_LIT>' ] , <EOL> } <EOL> backend = actor . LocalBackend ( config = config , audio = None ) <EOL> result = backend . library . lookup ( self . tracks [ <NUM_LIT:0> ] . uri ) <EOL> self . assertEqual ( result , self . tracks [ <NUM_LIT:0> : <NUM_LIT:1> ] ) <EOL> tmplib = os . path . join ( tmpdir_local , '<STR_LIT>' ) <EOL> open ( tmplib , '<STR_LIT:w>' ) . close ( ) <EOL> backend . library . refresh ( ) <EOL> result = backend . library . lookup ( self . tracks [ <NUM_LIT:0> ] . uri ) <EOL> self . assertEqual ( result , [ ] ) <EOL> finally : <EOL> shutil . rmtree ( tmpdir ) <EOL> @ unittest . SkipTest <EOL> def test_browse ( self ) : <EOL> pass <EOL> def test_lookup ( self ) : <EOL> uri = self . tracks [ <NUM_LIT:0> ] . uri <EOL> result = self . library . lookup ( uris = [ uri ] ) <EOL> self . assertEqual ( result [ uri ] , self . tracks [ <NUM_LIT:0> : <NUM_LIT:1> ] ) <EOL> def test_lookup_unknown_track ( self ) : <EOL> tracks = self . library . lookup ( uris = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( tracks , { '<STR_LIT>' : [ ] } ) <EOL> @ mock . patch . object ( json . JsonLibrary , '<STR_LIT>' ) <EOL> def test_lookup_return_single_track ( self , mock_lookup ) : <EOL> backend = actor . LocalBackend ( config = self . config , audio = None ) <EOL> mock_lookup . return_value = self . tracks [ <NUM_LIT:0> ] <EOL> tracks = backend . library . lookup ( self . tracks [ <NUM_LIT:0> ] . uri ) <EOL> mock_lookup . assert_called_with ( self . tracks [ <NUM_LIT:0> ] . uri ) <EOL> self . assertEqual ( tracks , self . tracks [ <NUM_LIT:0> : <NUM_LIT:1> ] ) <EOL> mock_lookup . return_value = None <EOL> tracks = backend . library . lookup ( '<STR_LIT>' ) <EOL> mock_lookup . assert_called_with ( '<STR_LIT>' ) <EOL> self . assertEqual ( tracks , [ ] ) <EOL> def test_find_exact_no_hits ( self ) : <EOL> result = self . find_exact ( track_name = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( artist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( albumartist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( composer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( performer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( album = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( date = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( genre = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( track_no = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( track_no = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( comment = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( uri = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> def test_find_exact_uri ( self ) : <EOL> track_1_uri = '<STR_LIT>' <EOL> result = self . find_exact ( uri = track_1_uri ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> track_2_uri = '<STR_LIT>' <EOL> result = self . find_exact ( uri = track_2_uri ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_find_exact_track_name ( self ) : <EOL> result = self . find_exact ( track_name = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . find_exact ( track_name = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_find_exact_artist ( self ) : <EOL> result = self . find_exact ( artist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . find_exact ( artist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> result = self . find_exact ( artist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:3> : <NUM_LIT:4> ] ) <EOL> def test_find_exact_composer ( self ) : <EOL> result = self . find_exact ( composer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:4> : <NUM_LIT:5> ] ) <EOL> result = self . find_exact ( composer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> def test_find_exact_performer ( self ) : <EOL> result = self . find_exact ( performer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:5> : <NUM_LIT:6> ] ) <EOL> result = self . find_exact ( performer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> def test_find_exact_album ( self ) : <EOL> result = self . find_exact ( album = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . find_exact ( album = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_find_exact_albumartist ( self ) : <EOL> result = self . find_exact ( albumartist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ self . tracks [ <NUM_LIT:0> ] ] ) <EOL> result = self . find_exact ( albumartist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ self . tracks [ <NUM_LIT:1> ] ] ) <EOL> result = self . find_exact ( albumartist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ self . tracks [ <NUM_LIT:2> ] ] ) <EOL> def test_find_exact_track_no ( self ) : <EOL> result = self . find_exact ( track_no = [ '<STR_LIT:1>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . find_exact ( track_no = [ '<STR_LIT:2>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_find_exact_genre ( self ) : <EOL> result = self . find_exact ( genre = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:4> : <NUM_LIT:5> ] ) <EOL> result = self . find_exact ( genre = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:5> : <NUM_LIT:6> ] ) <EOL> def test_find_exact_date ( self ) : <EOL> result = self . find_exact ( date = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . find_exact ( date = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . find_exact ( date = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_find_exact_comment ( self ) : <EOL> result = self . find_exact ( <EOL> comment = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:3> : <NUM_LIT:4> ] ) <EOL> result = self . find_exact ( <EOL> comment = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> def test_find_exact_any ( self ) : <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( result [ <NUM_LIT:0> ] . tracks ) , <NUM_LIT:2> ) <EOL> self . assertIn ( self . tracks [ <NUM_LIT:2> ] , result [ <NUM_LIT:0> ] . tracks ) <EOL> self . assertIn ( self . tracks [ <NUM_LIT:3> ] , result [ <NUM_LIT:0> ] . tracks ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:4> : <NUM_LIT:5> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:5> : <NUM_LIT:6> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:4> : <NUM_LIT:5> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:5> : <NUM_LIT:6> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> result = self . find_exact ( <EOL> any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:3> : <NUM_LIT:4> ] ) <EOL> result = self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> def test_find_exact_wrong_type ( self ) : <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( wrong = [ '<STR_LIT:test>' ] ) <EOL> def test_find_exact_with_empty_query ( self ) : <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( artist = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( albumartist = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( track_name = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( composer = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( performer = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( album = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( track_no = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( genre = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( date = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( comment = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . find_exact ( any = [ '<STR_LIT>' ] ) <EOL> def test_search_no_hits ( self ) : <EOL> result = self . search ( track_name = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( artist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( albumartist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( composer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( performer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( album = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( track_no = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( track_no = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( genre = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( date = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( comment = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( uri = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> def test_search_uri ( self ) : <EOL> result = self . search ( uri = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( uri = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_search_track_name ( self ) : <EOL> result = self . search ( track_name = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( track_name = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_search_artist ( self ) : <EOL> result = self . search ( artist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( artist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_search_albumartist ( self ) : <EOL> result = self . search ( albumartist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ self . tracks [ <NUM_LIT:0> ] ] ) <EOL> result = self . search ( albumartist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ self . tracks [ <NUM_LIT:1> ] ] ) <EOL> result = self . search ( albumartist = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ self . tracks [ <NUM_LIT:2> ] ] ) <EOL> def test_search_composer ( self ) : <EOL> result = self . search ( composer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:4> : <NUM_LIT:5> ] ) <EOL> def test_search_performer ( self ) : <EOL> result = self . search ( performer = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:5> : <NUM_LIT:6> ] ) <EOL> def test_search_album ( self ) : <EOL> result = self . search ( album = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( album = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_search_genre ( self ) : <EOL> result = self . search ( genre = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:4> : <NUM_LIT:5> ] ) <EOL> result = self . search ( genre = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:5> : <NUM_LIT:6> ] ) <EOL> def test_search_date ( self ) : <EOL> result = self . search ( date = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( date = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( date = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , [ ] ) <EOL> result = self . search ( date = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_search_track_no ( self ) : <EOL> result = self . search ( track_no = [ '<STR_LIT:1>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( track_no = [ '<STR_LIT:2>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> def test_search_comment ( self ) : <EOL> result = self . search ( comment = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:3> : <NUM_LIT:4> ] ) <EOL> result = self . search ( comment = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:3> : <NUM_LIT:4> ] ) <EOL> def test_search_any ( self ) : <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:4> : <NUM_LIT:5> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:5> : <NUM_LIT:6> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:1> : <NUM_LIT:2> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( result [ <NUM_LIT:0> ] . tracks ) , <NUM_LIT:2> ) <EOL> self . assertIn ( self . tracks [ <NUM_LIT:2> ] , result [ <NUM_LIT:0> ] . tracks ) <EOL> self . assertIn ( self . tracks [ <NUM_LIT:3> ] , result [ <NUM_LIT:0> ] . tracks ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:4> : <NUM_LIT:5> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:5> : <NUM_LIT:6> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:3> : <NUM_LIT:4> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ <NUM_LIT:3> : <NUM_LIT:4> ] ) <EOL> result = self . search ( any = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( result [ <NUM_LIT:0> ] . tracks ) , self . tracks [ : <NUM_LIT:1> ] ) <EOL> def test_search_wrong_type ( self ) : <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( wrong = [ '<STR_LIT:test>' ] ) <EOL> def test_search_with_empty_query ( self ) : <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( artist = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( albumartist = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( composer = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( performer = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( track_name = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( album = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( genre = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( date = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( comment = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( uri = [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( exceptions . ValidationError ) : <EOL> self . search ( any = [ '<STR_LIT>' ] ) <EOL> def test_default_get_images_impl_no_images ( self ) : <EOL> result = self . library . get_images ( [ track . uri for track in self . tracks ] ) <EOL> self . assertEqual ( result , { track . uri : tuple ( ) for track in self . tracks } ) <EOL> @ mock . patch . object ( json . JsonLibrary , '<STR_LIT>' ) <EOL> def test_default_get_images_impl_album_images ( self , mock_lookup ) : <EOL> library = actor . LocalBackend ( config = self . config , audio = None ) . library <EOL> image = Image ( uri = '<STR_LIT>' ) <EOL> album = Album ( images = [ image . uri ] ) <EOL> track = Track ( uri = '<STR_LIT>' , album = album ) <EOL> mock_lookup . return_value = [ track ] <EOL> result = library . get_images ( [ track . uri ] ) <EOL> self . assertEqual ( result , { track . uri : [ image ] } ) <EOL> @ mock . patch . object ( json . JsonLibrary , '<STR_LIT>' ) <EOL> def test_default_get_images_impl_single_track ( self , mock_lookup ) : <EOL> library = actor . LocalBackend ( config = self . config , audio = None ) . library <EOL> image = Image ( uri = '<STR_LIT>' ) <EOL> album = Album ( images = [ image . uri ] ) <EOL> track = Track ( uri = '<STR_LIT>' , album = album ) <EOL> mock_lookup . return_value = track <EOL> result = library . get_images ( [ track . uri ] ) <EOL> self . assertEqual ( result , { track . uri : [ image ] } ) <EOL> @ mock . patch . object ( json . JsonLibrary , '<STR_LIT>' ) <EOL> def test_local_library_get_images ( self , mock_get_images ) : <EOL> library = actor . LocalBackend ( config = self . config , audio = None ) . library <EOL> image = Image ( uri = '<STR_LIT>' ) <EOL> track = Track ( uri = '<STR_LIT>' ) <EOL> mock_get_images . return_value = { track . uri : [ image ] } <EOL> result = library . get_images ( [ track . uri ] ) <EOL> self . assertEqual ( result , { track . uri : [ image ] } ) </s>
