<s> from __future__ import absolute_import , unicode_literals <EOL> import unittest <EOL> import mock <EOL> import pykka <EOL> from mopidy import core , mixer <EOL> from tests import dummy_mixer <EOL> class CoreMixerTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mixer = mock . Mock ( spec = mixer . Mixer ) <EOL> self . core = core . Core ( mixer = self . mixer , backends = [ ] ) <EOL> def test_get_volume ( self ) : <EOL> self . mixer . get_volume . return_value . get . return_value = <NUM_LIT:30> <EOL> self . assertEqual ( self . core . mixer . get_volume ( ) , <NUM_LIT:30> ) <EOL> self . mixer . get_volume . assert_called_once_with ( ) <EOL> def test_set_volume ( self ) : <EOL> self . mixer . set_volume . return_value . get . return_value = True <EOL> self . core . mixer . set_volume ( <NUM_LIT:30> ) <EOL> self . mixer . set_volume . assert_called_once_with ( <NUM_LIT:30> ) <EOL> def test_get_mute ( self ) : <EOL> self . mixer . get_mute . return_value . get . return_value = True <EOL> self . assertEqual ( self . core . mixer . get_mute ( ) , True ) <EOL> self . mixer . get_mute . assert_called_once_with ( ) <EOL> def test_set_mute ( self ) : <EOL> self . mixer . set_mute . return_value . get . return_value = True <EOL> self . core . mixer . set_mute ( True ) <EOL> self . mixer . set_mute . assert_called_once_with ( True ) <EOL> class CoreNoneMixerTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . core = core . Core ( mixer = None , backends = [ ] ) <EOL> def test_get_volume_return_none_because_it_is_unknown ( self ) : <EOL> self . assertEqual ( self . core . mixer . get_volume ( ) , None ) <EOL> def test_set_volume_return_false_because_it_failed ( self ) : <EOL> self . assertEqual ( self . core . mixer . set_volume ( <NUM_LIT:30> ) , False ) <EOL> def test_get_mute_return_none_because_it_is_unknown ( self ) : <EOL> self . assertEqual ( self . core . mixer . get_mute ( ) , None ) <EOL> def test_set_mute_return_false_because_it_failed ( self ) : <EOL> self . assertEqual ( self . core . mixer . set_mute ( True ) , False ) <EOL> @ mock . patch . object ( mixer . MixerListener , '<STR_LIT>' ) <EOL> class CoreMixerListenerTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mixer = dummy_mixer . create_proxy ( ) <EOL> self . core = core . Core ( mixer = self . mixer , backends = [ ] ) <EOL> def tearDown ( self ) : <EOL> pykka . ActorRegistry . stop_all ( ) <EOL> def test_forwards_mixer_volume_changed_event_to_frontends ( self , send ) : <EOL> self . assertEqual ( self . core . mixer . set_volume ( volume = <NUM_LIT> ) , True ) <EOL> self . assertEqual ( send . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( send . call_args [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> def test_forwards_mixer_mute_changed_event_to_frontends ( self , send ) : <EOL> self . core . mixer . set_mute ( mute = True ) <EOL> self . assertEqual ( send . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( send . call_args [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , True ) <EOL> @ mock . patch . object ( mixer . MixerListener , '<STR_LIT>' ) <EOL> class CoreNoneMixerListenerTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . core = core . Core ( mixer = None , backends = [ ] ) <EOL> def test_forwards_mixer_volume_changed_event_to_frontends ( self , send ) : <EOL> self . assertEqual ( self . core . mixer . set_volume ( volume = <NUM_LIT> ) , False ) <EOL> self . assertEqual ( send . call_count , <NUM_LIT:0> ) <EOL> def test_forwards_mixer_mute_changed_event_to_frontends ( self , send ) : <EOL> self . core . mixer . set_mute ( mute = True ) <EOL> self . assertEqual ( send . call_count , <NUM_LIT:0> ) <EOL> class MockBackendCoreMixerBase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mixer = mock . Mock ( ) <EOL> self . mixer . actor_ref . actor_class . __name__ = '<STR_LIT>' <EOL> self . core = core . Core ( mixer = self . mixer , backends = [ ] ) <EOL> class GetVolumeBadBackendTest ( MockBackendCoreMixerBase ) : <EOL> def test_backend_raises_exception ( self ) : <EOL> self . mixer . get_volume . return_value . get . side_effect = Exception <EOL> self . assertEqual ( self . core . mixer . get_volume ( ) , None ) <EOL> def test_backend_returns_too_small_value ( self ) : <EOL> self . mixer . get_volume . return_value . get . return_value = - <NUM_LIT:1> <EOL> self . assertEqual ( self . core . mixer . get_volume ( ) , None ) <EOL> def test_backend_returns_too_large_value ( self ) : <EOL> self . mixer . get_volume . return_value . get . return_value = <NUM_LIT:1000> <EOL> self . assertEqual ( self . core . mixer . get_volume ( ) , None ) <EOL> def test_backend_returns_wrong_type ( self ) : <EOL> self . mixer . get_volume . return_value . get . return_value = '<STR_LIT>' <EOL> self . assertEqual ( self . core . mixer . get_volume ( ) , None ) <EOL> class SetVolumeBadBackendTest ( MockBackendCoreMixerBase ) : <EOL> def test_backend_raises_exception ( self ) : <EOL> self . mixer . set_volume . return_value . get . side_effect = Exception <EOL> self . assertFalse ( self . core . mixer . set_volume ( <NUM_LIT:30> ) ) <EOL> def test_backend_returns_wrong_type ( self ) : <EOL> self . mixer . set_volume . return_value . get . return_value = '<STR_LIT>' <EOL> self . assertFalse ( self . core . mixer . set_volume ( <NUM_LIT:30> ) ) <EOL> class GetMuteBadBackendTest ( MockBackendCoreMixerBase ) : <EOL> def test_backend_raises_exception ( self ) : <EOL> self . mixer . get_mute . return_value . get . side_effect = Exception <EOL> self . assertEqual ( self . core . mixer . get_mute ( ) , None ) <EOL> def test_backend_returns_wrong_type ( self ) : <EOL> self . mixer . get_mute . return_value . get . return_value = '<STR_LIT>' <EOL> self . assertEqual ( self . core . mixer . get_mute ( ) , None ) <EOL> class SetMuteBadBackendTest ( MockBackendCoreMixerBase ) : <EOL> def test_backend_raises_exception ( self ) : <EOL> self . mixer . set_mute . return_value . get . side_effect = Exception <EOL> self . assertFalse ( self . core . mixer . set_mute ( True ) ) <EOL> def test_backend_returns_wrong_type ( self ) : <EOL> self . mixer . set_mute . return_value . get . return_value = '<STR_LIT>' <EOL> self . assertFalse ( self . core . mixer . set_mute ( True ) ) </s>
