<s> from __future__ import absolute_import , unicode_literals <EOL> import unittest <EOL> import pykka <EOL> from mopidy import core <EOL> from mopidy . core import PlaybackState <EOL> from mopidy . internal import deprecation <EOL> from mopidy . models import Track <EOL> from mopidy . mpd import dispatcher <EOL> from mopidy . mpd . protocol import status <EOL> from tests import dummy_audio , dummy_backend , dummy_mixer <EOL> PAUSED = PlaybackState . PAUSED <EOL> PLAYING = PlaybackState . PLAYING <EOL> STOPPED = PlaybackState . STOPPED <EOL> class StatusHandlerTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> } <EOL> self . audio = dummy_audio . create_proxy ( ) <EOL> self . mixer = dummy_mixer . create_proxy ( ) <EOL> self . backend = dummy_backend . create_proxy ( audio = self . audio ) <EOL> with deprecation . ignore ( ) : <EOL> self . core = core . Core . start ( <EOL> config , <EOL> audio = self . audio , <EOL> mixer = self . mixer , <EOL> backends = [ self . backend ] ) . proxy ( ) <EOL> self . dispatcher = dispatcher . MpdDispatcher ( core = self . core ) <EOL> self . context = self . dispatcher . context <EOL> def tearDown ( self ) : <EOL> pykka . ActorRegistry . stop_all ( ) <EOL> def set_tracklist ( self , track ) : <EOL> self . backend . library . dummy_library = [ track ] <EOL> self . core . tracklist . add ( uris = [ track . uri ] ) . get ( ) <EOL> def test_stats_method ( self ) : <EOL> result = status . stats ( self . context ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_status_method_contains_volume_with_na_value ( self ) : <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , - <NUM_LIT:1> ) <EOL> def test_status_method_contains_volume ( self ) : <EOL> self . core . mixer . set_volume ( <NUM_LIT> ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT> ) <EOL> def test_status_method_contains_repeat_is_0 ( self ) : <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_status_method_contains_repeat_is_1 ( self ) : <EOL> self . core . tracklist . set_repeat ( True ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_status_method_contains_random_is_0 ( self ) : <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_status_method_contains_random_is_1 ( self ) : <EOL> self . core . tracklist . set_random ( True ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_status_method_contains_single ( self ) : <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertIn ( int ( result [ '<STR_LIT>' ] ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> def test_status_method_contains_consume_is_0 ( self ) : <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_status_method_contains_consume_is_1 ( self ) : <EOL> self . core . tracklist . set_consume ( True ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_status_method_contains_playlist ( self ) : <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertLessEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> ) <EOL> def test_status_method_contains_playlistlength ( self ) : <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_status_method_contains_xfade ( self ) : <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_status_method_contains_state_is_play ( self ) : <EOL> self . core . playback . state = PLAYING <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT:state>' , result ) <EOL> self . assertEqual ( result [ '<STR_LIT:state>' ] , '<STR_LIT>' ) <EOL> def test_status_method_contains_state_is_stop ( self ) : <EOL> self . core . playback . state = STOPPED <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT:state>' , result ) <EOL> self . assertEqual ( result [ '<STR_LIT:state>' ] , '<STR_LIT>' ) <EOL> def test_status_method_contains_state_is_pause ( self ) : <EOL> self . core . playback . state = PLAYING <EOL> self . core . playback . state = PAUSED <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT:state>' , result ) <EOL> self . assertEqual ( result [ '<STR_LIT:state>' ] , '<STR_LIT>' ) <EOL> def test_status_method_when_playlist_loaded_contains_song ( self ) : <EOL> self . set_tracklist ( Track ( uri = '<STR_LIT>' ) ) <EOL> self . core . playback . play ( ) . get ( ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertGreaterEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_status_method_when_playlist_loaded_contains_tlid_as_songid ( self ) : <EOL> self . set_tracklist ( Track ( uri = '<STR_LIT>' ) ) <EOL> self . core . playback . play ( ) . get ( ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def test_status_method_when_playing_contains_time_with_no_length ( self ) : <EOL> self . set_tracklist ( Track ( uri = '<STR_LIT>' , length = None ) ) <EOL> self . core . playback . play ( ) . get ( ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT:time>' , result ) <EOL> ( position , total ) = result [ '<STR_LIT:time>' ] . split ( '<STR_LIT::>' ) <EOL> position = int ( position ) <EOL> total = int ( total ) <EOL> self . assertLessEqual ( position , total ) <EOL> def test_status_method_when_playing_contains_time_with_length ( self ) : <EOL> self . set_tracklist ( Track ( uri = '<STR_LIT>' , length = <NUM_LIT> ) ) <EOL> self . core . playback . play ( ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT:time>' , result ) <EOL> ( position , total ) = result [ '<STR_LIT:time>' ] . split ( '<STR_LIT::>' ) <EOL> position = int ( position ) <EOL> total = int ( total ) <EOL> self . assertLessEqual ( position , total ) <EOL> def test_status_method_when_playing_contains_elapsed ( self ) : <EOL> self . set_tracklist ( Track ( uri = '<STR_LIT>' , length = <NUM_LIT> ) ) <EOL> self . core . playback . play ( ) . get ( ) <EOL> self . core . playback . pause ( ) <EOL> self . core . playback . seek ( <NUM_LIT> ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_status_method_when_starting_playing_contains_elapsed_zero ( self ) : <EOL> self . set_tracklist ( Track ( uri = '<STR_LIT>' , length = <NUM_LIT> ) ) <EOL> self . core . playback . play ( ) . get ( ) <EOL> self . core . playback . pause ( ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_status_method_when_playing_contains_bitrate ( self ) : <EOL> self . set_tracklist ( Track ( uri = '<STR_LIT>' , bitrate = <NUM_LIT> ) ) <EOL> self . core . playback . play ( ) . get ( ) <EOL> result = dict ( status . status ( self . context ) ) <EOL> self . assertIn ( '<STR_LIT>' , result ) <EOL> self . assertEqual ( int ( result [ '<STR_LIT>' ] ) , <NUM_LIT> ) </s>
