From 6acaa490e91255e2cb2494059ae1b1a63e3729ff Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 13 Nov 2012 00:17:45 +0100 Subject: [PATCH] Make all strings unicode by default (fixes #224) --- bin/mopidy-scan | 22 +- docs/changes.rst | 3 + docs/conf.py | 10 +- docs/development.rst | 16 + mopidy/__init__.py | 6 +- mopidy/__main__.py | 16 +- mopidy/audio/__init__.py | 2 + mopidy/audio/actor.py | 24 +- mopidy/audio/listener.py | 2 + mopidy/audio/mixers/__init__.py | 2 + mopidy/audio/mixers/auto.py | 2 + mopidy/audio/mixers/fake.py | 2 + mopidy/audio/mixers/nad.py | 18 +- mopidy/audio/mixers/utils.py | 2 + mopidy/backends/__init__.py | 1 + mopidy/backends/base.py | 2 + mopidy/backends/dummy.py | 4 +- mopidy/backends/local/__init__.py | 2 + mopidy/backends/local/actor.py | 6 +- mopidy/backends/local/library.py | 6 +- mopidy/backends/local/stored_playlists.py | 4 +- mopidy/backends/local/translator.py | 12 +- mopidy/backends/spotify/__init__.py | 2 + mopidy/backends/spotify/actor.py | 8 +- mopidy/backends/spotify/container_manager.py | 12 +- mopidy/backends/spotify/library.py | 26 +- mopidy/backends/spotify/playback.py | 2 + mopidy/backends/spotify/playlist_manager.py | 42 ++- mopidy/backends/spotify/session_manager.py | 32 +- mopidy/backends/spotify/stored_playlists.py | 2 + mopidy/backends/spotify/translator.py | 10 +- mopidy/core/__init__.py | 2 + mopidy/core/actor.py | 2 + mopidy/core/current_playlist.py | 10 +- mopidy/core/library.py | 2 + mopidy/core/listener.py | 2 + mopidy/core/playback.py | 24 +- mopidy/core/stored_playlists.py | 2 + mopidy/exceptions.py | 3 + mopidy/frontends/__init__.py | 1 + mopidy/frontends/lastfm.py | 22 +- mopidy/frontends/mpd/__init__.py | 2 + mopidy/frontends/mpd/actor.py | 6 +- mopidy/frontends/mpd/dispatcher.py | 28 +- mopidy/frontends/mpd/exceptions.py | 14 +- mopidy/frontends/mpd/protocol/__init__.py | 10 +- mopidy/frontends/mpd/protocol/audio_output.py | 2 + mopidy/frontends/mpd/protocol/command_list.py | 6 +- mopidy/frontends/mpd/protocol/connection.py | 6 +- .../mpd/protocol/current_playlist.py | 25 +- mopidy/frontends/mpd/protocol/empty.py | 2 + mopidy/frontends/mpd/protocol/music_db.py | 34 +- mopidy/frontends/mpd/protocol/playback.py | 8 +- mopidy/frontends/mpd/protocol/reflection.py | 4 +- mopidy/frontends/mpd/protocol/status.py | 14 +- mopidy/frontends/mpd/protocol/stickers.py | 2 + .../mpd/protocol/stored_playlists.py | 13 +- mopidy/frontends/mpd/session.py | 14 +- mopidy/frontends/mpd/translator.py | 6 +- mopidy/frontends/mpris/__init__.py | 2 + mopidy/frontends/mpris/actor.py | 28 +- mopidy/frontends/mpris/objects.py | 66 ++-- mopidy/models.py | 6 +- mopidy/scanner.py | 4 +- mopidy/settings.py | 44 +-- mopidy/utils/__init__.py | 1 + mopidy/utils/deps.py | 2 + mopidy/utils/encoding.py | 2 + mopidy/utils/formatting.py | 4 +- mopidy/utils/importing.py | 3 + mopidy/utils/log.py | 8 +- mopidy/utils/network.py | 38 +- mopidy/utils/path.py | 10 +- mopidy/utils/process.py | 30 +- mopidy/utils/settings.py | 46 +-- mopidy/utils/versioning.py | 2 + setup.py | 2 + tests/__init__.py | 2 + tests/__main__.py | 2 + tests/audio_test.py | 2 + tests/backends/__init__.py | 1 + tests/backends/base/__init__.py | 3 + tests/backends/base/current_playlist.py | 10 +- tests/backends/base/library.py | 2 + tests/backends/base/playback.py | 2 + tests/backends/base/stored_playlists.py | 26 +- tests/backends/events_test.py | 2 + tests/backends/local/__init__.py | 3 + tests/backends/local/current_playlist_test.py | 2 + tests/backends/local/library_test.py | 2 + tests/backends/local/playback_test.py | 2 + tests/backends/local/stored_playlists_test.py | 24 +- tests/backends/local/translator_test.py | 10 +- tests/core/__init__.py | 1 + tests/core/actor_test.py | 6 +- tests/core/library_test.py | 2 + tests/core/listener_test.py | 2 + tests/core/playback_test.py | 2 + tests/core/stored_playlists_test.py | 2 + tests/frontends/__init__.py | 1 + tests/frontends/mpd/__init__.py | 1 + tests/frontends/mpd/dispatcher_test.py | 8 +- tests/frontends/mpd/exception_test.py | 20 +- tests/frontends/mpd/protocol/__init__.py | 8 +- .../mpd/protocol/audio_output_test.py | 20 +- .../mpd/protocol/authentication_test.py | 28 +- .../mpd/protocol/command_list_test.py | 48 +-- .../frontends/mpd/protocol/connection_test.py | 38 +- .../mpd/protocol/current_playlist_test.py | 342 +++++++++--------- tests/frontends/mpd/protocol/idle_test.py | 148 ++++---- tests/frontends/mpd/protocol/music_db_test.py | 326 ++++++++--------- tests/frontends/mpd/protocol/playback_test.py | 246 ++++++------- .../frontends/mpd/protocol/reflection_test.py | 78 ++-- .../frontends/mpd/protocol/regression_test.py | 58 +-- tests/frontends/mpd/protocol/status_test.py | 40 +- tests/frontends/mpd/protocol/stickers_test.py | 26 +- .../mpd/protocol/stored_playlists_test.py | 86 ++--- tests/frontends/mpd/serializer_test.py | 18 +- tests/frontends/mpd/status_test.py | 2 + tests/frontends/mpris/__init__.py | 1 + tests/frontends/mpris/events_test.py | 2 + .../frontends/mpris/player_interface_test.py | 2 + tests/frontends/mpris/root_interface_test.py | 2 + tests/help_test.py | 2 + tests/models_test.py | 218 +++++------ tests/outputs/__init__.py | 1 + tests/scanner_test.py | 10 +- tests/utils/__init__.py | 1 + tests/utils/deps_test.py | 2 + tests/utils/encoding_test.py | 12 +- tests/utils/importing_test.py | 2 + tests/utils/network/__init__.py | 1 + tests/utils/network/connection_test.py | 2 + tests/utils/network/lineprotocol_test.py | 30 +- tests/utils/network/server_test.py | 2 + tests/utils/network/utils_test.py | 2 + tests/utils/path_test.py | 40 +- tests/utils/settings_test.py | 38 +- tests/version_test.py | 2 + tools/debug-proxy.py | 2 + tools/idle.py | 2 + 141 files changed, 1595 insertions(+), 1297 deletions(-) diff --git a/bin/mopidy-scan b/bin/mopidy-scan index 869aa662..001ea372 100755 --- a/bin/mopidy-scan +++ b/bin/mopidy-scan @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import unicode_literals + import sys import logging @@ -8,20 +10,26 @@ from mopidy.utils.log import setup_console_logging, setup_root_logger from mopidy.scanner import Scanner, translator from mopidy.frontends.mpd.translator import tracks_to_tag_cache_format + setup_root_logger() setup_console_logging(2) + tracks = [] + def store(data): track = translator(data) tracks.append(track) - logging.debug(u'Added %s', track.uri) + logging.debug('Added %s', track.uri) + def debug(uri, error, debug): - logging.error(u'Failed %s: %s - %s', uri, error, debug) + logging.error('Failed %s: %s - %s', uri, error, debug) + + +logging.info('Scanning %s', settings.LOCAL_MUSIC_PATH) -logging.info(u'Scanning %s', settings.LOCAL_MUSIC_PATH) scanner = Scanner(settings.LOCAL_MUSIC_PATH, store, debug) try: @@ -29,10 +37,12 @@ try: except KeyboardInterrupt: scanner.stop() -logging.info(u'Done') + +logging.info('Done') + for a in tracks_to_tag_cache_format(tracks): if len(a) == 1: - print (u'%s' % a).encode('utf-8') + print ('%s' % a).encode('utf-8') else: - print (u'%s: %s' % a).encode('utf-8') + print ('%s: %s' % a).encode('utf-8') diff --git a/docs/changes.rst b/docs/changes.rst index 3499fb04..670921d9 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -93,6 +93,9 @@ backends: :attr:`mopidy.settings.DEBUG_THREAD` setting a ``SIGUSR1`` signal will dump the traceback for all running threads. +- Make the entire code base use unicode strings by default, and only fall back + to bytestrings where it is required. Another step closer to Python 3. + **Bug fixes** - :issue:`218`: The MPD commands ``listplaylist`` and ``listplaylistinfo`` now diff --git a/docs/conf.py b/docs/conf.py index d02303df..d5debb46 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,6 +12,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. +from __future__ import unicode_literals + import os import sys @@ -89,8 +91,8 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'Mopidy' -copyright = u'2010-2012, Stein Magnus Jodal and contributors' +project = 'Mopidy' +copyright = '2010-2012, Stein Magnus Jodal and contributors' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -231,8 +233,8 @@ latex_documents = [ ( 'index', 'Mopidy.tex', - u'Mopidy Documentation', - u'Stein Magnus Jodal', + 'Mopidy Documentation', + 'Stein Magnus Jodal', 'manual' ), ] diff --git a/docs/development.rst b/docs/development.rst index 5c01d6d0..1211cec4 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -84,6 +84,22 @@ contributing. Code style ========== +- Always import ``unicode_literals`` and use unicode literals for everything + except where you're explicitly working with bytes, which are marked with the + ``b`` prefix. + + Do this:: + + from __future__ import unicode_literals + + foo = 'I am a unicode string, which is a sane default' + bar = b'I am a bytestring' + + Not this:: + + foo = u'I am a unicode string' + bar = 'I am a bytestring, but was it intentional?' + - Follow :pep:`8` unless otherwise noted. `pep8.py `_ or `flake8 `_ can be used to check your code diff --git a/mopidy/__init__.py b/mopidy/__init__.py index 3010acf4..072a604c 100644 --- a/mopidy/__init__.py +++ b/mopidy/__init__.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + # pylint: disable = E0611,F0401 from distutils.version import StrictVersion as SV # pylint: enable = E0611,F0401 @@ -9,13 +11,13 @@ import pykka if not (2, 6) <= sys.version_info < (3,): sys.exit( - u'Mopidy requires Python >= 2.6, < 3, but found %s' % + 'Mopidy requires Python >= 2.6, < 3, but found %s' % '.'.join(map(str, sys.version_info[:3]))) if (isinstance(pykka.__version__, basestring) and not SV('1.0') <= SV(pykka.__version__) < SV('2.0')): sys.exit( - u'Mopidy requires Pykka >= 1.0, < 2, but found %s' % pykka.__version__) + 'Mopidy requires Pykka >= 1.0, < 2, but found %s' % pykka.__version__) warnings.filterwarnings('ignore', 'could not open display') diff --git a/mopidy/__main__.py b/mopidy/__main__.py index de905d15..952f158c 100644 --- a/mopidy/__main__.py +++ b/mopidy/__main__.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import optparse import os @@ -62,7 +64,7 @@ def main(): except exceptions.SettingsError as ex: logger.error(ex.message) except KeyboardInterrupt: - logger.info(u'Interrupted. Exiting...') + logger.info('Interrupted. Exiting...') except Exception as ex: logger.exception(ex) finally: @@ -76,7 +78,7 @@ def main(): def parse_options(): parser = optparse.OptionParser( - version=u'Mopidy %s' % versioning.get_version()) + version='Mopidy %s' % versioning.get_version()) parser.add_option( '--help-gst', action='store_true', dest='help_gst', @@ -114,15 +116,15 @@ def parse_options(): def check_old_folders(): - old_settings_folder = os.path.expanduser(u'~/.mopidy') + old_settings_folder = os.path.expanduser('~/.mopidy') if not os.path.isdir(old_settings_folder): return logger.warning( - u'Old settings folder found at %s, settings.py should be moved ' - u'to %s, any cache data should be deleted. See release notes for ' - u'further instructions.', old_settings_folder, path.SETTINGS_PATH) + 'Old settings folder found at %s, settings.py should be moved ' + 'to %s, any cache data should be deleted. See release notes for ' + 'further instructions.', old_settings_folder, path.SETTINGS_PATH) def setup_settings(interactive): @@ -171,7 +173,7 @@ def setup_frontends(core): try: importing.get_class(frontend_class_name).start(core=core) except exceptions.OptionalDependencyError as ex: - logger.info(u'Disabled: %s (%s)', frontend_class_name, ex) + logger.info('Disabled: %s (%s)', frontend_class_name, ex) def stop_frontends(): diff --git a/mopidy/audio/__init__.py b/mopidy/audio/__init__.py index ba76bd84..c3fbc0c9 100644 --- a/mopidy/audio/__init__.py +++ b/mopidy/audio/__init__.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + # flake8: noqa from .actor import Audio from .listener import AudioListener diff --git a/mopidy/audio/actor.py b/mopidy/audio/actor.py index 852d5d57..633a9b00 100644 --- a/mopidy/audio/actor.py +++ b/mopidy/audio/actor.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import pygst pygst.require('0.10') import gst @@ -70,9 +72,9 @@ class Audio(pykka.ThreadingActor): # These caps matches the audio data provided by libspotify default_caps = gst.Caps( - 'audio/x-raw-int, endianness=(int)1234, channels=(int)2, ' - 'width=(int)16, depth=(int)16, signed=(boolean)true, ' - 'rate=(int)44100') + b'audio/x-raw-int, endianness=(int)1234, channels=(int)2, ' + b'width=(int)16, depth=(int)16, signed=(boolean)true, ' + b'rate=(int)44100') source = element.get_property('source') source.set_property('caps', default_caps) @@ -109,7 +111,7 @@ class Audio(pykka.ThreadingActor): return # We assume that the bin will contain a single mixer. - mixer = mixerbin.get_by_interface('GstMixer') + mixer = mixerbin.get_by_interface(b'GstMixer') if not mixer: logger.warning( 'Did not find any audio mixers in "%s"', settings.MIXER) @@ -162,14 +164,14 @@ class Audio(pykka.ThreadingActor): self._trigger_reached_end_of_stream_event() elif message.type == gst.MESSAGE_ERROR: error, debug = message.parse_error() - logger.error(u'%s %s', error, debug) + logger.error('%s %s', error, debug) self.stop_playback() elif message.type == gst.MESSAGE_WARNING: error, debug = message.parse_warning() - logger.warning(u'%s %s', error, debug) + logger.warning('%s %s', error, debug) def _trigger_reached_end_of_stream_event(self): - logger.debug(u'Triggering reached end of stream event') + logger.debug('Triggering reached end of stream event') AudioListener.send('reached_end_of_stream') def set_uri(self, uri): @@ -389,12 +391,12 @@ class Audio(pykka.ThreadingActor): # Default to blank data to trick shoutcast into clearing any previous # values it might have. - taglist[gst.TAG_ARTIST] = u' ' - taglist[gst.TAG_TITLE] = u' ' - taglist[gst.TAG_ALBUM] = u' ' + taglist[gst.TAG_ARTIST] = ' ' + taglist[gst.TAG_TITLE] = ' ' + taglist[gst.TAG_ALBUM] = ' ' if artists: - taglist[gst.TAG_ARTIST] = u', '.join([a.name for a in artists]) + taglist[gst.TAG_ARTIST] = ', '.join([a.name for a in artists]) if track.name: taglist[gst.TAG_TITLE] = track.name diff --git a/mopidy/audio/listener.py b/mopidy/audio/listener.py index 54fe058d..42c85e1e 100644 --- a/mopidy/audio/listener.py +++ b/mopidy/audio/listener.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import pykka diff --git a/mopidy/audio/mixers/__init__.py b/mopidy/audio/mixers/__init__.py index 034b0fa9..feaccc3d 100644 --- a/mopidy/audio/mixers/__init__.py +++ b/mopidy/audio/mixers/__init__.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import pygst pygst.require('0.10') import gst diff --git a/mopidy/audio/mixers/auto.py b/mopidy/audio/mixers/auto.py index 05294801..bd61445e 100644 --- a/mopidy/audio/mixers/auto.py +++ b/mopidy/audio/mixers/auto.py @@ -12,6 +12,8 @@ This is Mopidy's default mixer. to ``autoaudiomixer`` to use this mixer. """ +from __future__ import unicode_literals + import pygst pygst.require('0.10') import gst diff --git a/mopidy/audio/mixers/fake.py b/mopidy/audio/mixers/fake.py index 10710466..948ab82e 100644 --- a/mopidy/audio/mixers/fake.py +++ b/mopidy/audio/mixers/fake.py @@ -9,6 +9,8 @@ - Set :attr:`mopidy.settings.MIXER` to ``fakemixer`` to use this mixer. """ +from __future__ import unicode_literals + import pygst pygst.require('0.10') import gobject diff --git a/mopidy/audio/mixers/nad.py b/mopidy/audio/mixers/nad.py index 1a807e39..b5cb522d 100644 --- a/mopidy/audio/mixers/nad.py +++ b/mopidy/audio/mixers/nad.py @@ -45,6 +45,8 @@ Configuration examples:: u'source=aux speakers-a=on speakers-b=off') """ +from __future__ import unicode_literals + import logging import pygst @@ -107,7 +109,7 @@ class NadMixer(gst.Element, gst.ImplementsInterface, gst.interfaces.Mixer): def do_change_state(self, transition): if transition == gst.STATE_CHANGE_NULL_TO_READY: if serial is None: - logger.warning(u'nadmixer dependency python-serial not found') + logger.warning('nadmixer dependency python-serial not found') return gst.STATE_CHANGE_FAILURE self._start_nad_talker() return gst.STATE_CHANGE_SUCCESS @@ -164,7 +166,7 @@ class NadTalker(pykka.ThreadingActor): self._set_device_to_known_state() def _open_connection(self): - logger.info(u'NAD amplifier: Connecting through "%s"', self.port) + logger.info('NAD amplifier: Connecting through "%s"', self.port) self._device = serial.Serial( port=self.port, baudrate=self.BAUDRATE, @@ -183,7 +185,7 @@ class NadTalker(pykka.ThreadingActor): def _get_device_model(self): model = self._ask_device('Main.Model') - logger.info(u'NAD amplifier: Connected to model "%s"', model) + logger.info('NAD amplifier: Connected to model "%s"', model) return model def _power_device_on(self): @@ -212,19 +214,19 @@ class NadTalker(pykka.ThreadingActor): if current_nad_volume is None: current_nad_volume = self.VOLUME_LEVELS if current_nad_volume == self.VOLUME_LEVELS: - logger.info(u'NAD amplifier: Calibrating by setting volume to 0') + logger.info('NAD amplifier: Calibrating by setting volume to 0') self._nad_volume = current_nad_volume if self._decrease_volume(): current_nad_volume -= 1 if current_nad_volume == 0: - logger.info(u'NAD amplifier: Done calibrating') + logger.info('NAD amplifier: Done calibrating') else: self.actor_ref.proxy().calibrate_volume(current_nad_volume) def set_volume(self, volume): # Increase or decrease the amplifier volume until it matches the given # target volume. - logger.debug(u'Setting volume to %d' % volume) + logger.debug('Setting volume to %d' % volume) target_nad_volume = int(round(volume * self.VOLUME_LEVELS / 100.0)) if self._nad_volume is None: return # Calibration needed @@ -250,12 +252,12 @@ class NadTalker(pykka.ThreadingActor): if self._ask_device(key) == value: return logger.info( - u'NAD amplifier: Setting "%s" to "%s" (attempt %d/3)', + 'NAD amplifier: Setting "%s" to "%s" (attempt %d/3)', key, value, attempt) self._command_device(key, value) if self._ask_device(key) != value: logger.info( - u'NAD amplifier: Gave up on setting "%s" to "%s"', + 'NAD amplifier: Gave up on setting "%s" to "%s"', key, value) def _ask_device(self, key): diff --git a/mopidy/audio/mixers/utils.py b/mopidy/audio/mixers/utils.py index c257ffd7..8d0ce280 100644 --- a/mopidy/audio/mixers/utils.py +++ b/mopidy/audio/mixers/utils.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import pygst pygst.require('0.10') import gst diff --git a/mopidy/backends/__init__.py b/mopidy/backends/__init__.py index e69de29b..baffc488 100644 --- a/mopidy/backends/__init__.py +++ b/mopidy/backends/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/mopidy/backends/base.py b/mopidy/backends/base.py index de33e6e5..386d19b4 100644 --- a/mopidy/backends/base.py +++ b/mopidy/backends/base.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import copy diff --git a/mopidy/backends/dummy.py b/mopidy/backends/dummy.py index 51129200..34a176e5 100644 --- a/mopidy/backends/dummy.py +++ b/mopidy/backends/dummy.py @@ -14,6 +14,8 @@ The backend handles URIs starting with ``dummy:``. - None """ +from __future__ import unicode_literals + import pykka from mopidy.backends import base @@ -28,7 +30,7 @@ class DummyBackend(pykka.ThreadingActor, base.Backend): self.playback = DummyPlaybackProvider(audio=audio, backend=self) self.stored_playlists = DummyStoredPlaylistsProvider(backend=self) - self.uri_schemes = [u'dummy'] + self.uri_schemes = ['dummy'] class DummyLibraryProvider(base.BaseLibraryProvider): diff --git a/mopidy/backends/local/__init__.py b/mopidy/backends/local/__init__.py index 6f049474..8ee58d3b 100644 --- a/mopidy/backends/local/__init__.py +++ b/mopidy/backends/local/__init__.py @@ -20,5 +20,7 @@ https://github.com/mopidy/mopidy/issues?labels=Local+backend - :attr:`mopidy.settings.LOCAL_TAG_CACHE_FILE` """ +from __future__ import unicode_literals + # flake8: noqa from .actor import LocalBackend diff --git a/mopidy/backends/local/actor.py b/mopidy/backends/local/actor.py index 70351ed1..fb287468 100644 --- a/mopidy/backends/local/actor.py +++ b/mopidy/backends/local/actor.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import pykka @@ -7,7 +9,7 @@ from mopidy.backends import base from .library import LocalLibraryProvider from .stored_playlists import LocalStoredPlaylistsProvider -logger = logging.getLogger(u'mopidy.backends.local') +logger = logging.getLogger('mopidy.backends.local') class LocalBackend(pykka.ThreadingActor, base.Backend): @@ -18,4 +20,4 @@ class LocalBackend(pykka.ThreadingActor, base.Backend): self.playback = base.BasePlaybackProvider(audio=audio, backend=self) self.stored_playlists = LocalStoredPlaylistsProvider(backend=self) - self.uri_schemes = [u'file'] + self.uri_schemes = ['file'] diff --git a/mopidy/backends/local/library.py b/mopidy/backends/local/library.py index 9abdf7ed..9232225a 100644 --- a/mopidy/backends/local/library.py +++ b/mopidy/backends/local/library.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging from mopidy import settings @@ -6,7 +8,7 @@ from mopidy.models import Playlist, Album from .translator import parse_mpd_tag_cache -logger = logging.getLogger(u'mopidy.backends.local') +logger = logging.getLogger('mopidy.backends.local') class LocalLibraryProvider(base.BaseLibraryProvider): @@ -30,7 +32,7 @@ class LocalLibraryProvider(base.BaseLibraryProvider): try: return self._uri_mapping[uri] except KeyError: - logger.debug(u'Failed to lookup %r', uri) + logger.debug('Failed to lookup %r', uri) return None def find_exact(self, **query): diff --git a/mopidy/backends/local/stored_playlists.py b/mopidy/backends/local/stored_playlists.py index 04406c32..f521fc2e 100644 --- a/mopidy/backends/local/stored_playlists.py +++ b/mopidy/backends/local/stored_playlists.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import glob import logging import os @@ -11,7 +13,7 @@ from mopidy.utils import formatting, path from .translator import parse_m3u -logger = logging.getLogger(u'mopidy.backends.local') +logger = logging.getLogger('mopidy.backends.local') class LocalStoredPlaylistsProvider(base.BaseStoredPlaylistsProvider): diff --git a/mopidy/backends/local/translator.py b/mopidy/backends/local/translator.py index 01aad440..21e389ea 100644 --- a/mopidy/backends/local/translator.py +++ b/mopidy/backends/local/translator.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging from mopidy.models import Track, Artist, Album @@ -68,19 +70,19 @@ def parse_mpd_tag_cache(tag_cache, music_dir=''): current = {} state = None - for line in contents.split('\n'): - if line == 'songList begin': + for line in contents.split(b'\n'): + if line == b'songList begin': state = 'songs' continue - elif line == 'songList end': + elif line == b'songList end': state = None continue elif not state: continue - key, value = line.split(': ', 1) + key, value = line.split(b': ', 1) - if key == 'key': + if key == b'key': _convert_mpd_data(current, tracks, music_dir) current.clear() diff --git a/mopidy/backends/spotify/__init__.py b/mopidy/backends/spotify/__init__.py index 28813bc2..fa6feb99 100644 --- a/mopidy/backends/spotify/__init__.py +++ b/mopidy/backends/spotify/__init__.py @@ -30,5 +30,7 @@ https://github.com/mopidy/mopidy/issues?labels=Spotify+backend - :attr:`mopidy.settings.SPOTIFY_PASSWORD` """ +from __future__ import unicode_literals + # flake8: noqa from .actor import SpotifyBackend diff --git a/mopidy/backends/spotify/actor.py b/mopidy/backends/spotify/actor.py index 943600fc..a5b23071 100644 --- a/mopidy/backends/spotify/actor.py +++ b/mopidy/backends/spotify/actor.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import pykka @@ -24,7 +26,7 @@ class SpotifyBackend(pykka.ThreadingActor, base.Backend): self.playback = SpotifyPlaybackProvider(audio=audio, backend=self) self.stored_playlists = SpotifyStoredPlaylistsProvider(backend=self) - self.uri_schemes = [u'spotify'] + self.uri_schemes = ['spotify'] # Fail early if settings are not present username = settings.SPOTIFY_USERNAME @@ -34,8 +36,8 @@ class SpotifyBackend(pykka.ThreadingActor, base.Backend): username, password, audio=audio, backend_ref=self.actor_ref) def on_start(self): - logger.info(u'Mopidy uses SPOTIFY(R) CORE') - logger.debug(u'Connecting to Spotify') + logger.info('Mopidy uses SPOTIFY(R) CORE') + logger.debug('Connecting to Spotify') self.spotify.start() def on_stop(self): diff --git a/mopidy/backends/spotify/container_manager.py b/mopidy/backends/spotify/container_manager.py index e3388e0b..dc498a02 100644 --- a/mopidy/backends/spotify/container_manager.py +++ b/mopidy/backends/spotify/container_manager.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging from spotify.manager import SpotifyContainerManager as \ @@ -13,7 +15,7 @@ class SpotifyContainerManager(PyspotifyContainerManager): def container_loaded(self, container, userdata): """Callback used by pyspotify""" - logger.debug(u'Callback called: playlist container loaded') + logger.debug('Callback called: playlist container loaded') self.session_manager.refresh_stored_playlists() @@ -22,12 +24,12 @@ class SpotifyContainerManager(PyspotifyContainerManager): if playlist.type() == 'playlist': self.session_manager.playlist_manager.watch(playlist) count += 1 - logger.debug(u'Watching %d playlist(s) for changes', count) + logger.debug('Watching %d playlist(s) for changes', count) def playlist_added(self, container, playlist, position, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: playlist added at position %d', position) + 'Callback called: playlist added at position %d', position) # container_loaded() is called after this callback, so we do not need # to handle this callback. @@ -35,7 +37,7 @@ class SpotifyContainerManager(PyspotifyContainerManager): userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: playlist "%s" moved from position %d to %d', + 'Callback called: playlist "%s" moved from position %d to %d', playlist.name(), old_position, new_position) # container_loaded() is called after this callback, so we do not need # to handle this callback. @@ -43,7 +45,7 @@ class SpotifyContainerManager(PyspotifyContainerManager): def playlist_removed(self, container, playlist, position, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: playlist "%s" removed from position %d', + 'Callback called: playlist "%s" removed from position %d', playlist.name(), position) # container_loaded() is called after this callback, so we do not need # to handle this callback. diff --git a/mopidy/backends/spotify/library.py b/mopidy/backends/spotify/library.py index bf057bee..18900d28 100644 --- a/mopidy/backends/spotify/library.py +++ b/mopidy/backends/spotify/library.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import Queue @@ -16,7 +18,7 @@ class SpotifyTrack(Track): def __init__(self, uri): super(SpotifyTrack, self).__init__() self._spotify_track = Link.from_string(uri).as_track() - self._unloaded_track = Track(uri=uri, name=u'[loading...]') + self._unloaded_track = Track(uri=uri, name='[loading...]') self._track = None @property @@ -57,7 +59,7 @@ class SpotifyLibraryProvider(base.BaseLibraryProvider): try: return SpotifyTrack(uri) except SpotifyError as e: - logger.debug(u'Failed to lookup "%s": %s', uri, e) + logger.debug('Failed to lookup "%s": %s', uri, e) return None def refresh(self, uri=None): @@ -73,22 +75,22 @@ class SpotifyLibraryProvider(base.BaseLibraryProvider): return Playlist(tracks=tracks) spotify_query = [] for (field, values) in query.iteritems(): - if field == u'track': - field = u'title' - if field == u'date': - field = u'year' + if field == 'track': + field = 'title' + if field == 'date': + field = 'year' if not hasattr(values, '__iter__'): values = [values] for value in values: - if field == u'any': + if field == 'any': spotify_query.append(value) - elif field == u'year': + elif field == 'year': value = int(value.split('-')[0]) # Extract year - spotify_query.append(u'%s:%d' % (field, value)) + spotify_query.append('%s:%d' % (field, value)) else: - spotify_query.append(u'%s:"%s"' % (field, value)) - spotify_query = u' '.join(spotify_query) - logger.debug(u'Spotify search query: %s' % spotify_query) + spotify_query.append('%s:"%s"' % (field, value)) + spotify_query = ' '.join(spotify_query) + logger.debug('Spotify search query: %s' % spotify_query) queue = Queue.Queue() self.backend.spotify.search(spotify_query, queue) try: diff --git a/mopidy/backends/spotify/playback.py b/mopidy/backends/spotify/playback.py index 40868745..de82464a 100644 --- a/mopidy/backends/spotify/playback.py +++ b/mopidy/backends/spotify/playback.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import time diff --git a/mopidy/backends/spotify/playlist_manager.py b/mopidy/backends/spotify/playlist_manager.py index 645a574c..a3deff7e 100644 --- a/mopidy/backends/spotify/playlist_manager.py +++ b/mopidy/backends/spotify/playlist_manager.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import datetime import logging @@ -14,90 +16,90 @@ class SpotifyPlaylistManager(PyspotifyPlaylistManager): def tracks_added(self, playlist, tracks, position, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: ' - u'%d track(s) added to position %d in playlist "%s"', + 'Callback called: ' + '%d track(s) added to position %d in playlist "%s"', len(tracks), position, playlist.name()) self.session_manager.refresh_stored_playlists() def tracks_moved(self, playlist, tracks, new_position, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: ' - u'%d track(s) moved to position %d in playlist "%s"', + 'Callback called: ' + '%d track(s) moved to position %d in playlist "%s"', len(tracks), new_position, playlist.name()) self.session_manager.refresh_stored_playlists() def tracks_removed(self, playlist, tracks, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: ' - u'%d track(s) removed from playlist "%s"', + 'Callback called: ' + '%d track(s) removed from playlist "%s"', len(tracks), playlist.name()) self.session_manager.refresh_stored_playlists() def playlist_renamed(self, playlist, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: Playlist renamed to "%s"', playlist.name()) + 'Callback called: Playlist renamed to "%s"', playlist.name()) self.session_manager.refresh_stored_playlists() def playlist_state_changed(self, playlist, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: The state of playlist "%s" changed', + 'Callback called: The state of playlist "%s" changed', playlist.name()) def playlist_update_in_progress(self, playlist, done, userdata): """Callback used by pyspotify""" if done: logger.debug( - u'Callback called: Update of playlist "%s" done', + 'Callback called: Update of playlist "%s" done', playlist.name()) else: logger.debug( - u'Callback called: Update of playlist "%s" in progress', + 'Callback called: Update of playlist "%s" in progress', playlist.name()) def playlist_metadata_updated(self, playlist, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: Metadata updated for playlist "%s"', + 'Callback called: Metadata updated for playlist "%s"', playlist.name()) def track_created_changed(self, playlist, position, user, when, userdata): """Callback used by pyspotify""" when = datetime.datetime.fromtimestamp(when) logger.debug( - u'Callback called: Created by/when for track %d in playlist ' - u'"%s" changed to user "N/A" and time "%s"', + 'Callback called: Created by/when for track %d in playlist ' + '"%s" changed to user "N/A" and time "%s"', position, playlist.name(), when) def track_message_changed(self, playlist, position, message, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: Message for track %d in playlist ' - u'"%s" changed to "%s"', position, playlist.name(), message) + 'Callback called: Message for track %d in playlist ' + '"%s" changed to "%s"', position, playlist.name(), message) def track_seen_changed(self, playlist, position, seen, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: Seen attribute for track %d in playlist ' - u'"%s" changed to "%s"', position, playlist.name(), seen) + 'Callback called: Seen attribute for track %d in playlist ' + '"%s" changed to "%s"', position, playlist.name(), seen) def description_changed(self, playlist, description, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: Description changed for playlist "%s" to "%s"', + 'Callback called: Description changed for playlist "%s" to "%s"', playlist.name(), description) def subscribers_changed(self, playlist, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: Subscribers changed for playlist "%s"', + 'Callback called: Subscribers changed for playlist "%s"', playlist.name()) def image_changed(self, playlist, image, userdata): """Callback used by pyspotify""" logger.debug( - u'Callback called: Image changed for playlist "%s"', + 'Callback called: Image changed for playlist "%s"', playlist.name()) diff --git a/mopidy/backends/spotify/session_manager.py b/mopidy/backends/spotify/session_manager.py index 23b99d48..62eecde3 100644 --- a/mopidy/backends/spotify/session_manager.py +++ b/mopidy/backends/spotify/session_manager.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import os import threading @@ -50,14 +52,14 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager): def logged_in(self, session, error): """Callback used by pyspotify""" if error: - logger.error(u'Spotify login error: %s', error) + logger.error('Spotify login error: %s', error) return - logger.info(u'Connected to Spotify') + logger.info('Connected to Spotify') self.session = session logger.debug( - u'Preferred Spotify bitrate is %s kbps', + 'Preferred Spotify bitrate is %s kbps', settings.SPOTIFY_BITRATE) self.session.set_preferred_bitrate(BITRATES[settings.SPOTIFY_BITRATE]) @@ -70,30 +72,30 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager): def logged_out(self, session): """Callback used by pyspotify""" - logger.info(u'Disconnected from Spotify') + logger.info('Disconnected from Spotify') def metadata_updated(self, session): """Callback used by pyspotify""" - logger.debug(u'Callback called: Metadata updated') + logger.debug('Callback called: Metadata updated') def connection_error(self, session, error): """Callback used by pyspotify""" if error is None: - logger.info(u'Spotify connection OK') + logger.info('Spotify connection OK') else: - logger.error(u'Spotify connection error: %s', error) + logger.error('Spotify connection error: %s', error) self.backend.playback.pause() def message_to_user(self, session, message): """Callback used by pyspotify""" - logger.debug(u'User message: %s', message.strip()) + logger.debug('User message: %s', message.strip()) def music_delivery(self, session, frames, frame_size, num_frames, sample_type, sample_rate, channels): """Callback used by pyspotify""" # pylint: disable = R0913 # Too many arguments (8/5) - assert sample_type == 0, u'Expects 16-bit signed integer samples' + assert sample_type == 0, 'Expects 16-bit signed integer samples' capabilites = """ audio/x-raw-int, endianness=(int)1234, @@ -111,12 +113,12 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager): def play_token_lost(self, session): """Callback used by pyspotify""" - logger.debug(u'Play token lost') + logger.debug('Play token lost') self.backend.playback.pause() def log_message(self, session, data): """Callback used by pyspotify""" - logger.debug(u'System message: %s' % data.strip()) + logger.debug('System message: %s' % data.strip()) if 'offline-mgr' in data and 'files unlocked' in data: # XXX This is a very very fragile and ugly hack, but we get no # proper event when libspotify is done with initial data loading. @@ -131,20 +133,20 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager): def end_of_track(self, session): """Callback used by pyspotify""" - logger.debug(u'End of data stream reached') + logger.debug('End of data stream reached') self.audio.emit_end_of_stream() def refresh_stored_playlists(self): """Refresh the stored playlists in the backend with fresh meta data from Spotify""" if not self._initial_data_receive_completed: - logger.debug(u'Still getting data; skipped refresh of playlists') + logger.debug('Still getting data; skipped refresh of playlists') return playlists = map( translator.to_mopidy_playlist, self.session.playlist_container()) playlists = filter(None, playlists) self.backend.stored_playlists.playlists = playlists - logger.info(u'Loaded %d Spotify playlist(s)', len(playlists)) + logger.info('Loaded %d Spotify playlist(s)', len(playlists)) def search(self, query, queue): """Search method used by Mopidy backend""" @@ -161,6 +163,6 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager): def logout(self): """Log out from spotify""" - logger.debug(u'Logging out from Spotify') + logger.debug('Logging out from Spotify') if self.session: self.session.logout() diff --git a/mopidy/backends/spotify/stored_playlists.py b/mopidy/backends/spotify/stored_playlists.py index cb068f63..559ffd99 100644 --- a/mopidy/backends/spotify/stored_playlists.py +++ b/mopidy/backends/spotify/stored_playlists.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.backends import base diff --git a/mopidy/backends/spotify/translator.py b/mopidy/backends/spotify/translator.py index 4ad92fe9..834b34d8 100644 --- a/mopidy/backends/spotify/translator.py +++ b/mopidy/backends/spotify/translator.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from spotify import Link from mopidy import settings @@ -9,7 +11,7 @@ def to_mopidy_artist(spotify_artist): return uri = str(Link.from_artist(spotify_artist)) if not spotify_artist.is_loaded(): - return Artist(uri=uri, name=u'[loading...]') + return Artist(uri=uri, name='[loading...]') return Artist(uri=uri, name=spotify_artist.name()) @@ -18,7 +20,7 @@ def to_mopidy_album(spotify_album): return uri = str(Link.from_album(spotify_album)) if not spotify_album.is_loaded(): - return Album(uri=uri, name=u'[loading...]') + return Album(uri=uri, name='[loading...]') return Album( uri=uri, name=spotify_album.name(), @@ -31,7 +33,7 @@ def to_mopidy_track(spotify_track): return uri = str(Link.from_track(spotify_track, 0)) if not spotify_track.is_loaded(): - return Track(uri=uri, name=u'[loading...]') + return Track(uri=uri, name='[loading...]') spotify_album = spotify_track.album() if spotify_album is not None and spotify_album.is_loaded(): date = spotify_album.year() @@ -53,7 +55,7 @@ def to_mopidy_playlist(spotify_playlist): return uri = str(Link.from_playlist(spotify_playlist)) if not spotify_playlist.is_loaded(): - return Playlist(uri=uri, name=u'[loading...]') + return Playlist(uri=uri, name='[loading...]') return Playlist( uri=uri, name=spotify_playlist.name(), diff --git a/mopidy/core/__init__.py b/mopidy/core/__init__.py index 7fecfd79..c8648766 100644 --- a/mopidy/core/__init__.py +++ b/mopidy/core/__init__.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + # flake8: noqa from .actor import Core from .current_playlist import CurrentPlaylistController diff --git a/mopidy/core/actor.py b/mopidy/core/actor.py index 482868ad..7ced97ed 100644 --- a/mopidy/core/actor.py +++ b/mopidy/core/actor.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import itertools import pykka diff --git a/mopidy/core/current_playlist.py b/mopidy/core/current_playlist.py index fb296a52..bd4f7b46 100644 --- a/mopidy/core/current_playlist.py +++ b/mopidy/core/current_playlist.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from copy import copy import logging import random @@ -73,7 +75,7 @@ class CurrentPlaylistController(object): was added to the current playlist playlist """ assert at_position <= len(self._cp_tracks), \ - u'at_position can not be greater than playlist length' + 'at_position can not be greater than playlist length' cp_track = CpTrack(self.cp_id, track) if at_position is not None: self._cp_tracks.insert(at_position, cp_track) @@ -132,9 +134,9 @@ class CurrentPlaylistController(object): criteria_string = ', '.join( ['%s=%s' % (k, v) for (k, v) in criteria.iteritems()]) if len(matches) == 0: - raise LookupError(u'"%s" match no tracks' % criteria_string) + raise LookupError('"%s" match no tracks' % criteria_string) else: - raise LookupError(u'"%s" match multiple tracks' % criteria_string) + raise LookupError('"%s" match multiple tracks' % criteria_string) def index(self, cp_track): """ @@ -237,5 +239,5 @@ class CurrentPlaylistController(object): return [copy(cp_track) for cp_track in self._cp_tracks[start:end]] def _trigger_playlist_changed(self): - logger.debug(u'Triggering playlist changed event') + logger.debug('Triggering playlist changed event') listener.CoreListener.send('playlist_changed') diff --git a/mopidy/core/library.py b/mopidy/core/library.py index f7514fd8..801ed983 100644 --- a/mopidy/core/library.py +++ b/mopidy/core/library.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import itertools import urlparse diff --git a/mopidy/core/listener.py b/mopidy/core/listener.py index ed7dae2f..9c8bf4bc 100644 --- a/mopidy/core/listener.py +++ b/mopidy/core/listener.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import pykka diff --git a/mopidy/core/playback.py b/mopidy/core/playback.py index 74f4bebd..4d8c8699 100644 --- a/mopidy/core/playback.py +++ b/mopidy/core/playback.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import random import urlparse @@ -28,13 +30,13 @@ class PlaybackState(object): """ #: Constant representing the paused state. - PAUSED = u'paused' + PAUSED = 'paused' #: Constant representing the playing state. - PLAYING = u'playing' + PLAYING = 'playing' #: Constant representing the stopped state. - STOPPED = u'stopped' + STOPPED = 'stopped' class PlaybackController(object): @@ -290,7 +292,7 @@ class PlaybackController(object): @state.setter # noqa def state(self, new_state): (old_state, self._state) = (self.state, new_state) - logger.debug(u'Changing state: %s -> %s', old_state, new_state) + logger.debug('Changing state: %s -> %s', old_state, new_state) self._trigger_playback_state_changed(old_state, new_state) @@ -493,7 +495,7 @@ class PlaybackController(object): self.current_cp_track = None def _trigger_track_playback_paused(self): - logger.debug(u'Triggering track playback paused event') + logger.debug('Triggering track playback paused event') if self.current_track is None: return listener.CoreListener.send( @@ -501,7 +503,7 @@ class PlaybackController(object): track=self.current_track, time_position=self.time_position) def _trigger_track_playback_resumed(self): - logger.debug(u'Triggering track playback resumed event') + logger.debug('Triggering track playback resumed event') if self.current_track is None: return listener.CoreListener.send( @@ -509,14 +511,14 @@ class PlaybackController(object): track=self.current_track, time_position=self.time_position) def _trigger_track_playback_started(self): - logger.debug(u'Triggering track playback started event') + logger.debug('Triggering track playback started event') if self.current_track is None: return listener.CoreListener.send( 'track_playback_started', track=self.current_track) def _trigger_track_playback_ended(self): - logger.debug(u'Triggering track playback ended event') + logger.debug('Triggering track playback ended event') if self.current_track is None: return listener.CoreListener.send( @@ -524,15 +526,15 @@ class PlaybackController(object): track=self.current_track, time_position=self.time_position) def _trigger_playback_state_changed(self, old_state, new_state): - logger.debug(u'Triggering playback state change event') + logger.debug('Triggering playback state change event') listener.CoreListener.send( 'playback_state_changed', old_state=old_state, new_state=new_state) def _trigger_options_changed(self): - logger.debug(u'Triggering options changed event') + logger.debug('Triggering options changed event') listener.CoreListener.send('options_changed') def _trigger_seeked(self, time_position): - logger.debug(u'Triggering seeked event') + logger.debug('Triggering seeked event') listener.CoreListener.send('seeked', time_position=time_position) diff --git a/mopidy/core/stored_playlists.py b/mopidy/core/stored_playlists.py index 8c04d5ad..2c5d2c54 100644 --- a/mopidy/core/stored_playlists.py +++ b/mopidy/core/stored_playlists.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import itertools import urlparse diff --git a/mopidy/exceptions.py b/mopidy/exceptions.py index 6e0c575e..b8d183fb 100644 --- a/mopidy/exceptions.py +++ b/mopidy/exceptions.py @@ -1,3 +1,6 @@ +from __future__ import unicode_literals + + class MopidyException(Exception): def __init__(self, message, *args, **kwargs): super(MopidyException, self).__init__(message, *args, **kwargs) diff --git a/mopidy/frontends/__init__.py b/mopidy/frontends/__init__.py index e69de29b..baffc488 100644 --- a/mopidy/frontends/__init__.py +++ b/mopidy/frontends/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/mopidy/frontends/lastfm.py b/mopidy/frontends/lastfm.py index aaf55ec1..7f367262 100644 --- a/mopidy/frontends/lastfm.py +++ b/mopidy/frontends/lastfm.py @@ -22,6 +22,8 @@ Make sure :attr:`mopidy.settings.FRONTENDS` includes the Last.fm frontend. """ +from __future__ import unicode_literals + import logging import time @@ -54,21 +56,21 @@ class LastfmFrontend(pykka.ThreadingActor, CoreListener): self.lastfm = pylast.LastFMNetwork( api_key=API_KEY, api_secret=API_SECRET, username=username, password_hash=password_hash) - logger.info(u'Connected to Last.fm') + logger.info('Connected to Last.fm') except exceptions.SettingsError as e: - logger.info(u'Last.fm scrobbler not started') - logger.debug(u'Last.fm settings error: %s', e) + logger.info('Last.fm scrobbler not started') + logger.debug('Last.fm settings error: %s', e) self.stop() except (pylast.NetworkError, pylast.MalformedResponseError, pylast.WSError) as e: - logger.error(u'Error during Last.fm setup: %s', e) + logger.error('Error during Last.fm setup: %s', e) self.stop() def track_playback_started(self, track): artists = ', '.join([a.name for a in track.artists]) duration = track.length and track.length // 1000 or 0 self.last_start_time = int(time.time()) - logger.debug(u'Now playing track: %s - %s', artists, track.name) + logger.debug('Now playing track: %s - %s', artists, track.name) try: self.lastfm.update_now_playing( artists, @@ -79,22 +81,22 @@ class LastfmFrontend(pykka.ThreadingActor, CoreListener): mbid=(track.musicbrainz_id or '')) except (pylast.ScrobblingError, pylast.NetworkError, pylast.MalformedResponseError, pylast.WSError) as e: - logger.warning(u'Error submitting playing track to Last.fm: %s', e) + logger.warning('Error submitting playing track to Last.fm: %s', e) def track_playback_ended(self, track, time_position): artists = ', '.join([a.name for a in track.artists]) duration = track.length and track.length // 1000 or 0 time_position = time_position // 1000 if duration < 30: - logger.debug(u'Track too short to scrobble. (30s)') + logger.debug('Track too short to scrobble. (30s)') return if time_position < duration // 2 and time_position < 240: logger.debug( - u'Track not played long enough to scrobble. (50% or 240s)') + 'Track not played long enough to scrobble. (50% or 240s)') return if self.last_start_time is None: self.last_start_time = int(time.time()) - duration - logger.debug(u'Scrobbling track: %s - %s', artists, track.name) + logger.debug('Scrobbling track: %s - %s', artists, track.name) try: self.lastfm.scrobble( artists, @@ -106,4 +108,4 @@ class LastfmFrontend(pykka.ThreadingActor, CoreListener): mbid=(track.musicbrainz_id or '')) except (pylast.ScrobblingError, pylast.NetworkError, pylast.MalformedResponseError, pylast.WSError) as e: - logger.warning(u'Error submitting played track to Last.fm: %s', e) + logger.warning('Error submitting played track to Last.fm: %s', e) diff --git a/mopidy/frontends/mpd/__init__.py b/mopidy/frontends/mpd/__init__.py index a6cfd386..572192ef 100644 --- a/mopidy/frontends/mpd/__init__.py +++ b/mopidy/frontends/mpd/__init__.py @@ -21,5 +21,7 @@ Make sure :attr:`mopidy.settings.FRONTENDS` includes frontend. """ +from __future__ import unicode_literals + # flake8: noqa from .actor import MpdFrontend diff --git a/mopidy/frontends/mpd/actor.py b/mopidy/frontends/mpd/actor.py index e136ddee..3ba6378c 100644 --- a/mopidy/frontends/mpd/actor.py +++ b/mopidy/frontends/mpd/actor.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import sys @@ -24,11 +26,11 @@ class MpdFrontend(pykka.ThreadingActor, CoreListener): max_connections=settings.MPD_SERVER_MAX_CONNECTIONS) except IOError as error: logger.error( - u'MPD server startup failed: %s', + 'MPD server startup failed: %s', encoding.locale_decode(error)) sys.exit(1) - logger.info(u'MPD server running at [%s]:%s', hostname, port) + logger.info('MPD server running at [%s]:%s', hostname, port) def on_stop(self): process.stop_actors_by_class(session.MpdSession) diff --git a/mopidy/frontends/mpd/dispatcher.py b/mopidy/frontends/mpd/dispatcher.py index 148fe443..4f0001ac 100644 --- a/mopidy/frontends/mpd/dispatcher.py +++ b/mopidy/frontends/mpd/dispatcher.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import re @@ -52,8 +54,8 @@ class MpdDispatcher(object): response = [] for subsystem in subsystems: - response.append(u'changed: %s' % subsystem) - response.append(u'OK') + response.append('changed: %s' % subsystem) + response.append('OK') self.context.subscriptions = set() self.context.events = set() self.context.session.send_lines(response) @@ -103,26 +105,26 @@ class MpdDispatcher(object): response = self._call_next_filter(request, response, filter_chain) if (self._is_receiving_command_list(request) or self._is_processing_command_list(request)): - if response and response[-1] == u'OK': + if response and response[-1] == 'OK': response = response[:-1] return response def _is_receiving_command_list(self, request): return ( - self.command_list_receiving and request != u'command_list_end') + self.command_list_receiving and request != 'command_list_end') def _is_processing_command_list(self, request): return ( self.command_list_index is not None and - request != u'command_list_end') + request != 'command_list_end') ### Filter: idle def _idle_filter(self, request, response, filter_chain): if self._is_currently_idle() and not self._noidle.match(request): logger.debug( - u'Client sent us %s, only %s is allowed while in ' - u'the idle state', repr(request), repr(u'noidle')) + 'Client sent us %s, only %s is allowed while in ' + 'the idle state', repr(request), repr('noidle')) self.context.session.close() return [] @@ -144,11 +146,11 @@ class MpdDispatcher(object): def _add_ok_filter(self, request, response, filter_chain): response = self._call_next_filter(request, response, filter_chain) if not self._has_error(response): - response.append(u'OK') + response.append('OK') return response def _has_error(self, response): - return response and response[-1].startswith(u'ACK') + return response and response[-1].startswith('ACK') ### Filter: call handler @@ -157,7 +159,7 @@ class MpdDispatcher(object): response = self._format_response(self._call_handler(request)) return self._call_next_filter(request, response, filter_chain) except pykka.ActorDeadError as e: - logger.warning(u'Tried to communicate with dead actor.') + logger.warning('Tried to communicate with dead actor.') raise exceptions.MpdSystemError(e) def _call_handler(self, request): @@ -173,7 +175,7 @@ class MpdDispatcher(object): command_name = request.split(' ')[0] if command_name in [command.name for command in protocol.mpd_commands]: raise exceptions.MpdArgError( - u'incorrect arguments', command=command_name) + 'incorrect arguments', command=command_name) raise exceptions.MpdUnknownCommand(command=command_name) def _format_response(self, response): @@ -202,10 +204,10 @@ class MpdDispatcher(object): def _format_lines(self, line): if isinstance(line, dict): - return [u'%s: %s' % (key, value) for (key, value) in line.items()] + return ['%s: %s' % (key, value) for (key, value) in line.items()] if isinstance(line, tuple): (key, value) = line - return [u'%s: %s' % (key, value)] + return ['%s: %s' % (key, value)] return [line] diff --git a/mopidy/frontends/mpd/exceptions.py b/mopidy/frontends/mpd/exceptions.py index 5925d6bc..db3212d8 100644 --- a/mopidy/frontends/mpd/exceptions.py +++ b/mopidy/frontends/mpd/exceptions.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.exceptions import MopidyException @@ -19,7 +21,7 @@ class MpdAckError(MopidyException): error_code = 0 - def __init__(self, message=u'', index=0, command=u''): + def __init__(self, message='', index=0, command=''): super(MpdAckError, self).__init__(message, index, command) self.message = message self.index = index @@ -31,7 +33,7 @@ class MpdAckError(MopidyException): ACK [%(error_code)i@%(index)i] {%(command)s} description """ - return u'ACK [%i@%i] {%s} %s' % ( + return 'ACK [%i@%i] {%s} %s' % ( self.__class__.error_code, self.index, self.command, self.message) @@ -48,7 +50,7 @@ class MpdPermissionError(MpdAckError): def __init__(self, *args, **kwargs): super(MpdPermissionError, self).__init__(*args, **kwargs) - self.message = u'you don\'t have permission for "%s"' % self.command + self.message = 'you don\'t have permission for "%s"' % self.command class MpdUnknownCommand(MpdAckError): @@ -56,8 +58,8 @@ class MpdUnknownCommand(MpdAckError): def __init__(self, *args, **kwargs): super(MpdUnknownCommand, self).__init__(*args, **kwargs) - self.message = u'unknown command "%s"' % self.command - self.command = u'' + self.message = 'unknown command "%s"' % self.command + self.command = '' class MpdNoExistError(MpdAckError): @@ -73,4 +75,4 @@ class MpdNotImplemented(MpdAckError): def __init__(self, *args, **kwargs): super(MpdNotImplemented, self).__init__(*args, **kwargs) - self.message = u'Not implemented' + self.message = 'Not implemented' diff --git a/mopidy/frontends/mpd/protocol/__init__.py b/mopidy/frontends/mpd/protocol/__init__.py index 968a7dac..3a9f3674 100644 --- a/mopidy/frontends/mpd/protocol/__init__.py +++ b/mopidy/frontends/mpd/protocol/__init__.py @@ -10,17 +10,19 @@ implement our own MPD server which is compatible with the numerous existing `MPD clients `_. """ +from __future__ import unicode_literals + from collections import namedtuple import re #: The MPD protocol uses UTF-8 for encoding all data. -ENCODING = u'UTF-8' +ENCODING = 'UTF-8' #: The MPD protocol uses ``\n`` as line terminator. -LINE_TERMINATOR = u'\n' +LINE_TERMINATOR = '\n' #: The MPD protocol version is 0.16.0. -VERSION = u'0.16.0' +VERSION = '0.16.0' MpdCommand = namedtuple('MpdCommand', ['name', 'auth_required']) @@ -55,7 +57,7 @@ def handle_request(pattern, auth_required=True): mpd_commands.add( MpdCommand(name=match.group(), auth_required=auth_required)) if pattern in request_handlers: - raise ValueError(u'Tried to redefine handler for %s with %s' % ( + raise ValueError('Tried to redefine handler for %s with %s' % ( pattern, func)) request_handlers[pattern] = func func.__doc__ = ' - *Pattern:* ``%s``\n\n%s' % ( diff --git a/mopidy/frontends/mpd/protocol/audio_output.py b/mopidy/frontends/mpd/protocol/audio_output.py index 7e50c8c0..b4d491e5 100644 --- a/mopidy/frontends/mpd/protocol/audio_output.py +++ b/mopidy/frontends/mpd/protocol/audio_output.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import MpdNotImplemented diff --git a/mopidy/frontends/mpd/protocol/command_list.py b/mopidy/frontends/mpd/protocol/command_list.py index d422f97e..8d5769ef 100644 --- a/mopidy/frontends/mpd/protocol/command_list.py +++ b/mopidy/frontends/mpd/protocol/command_list.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import MpdUnknownCommand @@ -40,10 +42,10 @@ def command_list_end(context): command, current_command_list_index=index) command_list_response.extend(response) if (command_list_response and - command_list_response[-1].startswith(u'ACK')): + command_list_response[-1].startswith('ACK')): return command_list_response if command_list_ok: - command_list_response.append(u'list_OK') + command_list_response.append('list_OK') return command_list_response diff --git a/mopidy/frontends/mpd/protocol/connection.py b/mopidy/frontends/mpd/protocol/connection.py index 3228807f..f7898d21 100644 --- a/mopidy/frontends/mpd/protocol/connection.py +++ b/mopidy/frontends/mpd/protocol/connection.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy import settings from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import ( @@ -25,7 +27,7 @@ def kill(context): Kills MPD. """ - raise MpdPermissionError(command=u'kill') + raise MpdPermissionError(command='kill') @handle_request(r'^password "(?P[^"]+)"$', auth_required=False) @@ -41,7 +43,7 @@ def password_(context, password): if password == settings.MPD_SERVER_PASSWORD: context.dispatcher.authenticated = True else: - raise MpdPasswordError(u'incorrect password', command=u'password') + raise MpdPasswordError('incorrect password', command='password') @handle_request(r'^ping$', auth_required=False) diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index 5a88d41b..57b06e1a 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.frontends.mpd import translator from mopidy.frontends.mpd.exceptions import ( MpdArgError, MpdNoExistError, MpdNotImplemented) @@ -26,8 +28,7 @@ def add(context, uri): if track is not None: context.core.current_playlist.add(track) return - raise MpdNoExistError( - u'directory or file not found', command=u'add') + raise MpdNoExistError('directory or file not found', command='add') @handle_request(r'^addid "(?P[^"]*)"( "(?P\d+)")*$') @@ -50,14 +51,14 @@ def addid(context, uri, songpos=None): - ``addid ""`` should return an error. """ if not uri: - raise MpdNoExistError(u'No such song', command=u'addid') + raise MpdNoExistError('No such song', command='addid') if songpos is not None: songpos = int(songpos) track = context.core.library.lookup(uri).get() if track is None: - raise MpdNoExistError(u'No such song', command=u'addid') + raise MpdNoExistError('No such song', command='addid') if songpos and songpos > context.core.current_playlist.length.get(): - raise MpdArgError(u'Bad song index', command=u'addid') + raise MpdArgError('Bad song index', command='addid') cp_track = context.core.current_playlist.add( track, at_position=songpos).get() return ('Id', cp_track.cpid) @@ -79,7 +80,7 @@ def delete_range(context, start, end=None): end = context.core.current_playlist.length.get() cp_tracks = context.core.current_playlist.slice(start, end).get() if not cp_tracks: - raise MpdArgError(u'Bad song index', command=u'delete') + raise MpdArgError('Bad song index', command='delete') for (cpid, _) in cp_tracks: context.core.current_playlist.remove(cpid=cpid) @@ -93,7 +94,7 @@ def delete_songpos(context, songpos): songpos, songpos + 1).get()[0] context.core.current_playlist.remove(cpid=cpid) except IndexError: - raise MpdArgError(u'Bad song index', command=u'delete') + raise MpdArgError('Bad song index', command='delete') @handle_request(r'^deleteid "(?P\d+)"$') @@ -111,7 +112,7 @@ def deleteid(context, cpid): context.core.playback.next() return context.core.current_playlist.remove(cpid=cpid).get() except LookupError: - raise MpdNoExistError(u'No such song', command=u'deleteid') + raise MpdNoExistError('No such song', command='deleteid') @handle_request(r'^clear$') @@ -227,7 +228,7 @@ def playlistid(context, cpid=None): position = context.core.current_playlist.index(cp_track).get() return translator.track_to_mpd_format(cp_track, position=position) except LookupError: - raise MpdNoExistError(u'No such song', command=u'playlistid') + raise MpdNoExistError('No such song', command='playlistid') else: return translator.tracks_to_mpd_format( context.core.current_playlist.cp_tracks.get()) @@ -261,7 +262,7 @@ def playlistinfo(context, songpos=None, start=None, end=None): start = 0 start = int(start) if not (0 <= start <= context.core.current_playlist.length.get()): - raise MpdArgError(u'Bad song index', command=u'playlistinfo') + raise MpdArgError('Bad song index', command='playlistinfo') if end is not None: end = int(end) if end > context.core.current_playlist.length.get(): @@ -331,8 +332,8 @@ def plchangesposid(context, version): result = [] for (position, (cpid, _)) in enumerate( context.core.current_playlist.cp_tracks.get()): - result.append((u'cpos', position)) - result.append((u'Id', cpid)) + result.append(('cpos', position)) + result.append(('Id', cpid)) return result diff --git a/mopidy/frontends/mpd/protocol/empty.py b/mopidy/frontends/mpd/protocol/empty.py index f2ee4757..dfd610a9 100644 --- a/mopidy/frontends/mpd/protocol/empty.py +++ b/mopidy/frontends/mpd/protocol/empty.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.frontends.mpd.protocol import handle_request diff --git a/mopidy/frontends/mpd/protocol/music_db.py b/mopidy/frontends/mpd/protocol/music_db.py index a5d5b214..49c52d34 100644 --- a/mopidy/frontends/mpd/protocol/music_db.py +++ b/mopidy/frontends/mpd/protocol/music_db.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import re import shlex @@ -20,8 +22,8 @@ def _build_query(mpd_query): for query_part in query_parts: m = re.match(query_part_pattern, query_part) field = m.groupdict()['field'].lower() - if field == u'title': - field = u'track' + if field == 'title': + field = 'track' field = str(field) # Needed for kwargs keys on OS X and Windows what = m.groupdict()['what'].lower() if field in query: @@ -183,13 +185,13 @@ def list_(context, field, mpd_query=None): """ field = field.lower() query = _list_build_query(field, mpd_query) - if field == u'artist': + if field == 'artist': return _list_artist(context, query) - elif field == u'album': + elif field == 'album': return _list_album(context, query) - elif field == u'date': + elif field == 'date': return _list_date(context, query) - elif field == u'genre': + elif field == 'genre': pass # TODO We don't have genre in our internal data structures yet @@ -202,16 +204,16 @@ def _list_build_query(field, mpd_query): tokens = shlex.split(mpd_query.encode('utf-8')) except ValueError as error: if str(error) == 'No closing quotation': - raise MpdArgError(u'Invalid unquoted character', command=u'list') + raise MpdArgError('Invalid unquoted character', command='list') else: raise tokens = [t.decode('utf-8') for t in tokens] if len(tokens) == 1: - if field == u'album': + if field == 'album': return {'artist': [tokens[0]]} else: raise MpdArgError( - u'should be "Album" for 3 arguments', command=u'list') + 'should be "Album" for 3 arguments', command='list') elif len(tokens) % 2 == 0: query = {} while tokens: @@ -219,15 +221,15 @@ def _list_build_query(field, mpd_query): key = str(key) # Needed for kwargs keys on OS X and Windows value = tokens[1] tokens = tokens[2:] - if key not in (u'artist', u'album', u'date', u'genre'): - raise MpdArgError(u'not able to parse args', command=u'list') + if key not in ('artist', 'album', 'date', 'genre'): + raise MpdArgError('not able to parse args', command='list') if key in query: query[key].append(value) else: query[key] = [value] return query else: - raise MpdArgError(u'not able to parse args', command=u'list') + raise MpdArgError('not able to parse args', command='list') def _list_artist(context, query): @@ -235,7 +237,7 @@ def _list_artist(context, query): playlist = context.core.library.find_exact(**query).get() for track in playlist.tracks: for artist in track.artists: - artists.add((u'Artist', artist.name)) + artists.add(('Artist', artist.name)) return artists @@ -244,7 +246,7 @@ def _list_album(context, query): playlist = context.core.library.find_exact(**query).get() for track in playlist.tracks: if track.album is not None: - albums.add((u'Album', track.album.name)) + albums.add(('Album', track.album.name)) return albums @@ -253,7 +255,7 @@ def _list_date(context, query): playlist = context.core.library.find_exact(**query).get() for track in playlist.tracks: if track.date is not None: - dates.add((u'Date', track.date)) + dates.add(('Date', track.date)) return dates @@ -300,7 +302,7 @@ def lsinfo(context, uri=None): directories located at the root level, for both ``lsinfo``, ``lsinfo ""``, and ``lsinfo "/"``. """ - if uri is None or uri == u'/' or uri == u'': + if uri is None or uri == '/' or uri == '': return stored_playlists.listplaylists(context) raise MpdNotImplemented # TODO diff --git a/mopidy/frontends/mpd/protocol/playback.py b/mopidy/frontends/mpd/protocol/playback.py index 7851ebe0..35ceddad 100644 --- a/mopidy/frontends/mpd/protocol/playback.py +++ b/mopidy/frontends/mpd/protocol/playback.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.core import PlaybackState from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import ( @@ -153,7 +155,7 @@ def playid(context, cpid): cp_track = context.core.current_playlist.get(cpid=cpid).get() return context.core.playback.play(cp_track).get() except LookupError: - raise MpdNoExistError(u'No such song', command=u'playid') + raise MpdNoExistError('No such song', command='playid') @handle_request(r'^play (?P-?\d+)$') @@ -187,7 +189,7 @@ def playpos(context, songpos): songpos, songpos + 1).get()[0] return context.core.playback.play(cp_track).get() except IndexError: - raise MpdArgError(u'Bad song index', command=u'play') + raise MpdArgError('Bad song index', command='play') def _play_minus_one(context): @@ -311,7 +313,7 @@ def replay_gain_status(context): Prints replay gain options. Currently, only the variable ``replay_gain_mode`` is returned. """ - return u'off' # TODO + return 'off' # TODO @handle_request(r'^seek (?P\d+) (?P\d+)$') diff --git a/mopidy/frontends/mpd/protocol/reflection.py b/mopidy/frontends/mpd/protocol/reflection.py index bc18eb3a..5af86a1a 100644 --- a/mopidy/frontends/mpd/protocol/reflection.py +++ b/mopidy/frontends/mpd/protocol/reflection.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.frontends.mpd.protocol import handle_request, mpd_commands from mopidy.frontends.mpd.exceptions import MpdNotImplemented @@ -93,5 +95,5 @@ def urlhandlers(context): Gets a list of available URL handlers. """ return [ - (u'handler', uri_scheme) + ('handler', uri_scheme) for uri_scheme in context.core.uri_schemes.get()] diff --git a/mopidy/frontends/mpd/protocol/status.py b/mopidy/frontends/mpd/protocol/status.py index b8e207d1..c5b283da 100644 --- a/mopidy/frontends/mpd/protocol/status.py +++ b/mopidy/frontends/mpd/protocol/status.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import pykka from mopidy.core import PlaybackState @@ -94,7 +96,7 @@ def idle(context, subsystems=None): context.subscriptions = set() for subsystem in active: - response.append(u'changed: %s' % subsystem) + response.append('changed: %s' % subsystem) return response @@ -257,21 +259,21 @@ def _status_songpos(futures): def _status_state(futures): state = futures['playback.state'].get() if state == PlaybackState.PLAYING: - return u'play' + return 'play' elif state == PlaybackState.STOPPED: - return u'stop' + return 'stop' elif state == PlaybackState.PAUSED: - return u'pause' + return 'pause' def _status_time(futures): - return u'%d:%d' % ( + return '%d:%d' % ( futures['playback.time_position'].get() // 1000, _status_time_total(futures) // 1000) def _status_time_elapsed(futures): - return u'%.3f' % (futures['playback.time_position'].get() / 1000.0) + return '%.3f' % (futures['playback.time_position'].get() / 1000.0) def _status_time_total(futures): diff --git a/mopidy/frontends/mpd/protocol/stickers.py b/mopidy/frontends/mpd/protocol/stickers.py index 074a306d..439d8d5b 100644 --- a/mopidy/frontends/mpd/protocol/stickers.py +++ b/mopidy/frontends/mpd/protocol/stickers.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.frontends.mpd.protocol import handle_request from mopidy.frontends.mpd.exceptions import MpdNotImplemented diff --git a/mopidy/frontends/mpd/protocol/stored_playlists.py b/mopidy/frontends/mpd/protocol/stored_playlists.py index 17e5abf7..fc618201 100644 --- a/mopidy/frontends/mpd/protocol/stored_playlists.py +++ b/mopidy/frontends/mpd/protocol/stored_playlists.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import datetime as dt from mopidy.frontends.mpd.exceptions import MpdNoExistError, MpdNotImplemented @@ -25,7 +27,7 @@ def listplaylist(context, name): playlist = context.core.stored_playlists.get(name=name).get() return ['file: %s' % t.uri for t in playlist.tracks] except LookupError: - raise MpdNoExistError(u'No such playlist', command=u'listplaylist') + raise MpdNoExistError('No such playlist', command='listplaylist') @handle_request(r'^listplaylistinfo (?P\S+)$') @@ -47,8 +49,7 @@ def listplaylistinfo(context, name): playlist = context.core.stored_playlists.get(name=name).get() return playlist_to_mpd_format(playlist) except LookupError: - raise MpdNoExistError( - u'No such playlist', command=u'listplaylistinfo') + raise MpdNoExistError('No such playlist', command='listplaylistinfo') @handle_request(r'^listplaylists$') @@ -74,7 +75,7 @@ def listplaylists(context): """ result = [] for playlist in context.core.stored_playlists.playlists.get(): - result.append((u'playlist', playlist.name)) + result.append(('playlist', playlist.name)) last_modified = ( playlist.last_modified or dt.datetime.now()).isoformat() # Remove microseconds @@ -82,7 +83,7 @@ def listplaylists(context): # Add time zone information # TODO Convert to UTC before adding Z last_modified = last_modified + 'Z' - result.append((u'Last-Modified', last_modified)) + result.append(('Last-Modified', last_modified)) return result @@ -103,7 +104,7 @@ def load(context, name): playlist = context.core.stored_playlists.get(name=name).get() context.core.current_playlist.append(playlist.tracks) except LookupError: - raise MpdNoExistError(u'No such playlist', command=u'load') + raise MpdNoExistError('No such playlist', command='load') @handle_request(r'^playlistadd "(?P[^"]+)" "(?P[^"]+)"$') diff --git a/mopidy/frontends/mpd/session.py b/mopidy/frontends/mpd/session.py index 5d535f75..8a5deecd 100644 --- a/mopidy/frontends/mpd/session.py +++ b/mopidy/frontends/mpd/session.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging from mopidy.frontends.mpd import dispatcher, protocol @@ -21,18 +23,18 @@ class MpdSession(network.LineProtocol): self.dispatcher = dispatcher.MpdDispatcher(session=self, core=core) def on_start(self): - logger.info(u'New MPD connection from [%s]:%s', self.host, self.port) - self.send_lines([u'OK MPD %s' % protocol.VERSION]) + logger.info('New MPD connection from [%s]:%s', self.host, self.port) + self.send_lines(['OK MPD %s' % protocol.VERSION]) def on_line_received(self, line): - logger.debug(u'Request from [%s]:%s: %s', self.host, self.port, line) + logger.debug('Request from [%s]:%s: %s', self.host, self.port, line) response = self.dispatcher.handle_request(line) if not response: return logger.debug( - u'Response to [%s]:%s: %s', self.host, self.port, + 'Response to [%s]:%s: %s', self.host, self.port, formatting.indent(self.terminator.join(response))) self.send_lines(response) @@ -45,8 +47,8 @@ class MpdSession(network.LineProtocol): return super(MpdSession, self).decode(line.decode('string_escape')) except ValueError: logger.warning( - u'Stopping actor due to unescaping error, data ' - u'supplied by client was not valid.') + 'Stopping actor due to unescaping error, data ' + 'supplied by client was not valid.') self.stop() def close(self): diff --git a/mopidy/frontends/mpd/translator.py b/mopidy/frontends/mpd/translator.py index 0ab28271..0f4aed68 100644 --- a/mopidy/frontends/mpd/translator.py +++ b/mopidy/frontends/mpd/translator.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import os import re @@ -93,7 +95,7 @@ def artists_to_mpd_format(artists): """ artists = list(artists) artists.sort(key=lambda a: a.name) - return u', '.join([a.name for a in artists if a.name]) + return ', '.join([a.name for a in artists if a.name]) def tracks_to_mpd_format(tracks, start=0, end=None): @@ -178,7 +180,7 @@ def _add_to_tag_cache(result, folders, files): def tracks_to_directory_tree(tracks): directories = ({}, []) for track in tracks: - path = u'' + path = '' current = directories local_folder = settings.LOCAL_MUSIC_PATH diff --git a/mopidy/frontends/mpris/__init__.py b/mopidy/frontends/mpris/__init__.py index 38deac7a..2be6efea 100644 --- a/mopidy/frontends/mpris/__init__.py +++ b/mopidy/frontends/mpris/__init__.py @@ -50,5 +50,7 @@ Now you can control Mopidy through the player object. Examples: player.Quit(dbus_interface='org.mpris.MediaPlayer2') """ +from __future__ import unicode_literals + # flake8: noqa from .actor import MprisFrontend diff --git a/mopidy/frontends/mpris/actor.py b/mopidy/frontends/mpris/actor.py index 5d8d5492..81a44fbb 100644 --- a/mopidy/frontends/mpris/actor.py +++ b/mopidy/frontends/mpris/actor.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import pykka @@ -12,7 +14,7 @@ try: import indicate except ImportError as import_error: indicate = None # noqa - logger.debug(u'Startup notification will not be sent (%s)', import_error) + logger.debug('Startup notification will not be sent (%s)', import_error) class MprisFrontend(pykka.ThreadingActor, CoreListener): @@ -27,20 +29,20 @@ class MprisFrontend(pykka.ThreadingActor, CoreListener): self.mpris_object = objects.MprisObject(self.core) self._send_startup_notification() except Exception as e: - logger.error(u'MPRIS frontend setup failed (%s)', e) + logger.error('MPRIS frontend setup failed (%s)', e) self.stop() def on_stop(self): - logger.debug(u'Removing MPRIS object from D-Bus connection...') + logger.debug('Removing MPRIS object from D-Bus connection...') if self.mpris_object: self.mpris_object.remove_from_connection() self.mpris_object = None - logger.debug(u'Removed MPRIS object from D-Bus connection') + logger.debug('Removed MPRIS object from D-Bus connection') def _send_startup_notification(self): """ Send startup notification using libindicate to make Mopidy appear in - e.g. `Ubuntu's sound menu `_. + e.g. `Ubunt's sound menu `_. A reference to the libindicate server is kept for as long as Mopidy is running. When Mopidy exits, the server will be unreferenced and Mopidy @@ -48,12 +50,12 @@ class MprisFrontend(pykka.ThreadingActor, CoreListener): """ if not indicate: return - logger.debug(u'Sending startup notification...') + logger.debug('Sending startup notification...') self.indicate_server = indicate.Server() self.indicate_server.set_type('music.mopidy') self.indicate_server.set_desktop_file(settings.DESKTOP_FILE) self.indicate_server.show() - logger.debug(u'Startup notification sent') + logger.debug('Startup notification sent') def _emit_properties_changed(self, *changed_properties): if self.mpris_object is None: @@ -65,25 +67,25 @@ class MprisFrontend(pykka.ThreadingActor, CoreListener): objects.PLAYER_IFACE, dict(props_with_new_values), []) def track_playback_paused(self, track, time_position): - logger.debug(u'Received track playback paused event') + logger.debug('Received track playback paused event') self._emit_properties_changed('PlaybackStatus') def track_playback_resumed(self, track, time_position): - logger.debug(u'Received track playback resumed event') + logger.debug('Received track playback resumed event') self._emit_properties_changed('PlaybackStatus') def track_playback_started(self, track): - logger.debug(u'Received track playback started event') + logger.debug('Received track playback started event') self._emit_properties_changed('PlaybackStatus', 'Metadata') def track_playback_ended(self, track, time_position): - logger.debug(u'Received track playback ended event') + logger.debug('Received track playback ended event') self._emit_properties_changed('PlaybackStatus', 'Metadata') def volume_changed(self): - logger.debug(u'Received volume changed event') + logger.debug('Received volume changed event') self._emit_properties_changed('Volume') def seeked(self, time_position_in_ms): - logger.debug(u'Received seeked event') + logger.debug('Received seeked event') self.mpris_object.Seeked(time_position_in_ms * 1000) diff --git a/mopidy/frontends/mpris/objects.py b/mopidy/frontends/mpris/objects.py index 4d4efe1e..0f8426a8 100644 --- a/mopidy/frontends/mpris/objects.py +++ b/mopidy/frontends/mpris/objects.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import os @@ -75,11 +77,11 @@ class MprisObject(dbus.service.Object): } def _connect_to_dbus(self): - logger.debug(u'Connecting to D-Bus...') + logger.debug('Connecting to D-Bus...') mainloop = dbus.mainloop.glib.DBusGMainLoop() bus_name = dbus.service.BusName( BUS_NAME, dbus.SessionBus(mainloop=mainloop)) - logger.info(u'Connected to D-Bus') + logger.info('Connected to D-Bus') return bus_name def _get_track_id(self, cp_track): @@ -95,7 +97,7 @@ class MprisObject(dbus.service.Object): in_signature='ss', out_signature='v') def Get(self, interface, prop): logger.debug( - u'%s.Get(%s, %s) called', + '%s.Get(%s, %s) called', dbus.PROPERTIES_IFACE, repr(interface), repr(prop)) (getter, _) = self.properties[interface][prop] if callable(getter): @@ -107,7 +109,7 @@ class MprisObject(dbus.service.Object): in_signature='s', out_signature='a{sv}') def GetAll(self, interface): logger.debug( - u'%s.GetAll(%s) called', dbus.PROPERTIES_IFACE, repr(interface)) + '%s.GetAll(%s) called', dbus.PROPERTIES_IFACE, repr(interface)) getters = {} for key, (getter, _) in self.properties[interface].iteritems(): getters[key] = getter() if callable(getter) else getter @@ -117,7 +119,7 @@ class MprisObject(dbus.service.Object): in_signature='ssv', out_signature='') def Set(self, interface, prop, value): logger.debug( - u'%s.Set(%s, %s, %s) called', + '%s.Set(%s, %s, %s) called', dbus.PROPERTIES_IFACE, repr(interface), repr(prop), repr(value)) _, setter = self.properties[interface][prop] if setter is not None: @@ -130,7 +132,7 @@ class MprisObject(dbus.service.Object): def PropertiesChanged(self, interface, changed_properties, invalidated_properties): logger.debug( - u'%s.PropertiesChanged(%s, %s, %s) signaled', + '%s.PropertiesChanged(%s, %s, %s) signaled', dbus.PROPERTIES_IFACE, interface, changed_properties, invalidated_properties) @@ -138,12 +140,12 @@ class MprisObject(dbus.service.Object): @dbus.service.method(dbus_interface=ROOT_IFACE) def Raise(self): - logger.debug(u'%s.Raise called', ROOT_IFACE) + logger.debug('%s.Raise called', ROOT_IFACE) # Do nothing, as we do not have a GUI @dbus.service.method(dbus_interface=ROOT_IFACE) def Quit(self): - logger.debug(u'%s.Quit called', ROOT_IFACE) + logger.debug('%s.Quit called', ROOT_IFACE) exit_process() ### Root interface properties @@ -158,33 +160,33 @@ class MprisObject(dbus.service.Object): @dbus.service.method(dbus_interface=PLAYER_IFACE) def Next(self): - logger.debug(u'%s.Next called', PLAYER_IFACE) + logger.debug('%s.Next called', PLAYER_IFACE) if not self.get_CanGoNext(): - logger.debug(u'%s.Next not allowed', PLAYER_IFACE) + logger.debug('%s.Next not allowed', PLAYER_IFACE) return self.core.playback.next().get() @dbus.service.method(dbus_interface=PLAYER_IFACE) def Previous(self): - logger.debug(u'%s.Previous called', PLAYER_IFACE) + logger.debug('%s.Previous called', PLAYER_IFACE) if not self.get_CanGoPrevious(): - logger.debug(u'%s.Previous not allowed', PLAYER_IFACE) + logger.debug('%s.Previous not allowed', PLAYER_IFACE) return self.core.playback.previous().get() @dbus.service.method(dbus_interface=PLAYER_IFACE) def Pause(self): - logger.debug(u'%s.Pause called', PLAYER_IFACE) + logger.debug('%s.Pause called', PLAYER_IFACE) if not self.get_CanPause(): - logger.debug(u'%s.Pause not allowed', PLAYER_IFACE) + logger.debug('%s.Pause not allowed', PLAYER_IFACE) return self.core.playback.pause().get() @dbus.service.method(dbus_interface=PLAYER_IFACE) def PlayPause(self): - logger.debug(u'%s.PlayPause called', PLAYER_IFACE) + logger.debug('%s.PlayPause called', PLAYER_IFACE) if not self.get_CanPause(): - logger.debug(u'%s.PlayPause not allowed', PLAYER_IFACE) + logger.debug('%s.PlayPause not allowed', PLAYER_IFACE) return state = self.core.playback.state.get() if state == PlaybackState.PLAYING: @@ -196,17 +198,17 @@ class MprisObject(dbus.service.Object): @dbus.service.method(dbus_interface=PLAYER_IFACE) def Stop(self): - logger.debug(u'%s.Stop called', PLAYER_IFACE) + logger.debug('%s.Stop called', PLAYER_IFACE) if not self.get_CanControl(): - logger.debug(u'%s.Stop not allowed', PLAYER_IFACE) + logger.debug('%s.Stop not allowed', PLAYER_IFACE) return self.core.playback.stop().get() @dbus.service.method(dbus_interface=PLAYER_IFACE) def Play(self): - logger.debug(u'%s.Play called', PLAYER_IFACE) + logger.debug('%s.Play called', PLAYER_IFACE) if not self.get_CanPlay(): - logger.debug(u'%s.Play not allowed', PLAYER_IFACE) + logger.debug('%s.Play not allowed', PLAYER_IFACE) return state = self.core.playback.state.get() if state == PlaybackState.PAUSED: @@ -216,9 +218,9 @@ class MprisObject(dbus.service.Object): @dbus.service.method(dbus_interface=PLAYER_IFACE) def Seek(self, offset): - logger.debug(u'%s.Seek called', PLAYER_IFACE) + logger.debug('%s.Seek called', PLAYER_IFACE) if not self.get_CanSeek(): - logger.debug(u'%s.Seek not allowed', PLAYER_IFACE) + logger.debug('%s.Seek not allowed', PLAYER_IFACE) return offset_in_milliseconds = offset // 1000 current_position = self.core.playback.time_position.get() @@ -227,9 +229,9 @@ class MprisObject(dbus.service.Object): @dbus.service.method(dbus_interface=PLAYER_IFACE) def SetPosition(self, track_id, position): - logger.debug(u'%s.SetPosition called', PLAYER_IFACE) + logger.debug('%s.SetPosition called', PLAYER_IFACE) if not self.get_CanSeek(): - logger.debug(u'%s.SetPosition not allowed', PLAYER_IFACE) + logger.debug('%s.SetPosition not allowed', PLAYER_IFACE) return position = position // 1000 current_cp_track = self.core.playback.current_cp_track.get() @@ -245,11 +247,11 @@ class MprisObject(dbus.service.Object): @dbus.service.method(dbus_interface=PLAYER_IFACE) def OpenUri(self, uri): - logger.debug(u'%s.OpenUri called', PLAYER_IFACE) + logger.debug('%s.OpenUri called', PLAYER_IFACE) if not self.get_CanPlay(): # NOTE The spec does not explictly require this check, but guarding # the other methods doesn't help much if OpenUri is open for use. - logger.debug(u'%s.Play not allowed', PLAYER_IFACE) + logger.debug('%s.Play not allowed', PLAYER_IFACE) return # NOTE Check if URI has MIME type known to the backend, if MIME support # is added to the backend. @@ -261,13 +263,13 @@ class MprisObject(dbus.service.Object): cp_track = self.core.current_playlist.add(track).get() self.core.playback.play(cp_track) else: - logger.debug(u'Track with URI "%s" not found in library.', uri) + logger.debug('Track with URI "%s" not found in library.', uri) ### Player interface signals @dbus.service.signal(dbus_interface=PLAYER_IFACE, signature='x') def Seeked(self, position): - logger.debug(u'%s.Seeked signaled', PLAYER_IFACE) + logger.debug('%s.Seeked signaled', PLAYER_IFACE) # Do nothing, as just calling the method is enough to emit the signal. ### Player interface properties @@ -294,7 +296,7 @@ class MprisObject(dbus.service.Object): def set_LoopStatus(self, value): if not self.get_CanControl(): - logger.debug(u'Setting %s.LoopStatus not allowed', PLAYER_IFACE) + logger.debug('Setting %s.LoopStatus not allowed', PLAYER_IFACE) return if value == 'None': self.core.playback.repeat = False @@ -310,7 +312,7 @@ class MprisObject(dbus.service.Object): if not self.get_CanControl(): # NOTE The spec does not explictly require this check, but it was # added to be consistent with all the other property setters. - logger.debug(u'Setting %s.Rate not allowed', PLAYER_IFACE) + logger.debug('Setting %s.Rate not allowed', PLAYER_IFACE) return if value == 0: self.Pause() @@ -320,7 +322,7 @@ class MprisObject(dbus.service.Object): def set_Shuffle(self, value): if not self.get_CanControl(): - logger.debug(u'Setting %s.Shuffle not allowed', PLAYER_IFACE) + logger.debug('Setting %s.Shuffle not allowed', PLAYER_IFACE) return if value: self.core.playback.random = True @@ -364,7 +366,7 @@ class MprisObject(dbus.service.Object): def set_Volume(self, value): if not self.get_CanControl(): - logger.debug(u'Setting %s.Volume not allowed', PLAYER_IFACE) + logger.debug('Setting %s.Volume not allowed', PLAYER_IFACE) return if value is None: return diff --git a/mopidy/models.py b/mopidy/models.py index 77561fe3..feb512f6 100644 --- a/mopidy/models.py +++ b/mopidy/models.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from collections import namedtuple @@ -14,7 +16,7 @@ class ImmutableObject(object): for key, value in kwargs.items(): if not hasattr(self, key): raise TypeError( - u"__init__() got an unexpected keyword argument '%s'" % + '__init__() got an unexpected keyword argument "%s"' % key) self.__dict__[key] = value @@ -73,7 +75,7 @@ class ImmutableObject(object): data[key] = values.pop(key) if values: raise TypeError( - u"copy() got an unexpected keyword argument '%s'" % key) + 'copy() got an unexpected keyword argument "%s"' % key) return self.__class__(**data) def serialize(self): diff --git a/mopidy/scanner.py b/mopidy/scanner.py index 2c12d26a..e5e484e5 100644 --- a/mopidy/scanner.py +++ b/mopidy/scanner.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import gobject gobject.threads_init() @@ -62,7 +64,7 @@ class Scanner(object): fakesink = gst.element_factory_make('fakesink') self.uribin = gst.element_factory_make('uridecodebin') - self.uribin.set_property('caps', gst.Caps('audio/x-raw-int')) + self.uribin.set_property('caps', gst.Caps(b'audio/x-raw-int')) self.uribin.connect( 'pad-added', self.process_new_pad, fakesink.get_pad('sink')) diff --git a/mopidy/settings.py b/mopidy/settings.py index 12acd281..897745d7 100644 --- a/mopidy/settings.py +++ b/mopidy/settings.py @@ -7,6 +7,8 @@ All available settings and their default values. file called ``~/.config/mopidy/settings.py`` and redefine settings there. """ +from __future__ import unicode_literals + #: List of playback backends to use. See :ref:`backend-implementations` for all #: available backends. #: @@ -20,21 +22,21 @@ All available settings and their default values. #: u'mopidy.backends.spotify.SpotifyBackend', #: ) BACKENDS = ( - u'mopidy.backends.local.LocalBackend', - u'mopidy.backends.spotify.SpotifyBackend', + 'mopidy.backends.local.LocalBackend', + 'mopidy.backends.spotify.SpotifyBackend', ) #: The log format used for informational logging. #: #: See http://docs.python.org/2/library/logging.html#formatter-objects for #: details on the format. -CONSOLE_LOG_FORMAT = u'%(levelname)-8s %(message)s' +CONSOLE_LOG_FORMAT = '%(levelname)-8s %(message)s' #: The log format used for debug logging. #: #: See http://docs.python.org/library/logging.html#formatter-objects for #: details on the format. -DEBUG_LOG_FORMAT = u'%(levelname)-8s %(asctime)s' + \ +DEBUG_LOG_FORMAT = '%(levelname)-8s %(asctime)s' + \ ' [%(process)d:%(threadName)s] %(name)s\n %(message)s' #: The file to dump debug log data to when Mopidy is run with the @@ -43,13 +45,13 @@ DEBUG_LOG_FORMAT = u'%(levelname)-8s %(asctime)s' + \ #: Default:: #: #: DEBUG_LOG_FILENAME = u'mopidy.log' -DEBUG_LOG_FILENAME = u'mopidy.log' +DEBUG_LOG_FILENAME = 'mopidy.log' #: If we should start a background thread that dumps thread's traceback when we #: get a SIGUSR1. Mainly a debug tool for figuring out deadlocks. #: #: Default:: -#: +#: #: DEBUG_THREAD = False DEBUG_THREAD = False @@ -60,7 +62,7 @@ DEBUG_THREAD = False #: Default:: #: #: DESKTOP_FILE = u'/usr/share/applications/mopidy.desktop' -DESKTOP_FILE = u'/usr/share/applications/mopidy.desktop' +DESKTOP_FILE = '/usr/share/applications/mopidy.desktop' #: List of server frontends to use. See :ref:`frontend-implementations` for #: available frontends. @@ -73,20 +75,20 @@ DESKTOP_FILE = u'/usr/share/applications/mopidy.desktop' #: u'mopidy.frontends.mpris.MprisFrontend', #: ) FRONTENDS = ( - u'mopidy.frontends.mpd.MpdFrontend', - u'mopidy.frontends.lastfm.LastfmFrontend', - u'mopidy.frontends.mpris.MprisFrontend', + 'mopidy.frontends.mpd.MpdFrontend', + 'mopidy.frontends.lastfm.LastfmFrontend', + 'mopidy.frontends.mpris.MprisFrontend', ) #: Your `Last.fm `_ username. #: #: Used by :mod:`mopidy.frontends.lastfm`. -LASTFM_USERNAME = u'' +LASTFM_USERNAME = '' #: Your `Last.fm `_ password. #: #: Used by :mod:`mopidy.frontends.lastfm`. -LASTFM_PASSWORD = u'' +LASTFM_PASSWORD = '' #: Path to folder with local music. #: @@ -95,7 +97,7 @@ LASTFM_PASSWORD = u'' #: Default:: #: #: LOCAL_MUSIC_PATH = u'$XDG_MUSIC_DIR' -LOCAL_MUSIC_PATH = u'$XDG_MUSIC_DIR' +LOCAL_MUSIC_PATH = '$XDG_MUSIC_DIR' #: Path to playlist folder with m3u files for local music. #: @@ -104,7 +106,7 @@ LOCAL_MUSIC_PATH = u'$XDG_MUSIC_DIR' #: Default:: #: #: LOCAL_PLAYLIST_PATH = u'$XDG_DATA_DIR/mopidy/playlists' -LOCAL_PLAYLIST_PATH = u'$XDG_DATA_DIR/mopidy/playlists' +LOCAL_PLAYLIST_PATH = '$XDG_DATA_DIR/mopidy/playlists' #: Path to tag cache for local music. #: @@ -113,7 +115,7 @@ LOCAL_PLAYLIST_PATH = u'$XDG_DATA_DIR/mopidy/playlists' #: Default:: #: #: LOCAL_TAG_CACHE_FILE = u'$XDG_DATA_DIR/mopidy/tag_cache' -LOCAL_TAG_CACHE_FILE = u'$XDG_DATA_DIR/mopidy/tag_cache' +LOCAL_TAG_CACHE_FILE = '$XDG_DATA_DIR/mopidy/tag_cache' #: Audio mixer to use. #: @@ -126,7 +128,7 @@ LOCAL_TAG_CACHE_FILE = u'$XDG_DATA_DIR/mopidy/tag_cache' #: Default:: #: #: MIXER = u'autoaudiomixer' -MIXER = u'autoaudiomixer' +MIXER = 'autoaudiomixer' #: Audio mixer track to use. #: @@ -153,7 +155,7 @@ MIXER_TRACK = None #: Listens on all IPv4 interfaces. #: ``::`` #: Listens on all interfaces, both IPv4 and IPv6. -MPD_SERVER_HOSTNAME = u'127.0.0.1' +MPD_SERVER_HOSTNAME = '127.0.0.1' #: Which TCP port Mopidy's MPD server should listen to. #: @@ -185,7 +187,7 @@ MPD_SERVER_MAX_CONNECTIONS = 20 #: Default:: #: #: OUTPUT = u'autoaudiosink' -OUTPUT = u'autoaudiosink' +OUTPUT = 'autoaudiosink' #: Path to the Spotify cache. #: @@ -194,17 +196,17 @@ OUTPUT = u'autoaudiosink' #: Default:: #: #: SPOTIFY_CACHE_PATH = u'$XDG_CACHE_DIR/mopidy/spotify' -SPOTIFY_CACHE_PATH = u'$XDG_CACHE_DIR/mopidy/spotify' +SPOTIFY_CACHE_PATH = '$XDG_CACHE_DIR/mopidy/spotify' #: Your Spotify Premium username. #: #: Used by :mod:`mopidy.backends.spotify`. -SPOTIFY_USERNAME = u'' +SPOTIFY_USERNAME = '' #: Your Spotify Premium password. #: #: Used by :mod:`mopidy.backends.spotify`. -SPOTIFY_PASSWORD = u'' +SPOTIFY_PASSWORD = '' #: Spotify preferred bitrate. #: diff --git a/mopidy/utils/__init__.py b/mopidy/utils/__init__.py index e69de29b..baffc488 100644 --- a/mopidy/utils/__init__.py +++ b/mopidy/utils/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/mopidy/utils/deps.py b/mopidy/utils/deps.py index 32949f55..41fd513d 100644 --- a/mopidy/utils/deps.py +++ b/mopidy/utils/deps.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import os import platform import sys diff --git a/mopidy/utils/encoding.py b/mopidy/utils/encoding.py index 888896c5..a21b3384 100644 --- a/mopidy/utils/encoding.py +++ b/mopidy/utils/encoding.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import locale diff --git a/mopidy/utils/formatting.py b/mopidy/utils/formatting.py index 9091bc2a..ba311fb5 100644 --- a/mopidy/utils/formatting.py +++ b/mopidy/utils/formatting.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import re import unicodedata @@ -6,7 +8,7 @@ def indent(string, places=4, linebreak='\n'): lines = string.split(linebreak) if len(lines) == 1: return string - result = u'' + result = '' for line in lines: result += linebreak + ' ' * places + line return result diff --git a/mopidy/utils/importing.py b/mopidy/utils/importing.py index 3df6abe4..591071a1 100644 --- a/mopidy/utils/importing.py +++ b/mopidy/utils/importing.py @@ -1,6 +1,9 @@ +from __future__ import unicode_literals + import logging import sys + logger = logging.getLogger('mopidy.utils') diff --git a/mopidy/utils/log.py b/mopidy/utils/log.py index bb966a1d..e503ff9f 100644 --- a/mopidy/utils/log.py +++ b/mopidy/utils/log.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import logging.handlers @@ -14,9 +16,9 @@ def setup_logging(verbosity_level, save_debug_log): # New in Python 2.7 logging.captureWarnings(True) logger = logging.getLogger('mopidy.utils.log') - logger.info(u'Starting Mopidy %s', versioning.get_version()) - logger.info(u'%(name)s: %(version)s', deps.platform_info()) - logger.info(u'%(name)s: %(version)s', deps.python_info()) + logger.info('Starting Mopidy %s', versioning.get_version()) + logger.info('%(name)s: %(version)s', deps.platform_info()) + logger.info('%(name)s: %(version)s', deps.python_info()) def setup_root_logger(): diff --git a/mopidy/utils/network.py b/mopidy/utils/network.py index e56f6a81..91831871 100644 --- a/mopidy/utils/network.py +++ b/mopidy/utils/network.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import errno import gobject import logging @@ -26,8 +28,8 @@ def try_ipv6_socket(): return True except IOError as error: logger.debug( - u'Platform supports IPv6, but socket creation failed, ' - u'disabling: %s', + 'Platform supports IPv6, but socket creation failed, ' + 'disabling: %s', encoding.locale_decode(error)) return False @@ -107,7 +109,7 @@ class Server(object): def reject_connection(self, sock, addr): # FIXME provide more context in logging? - logger.warning(u'Rejected connection from [%s]:%s', addr[0], addr[1]) + logger.warning('Rejected connection from [%s]:%s', addr[0], addr[1]) try: sock.close() except socket.error: @@ -190,7 +192,7 @@ class Connection(object): except socket.error as e: if e.errno in (errno.EWOULDBLOCK, errno.EINTR): return data - self.stop(u'Unexpected client error: %s' % e) + self.stop('Unexpected client error: %s' % e) return '' def enable_timeout(self): @@ -219,7 +221,7 @@ class Connection(object): gobject.IO_IN | gobject.IO_ERR | gobject.IO_HUP, self.recv_callback) except socket.error as e: - self.stop(u'Problem with connection: %s' % e) + self.stop('Problem with connection: %s' % e) def disable_recv(self): if self.recv_id is None: @@ -237,7 +239,7 @@ class Connection(object): gobject.IO_OUT | gobject.IO_ERR | gobject.IO_HUP, self.send_callback) except socket.error as e: - self.stop(u'Problem with connection: %s' % e) + self.stop('Problem with connection: %s' % e) def disable_send(self): if self.send_id is None: @@ -248,30 +250,30 @@ class Connection(object): def recv_callback(self, fd, flags): if flags & (gobject.IO_ERR | gobject.IO_HUP): - self.stop(u'Bad client flags: %s' % flags) + self.stop('Bad client flags: %s' % flags) return True try: data = self.sock.recv(4096) except socket.error as e: if e.errno not in (errno.EWOULDBLOCK, errno.EINTR): - self.stop(u'Unexpected client error: %s' % e) + self.stop('Unexpected client error: %s' % e) return True if not data: - self.stop(u'Client most likely disconnected.') + self.stop('Client most likely disconnected.') return True try: self.actor_ref.tell({'received': data}) except pykka.ActorDeadError: - self.stop(u'Actor is dead.') + self.stop('Actor is dead.') return True def send_callback(self, fd, flags): if flags & (gobject.IO_ERR | gobject.IO_HUP): - self.stop(u'Bad client flags: %s' % flags) + self.stop('Bad client flags: %s' % flags) return True # If with can't get the lock, simply try again next time socket is @@ -289,7 +291,7 @@ class Connection(object): return True def timeout_callback(self): - self.stop(u'Client timeout out after %s seconds' % self.timeout) + self.stop('Client timeout out after %s seconds' % self.timeout) return False @@ -356,7 +358,7 @@ class LineProtocol(pykka.ThreadingActor): def on_stop(self): """Ensure that cleanup when actor stops.""" - self.connection.stop(u'Actor is shutting down.') + self.connection.stop('Actor is shutting down.') def parse_lines(self): """Consume new data and yield any lines found.""" @@ -375,8 +377,8 @@ class LineProtocol(pykka.ThreadingActor): return line.encode(self.encoding) except UnicodeError: logger.warning( - u'Stopping actor due to encode problem, data ' - u'supplied by client was not valid %s', + 'Stopping actor due to encode problem, data ' + 'supplied by client was not valid %s', self.encoding) self.stop() @@ -390,14 +392,14 @@ class LineProtocol(pykka.ThreadingActor): return line.decode(self.encoding) except UnicodeError: logger.warning( - u'Stopping actor due to decode problem, data ' - u'supplied by client was not valid %s', + 'Stopping actor due to decode problem, data ' + 'supplied by client was not valid %s', self.encoding) self.stop() def join_lines(self, lines): if not lines: - return u'' + return '' return self.terminator.join(lines) + self.terminator def send_lines(self, lines): diff --git a/mopidy/utils/path.py b/mopidy/utils/path.py index 1092534f..0c06eedd 100644 --- a/mopidy/utils/path.py +++ b/mopidy/utils/path.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import os import re @@ -25,10 +27,10 @@ def get_or_create_folder(folder): folder = os.path.expanduser(folder) if os.path.isfile(folder): raise OSError( - u'A file with the same name as the desired dir, ' - u'"%s", already exists.' % folder) + 'A file with the same name as the desired dir, ' + '"%s", already exists.' % folder) elif not os.path.isdir(folder): - logger.info(u'Creating dir %s', folder) + logger.info('Creating dir %s', folder) os.makedirs(folder, 0755) return folder @@ -36,7 +38,7 @@ def get_or_create_folder(folder): def get_or_create_file(filename): filename = os.path.expanduser(filename) if not os.path.isfile(filename): - logger.info(u'Creating file %s', filename) + logger.info('Creating file %s', filename) open(filename, 'w') return filename diff --git a/mopidy/utils/process.py b/mopidy/utils/process.py index c6b27533..27e312de 100644 --- a/mopidy/utils/process.py +++ b/mopidy/utils/process.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import logging import signal import sys @@ -10,26 +12,29 @@ from pykka.registry import ActorRegistry from mopidy import exceptions + logger = logging.getLogger('mopidy.utils.process') + SIGNALS = dict((k, v) for v, k in signal.__dict__.iteritems() if v.startswith('SIG') and not v.startswith('SIG_')) + def exit_process(): - logger.debug(u'Interrupting main...') + logger.debug('Interrupting main...') thread.interrupt_main() - logger.debug(u'Interrupted main') + logger.debug('Interrupted main') def exit_handler(signum, frame): """A :mod:`signal` handler which will exit the program on signal.""" - logger.info(u'Got %s signal', SIGNALS[signum]) + logger.info('Got %s signal', SIGNALS[signum]) exit_process() def stop_actors_by_class(klass): actors = ActorRegistry.get_by_class(klass) - logger.debug(u'Stopping %d instance(s) of %s', len(actors), klass.__name__) + logger.debug('Stopping %d instance(s) of %s', len(actors), klass.__name__) for actor in actors: actor.stop() @@ -38,15 +43,15 @@ def stop_remaining_actors(): num_actors = len(ActorRegistry.get_all()) while num_actors: logger.error( - u'There are actor threads still running, this is probably a bug') + 'There are actor threads still running, this is probably a bug') logger.debug( - u'Seeing %d actor and %d non-actor thread(s): %s', + 'Seeing %d actor and %d non-actor thread(s): %s', num_actors, threading.active_count() - num_actors, ', '.join([t.name for t in threading.enumerate()])) - logger.debug(u'Stopping %d actor(s)...', num_actors) + logger.debug('Stopping %d actor(s)...', num_actors) ActorRegistry.stop_all() num_actors = len(ActorRegistry.get_all()) - logger.debug(u'All actors stopped.') + logger.debug('All actors stopped.') class BaseThread(threading.Thread): @@ -56,11 +61,11 @@ class BaseThread(threading.Thread): self.daemon = True def run(self): - logger.debug(u'%s: Starting thread', self.name) + logger.debug('%s: Starting thread', self.name) try: self.run_inside_try() except KeyboardInterrupt: - logger.info(u'Interrupted by user') + logger.info('Interrupted by user') except exceptions.SettingsError as e: logger.error(e.message) except ImportError as e: @@ -69,11 +74,12 @@ class BaseThread(threading.Thread): logger.warning(e) except Exception as e: logger.exception(e) - logger.debug(u'%s: Exiting thread', self.name) + logger.debug('%s: Exiting thread', self.name) def run_inside_try(self): raise NotImplementedError + class DebugThread(threading.Thread): daemon = True name = 'DebugThread' @@ -81,7 +87,7 @@ class DebugThread(threading.Thread): event = threading.Event() def handler(self, signum, frame): - logger.info(u'Got %s signal', SIGNALS[signum]) + logger.info('Got %s signal', SIGNALS[signum]) self.event.set() def run(self): diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index 5760106b..105a94e3 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -1,6 +1,6 @@ # Absolute import needed to import ~/.config/mopidy/settings.py and not # ourselves -from __future__ import absolute_import +from __future__ import absolute_import, unicode_literals import copy import getpass @@ -53,11 +53,11 @@ class SettingsProxy(object): current = self.current # bind locally to avoid copying+updates if attr not in current: - raise exceptions.SettingsError(u'Setting "%s" is not set.' % attr) + raise exceptions.SettingsError('Setting "%s" is not set.' % attr) value = current[attr] if isinstance(value, basestring) and len(value) == 0: - raise exceptions.SettingsError(u'Setting "%s" is empty.' % attr) + raise exceptions.SettingsError('Setting "%s" is empty.' % attr) if not value: return value if attr.endswith('_PATH') or attr.endswith('_FILE'): @@ -75,17 +75,17 @@ class SettingsProxy(object): self._read_missing_settings_from_stdin(self.current, self.runtime) if self.get_errors(): logger.error( - u'Settings validation errors: %s', + 'Settings validation errors: %s', formatting.indent(self.get_errors_as_string())) - raise exceptions.SettingsError(u'Settings validation failed.') + raise exceptions.SettingsError('Settings validation failed.') def _read_missing_settings_from_stdin(self, current, runtime): for setting, value in sorted(current.iteritems()): if isinstance(value, basestring) and len(value) == 0: - runtime[setting] = self._read_from_stdin(setting + u': ') + runtime[setting] = self._read_from_stdin(setting + ': ') def _read_from_stdin(self, prompt): - if u'_PASSWORD' in prompt: + if '_PASSWORD' in prompt: return ( getpass.getpass(prompt) .decode(sys.stdin.encoding, 'ignore')) @@ -101,7 +101,7 @@ class SettingsProxy(object): def get_errors_as_string(self): lines = [] for (setting, error) in self.get_errors().iteritems(): - lines.append(u'%s: %s' % (setting, error)) + lines.append('%s: %s' % (setting, error)) return '\n'.join(lines) @@ -151,37 +151,37 @@ def validate_settings(defaults, settings): for setting, value in settings.iteritems(): if setting in changed: if changed[setting] is None: - errors[setting] = u'Deprecated setting. It may be removed.' + errors[setting] = 'Deprecated setting. It may be removed.' else: - errors[setting] = u'Deprecated setting. Use %s.' % ( + errors[setting] = 'Deprecated setting. Use %s.' % ( changed[setting],) elif setting == 'OUTPUTS': errors[setting] = ( - u'Deprecated setting, please change to OUTPUT. OUTPUT expects ' - u'a GStreamer bin description string for your desired output.') + 'Deprecated setting, please change to OUTPUT. OUTPUT expects ' + 'a GStreamer bin description string for your desired output.') elif setting == 'SPOTIFY_BITRATE': if value not in (96, 160, 320): errors[setting] = ( - u'Unavailable Spotify bitrate. Available bitrates are 96, ' - u'160, and 320.') + 'Unavailable Spotify bitrate. Available bitrates are 96, ' + '160, and 320.') elif setting.startswith('SHOUTCAST_OUTPUT_'): errors[setting] = ( - u'Deprecated setting, please set the value via the GStreamer ' - u'bin in OUTPUT.') + 'Deprecated setting, please set the value via the GStreamer ' + 'bin in OUTPUT.') elif setting in list_of_one_or_more: if not value: - errors[setting] = u'Must contain at least one value.' + errors[setting] = 'Must contain at least one value.' elif setting not in defaults: - errors[setting] = u'Unknown setting.' + errors[setting] = 'Unknown setting.' suggestion = did_you_mean(setting, defaults) if suggestion: - errors[setting] += u' Did you mean %s?' % suggestion + errors[setting] += ' Did you mean %s?' % suggestion return errors @@ -204,20 +204,20 @@ def format_settings_list(settings): for (key, value) in sorted(settings.current.iteritems()): default_value = settings.default.get(key) masked_value = mask_value_if_secret(key, value) - lines.append(u'%s: %s' % ( + lines.append('%s: %s' % ( key, formatting.indent(pprint.pformat(masked_value), places=2))) if value != default_value and default_value is not None: lines.append( - u' Default: %s' % + ' Default: %s' % formatting.indent(pprint.pformat(default_value), places=4)) if errors.get(key) is not None: - lines.append(u' Error: %s' % errors[key]) + lines.append(' Error: %s' % errors[key]) return '\n'.join(lines) def mask_value_if_secret(key, value): if key.endswith('PASSWORD') and value: - return u'********' + return '********' else: return value diff --git a/mopidy/utils/versioning.py b/mopidy/utils/versioning.py index 8e7d55bd..3ad72458 100644 --- a/mopidy/utils/versioning.py +++ b/mopidy/utils/versioning.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from subprocess import PIPE, Popen from mopidy import __version__ diff --git a/setup.py b/setup.py index 99fb7f49..d559d0c9 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,8 @@ Most of this file is taken from the Django project, which is BSD licensed. """ +from __future__ import unicode_literals + from distutils.core import setup from distutils.command.install_data import install_data from distutils.command.install import INSTALL_SCHEMES diff --git a/tests/__init__.py b/tests/__init__.py index 5d9ea2b5..7f7a9c36 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import os import sys diff --git a/tests/__main__.py b/tests/__main__.py index 69113580..11757cbb 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import nose import yappi diff --git a/tests/audio_test.py b/tests/audio_test.py index 852ce36b..b8b65e83 100644 --- a/tests/audio_test.py +++ b/tests/audio_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy import audio, settings from mopidy.utils.path import path_to_uri diff --git a/tests/backends/__init__.py b/tests/backends/__init__.py index e69de29b..baffc488 100644 --- a/tests/backends/__init__.py +++ b/tests/backends/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/tests/backends/base/__init__.py b/tests/backends/base/__init__.py index 84eee193..34b18f2c 100644 --- a/tests/backends/base/__init__.py +++ b/tests/backends/base/__init__.py @@ -1,3 +1,6 @@ +from __future__ import unicode_literals + + def populate_playlist(func): def wrapper(self): for track in self.tracks: diff --git a/tests/backends/base/current_playlist.py b/tests/backends/base/current_playlist.py index 2ba77ee3..6446ffd6 100644 --- a/tests/backends/base/current_playlist.py +++ b/tests/backends/base/current_playlist.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import mock import random @@ -93,18 +95,18 @@ class CurrentPlaylistControllerTest(object): self.controller.append([Track(uri='z'), track, track]) try: self.controller.get(uri='a') - self.fail(u'Should raise LookupError if multiple matches') + self.fail('Should raise LookupError if multiple matches') except LookupError as e: - self.assertEqual(u'"uri=a" match multiple tracks', e[0]) + self.assertEqual('"uri=a" match multiple tracks', e[0]) def test_get_by_uri_raises_error_if_no_match(self): self.controller.playlist = Playlist( tracks=[Track(uri='z'), Track(uri='y')]) try: self.controller.get(uri='a') - self.fail(u'Should raise LookupError if no match') + self.fail('Should raise LookupError if no match') except LookupError as e: - self.assertEqual(u'"uri=a" match no tracks', e[0]) + self.assertEqual('"uri=a" match no tracks', e[0]) def test_get_by_multiple_criteria_returns_elements_matching_all(self): track1 = Track(uri='a', name='x') diff --git a/tests/backends/base/library.py b/tests/backends/base/library.py index b7510dbb..d2e44140 100644 --- a/tests/backends/base/library.py +++ b/tests/backends/base/library.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import pykka from mopidy import core diff --git a/tests/backends/base/playback.py b/tests/backends/base/playback.py index cd55668c..bd42a87b 100644 --- a/tests/backends/base/playback.py +++ b/tests/backends/base/playback.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import mock import random import time diff --git a/tests/backends/base/stored_playlists.py b/tests/backends/base/stored_playlists.py index 267a025c..42c7baa7 100644 --- a/tests/backends/base/stored_playlists.py +++ b/tests/backends/base/stored_playlists.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import os import shutil import tempfile @@ -31,15 +33,15 @@ class StoredPlaylistsControllerTest(object): settings.runtime.clear() def test_create_returns_playlist_with_name_set(self): - playlist = self.stored.create(u'test') + playlist = self.stored.create('test') self.assertEqual(playlist.name, 'test') def test_create_returns_playlist_with_uri_set(self): - playlist = self.stored.create(u'test') + playlist = self.stored.create('test') self.assert_(playlist.uri) def test_create_adds_playlist_to_playlists_collection(self): - playlist = self.stored.create(u'test') + playlist = self.stored.create('test') self.assert_(self.stored.playlists) self.assertIn(playlist, self.stored.playlists) @@ -50,7 +52,7 @@ class StoredPlaylistsControllerTest(object): self.stored.delete('file:///unknown/playlist') def test_delete_playlist_removes_it_from_the_collection(self): - playlist = self.stored.create(u'test') + playlist = self.stored.create('test') self.assertIn(playlist, self.stored.playlists) self.stored.delete(playlist.uri) @@ -66,7 +68,7 @@ class StoredPlaylistsControllerTest(object): self.assertRaises(LookupError, test) def test_get_with_right_criteria(self): - playlist1 = self.stored.create(u'test') + playlist1 = self.stored.create('test') playlist2 = self.stored.get(name='test') self.assertEqual(playlist1, playlist2) @@ -82,21 +84,21 @@ class StoredPlaylistsControllerTest(object): playlist, Playlist(name='a'), Playlist(name='b')] try: self.stored.get(name='b') - self.fail(u'Should raise LookupError if multiple matches') + self.fail('Should raise LookupError if multiple matches') except LookupError as e: - self.assertEqual(u'"name=b" match multiple playlists', e[0]) + self.assertEqual('"name=b" match multiple playlists', e[0]) def test_get_by_name_raises_keyerror_if_no_match(self): self.backend.stored_playlists.playlists = [ Playlist(name='a'), Playlist(name='b')] try: self.stored.get(name='c') - self.fail(u'Should raise LookupError if no match') + self.fail('Should raise LookupError if no match') except LookupError as e: - self.assertEqual(u'"name=c" match no playlists', e[0]) + self.assertEqual('"name=c" match no playlists', e[0]) def test_lookup_finds_playlist_by_uri(self): - original_playlist = self.stored.create(u'test') + original_playlist = self.stored.create('test') looked_up_playlist = self.stored.lookup(original_playlist.uri) @@ -107,10 +109,10 @@ class StoredPlaylistsControllerTest(object): pass def test_save_replaces_stored_playlist_with_updated_playlist(self): - playlist1 = self.stored.create(u'test1') + playlist1 = self.stored.create('test1') self.assertIn(playlist1, self.stored.playlists) - playlist2 = playlist1.copy(name=u'test2') + playlist2 = playlist1.copy(name='test2') playlist2 = self.stored.save(playlist2) self.assertNotIn(playlist1, self.stored.playlists) self.assertIn(playlist2, self.stored.playlists) diff --git a/tests/backends/events_test.py b/tests/backends/events_test.py index 600dbf6c..eaf5863b 100644 --- a/tests/backends/events_test.py +++ b/tests/backends/events_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import mock import pykka diff --git a/tests/backends/local/__init__.py b/tests/backends/local/__init__.py index d2213297..684e12d8 100644 --- a/tests/backends/local/__init__.py +++ b/tests/backends/local/__init__.py @@ -1,6 +1,9 @@ +from __future__ import unicode_literals + from mopidy.utils.path import path_to_uri from tests import path_to_data_dir + song = path_to_data_dir('song%s.wav') generate_song = lambda i: path_to_uri(song % i) diff --git a/tests/backends/local/current_playlist_test.py b/tests/backends/local/current_playlist_test.py index 52fa9eb5..fa326501 100644 --- a/tests/backends/local/current_playlist_test.py +++ b/tests/backends/local/current_playlist_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy import settings from mopidy.backends.local import LocalBackend from mopidy.models import Track diff --git a/tests/backends/local/library_test.py b/tests/backends/local/library_test.py index 75cebdbc..7324d85f 100644 --- a/tests/backends/local/library_test.py +++ b/tests/backends/local/library_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy import settings from mopidy.backends.local import LocalBackend diff --git a/tests/backends/local/playback_test.py b/tests/backends/local/playback_test.py index fea93ae3..b669d5c0 100644 --- a/tests/backends/local/playback_test.py +++ b/tests/backends/local/playback_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy import settings from mopidy.backends.local import LocalBackend from mopidy.core import PlaybackState diff --git a/tests/backends/local/stored_playlists_test.py b/tests/backends/local/stored_playlists_test.py index cd1ecd3c..a99b8c23 100644 --- a/tests/backends/local/stored_playlists_test.py +++ b/tests/backends/local/stored_playlists_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import os from mopidy import settings @@ -20,38 +22,38 @@ class LocalStoredPlaylistsControllerTest( path = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test.m3u') self.assertFalse(os.path.exists(path)) - self.stored.create(u'test') + self.stored.create('test') self.assertTrue(os.path.exists(path)) def test_create_slugifies_playlist_name(self): path = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test-foo-bar.m3u') self.assertFalse(os.path.exists(path)) - playlist = self.stored.create(u'test FOO baR') - self.assertEqual(u'test-foo-bar', playlist.name) + playlist = self.stored.create('test FOO baR') + self.assertEqual('test-foo-bar', playlist.name) self.assertTrue(os.path.exists(path)) def test_create_slugifies_names_which_tries_to_change_directory(self): path = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test-foo-bar.m3u') self.assertFalse(os.path.exists(path)) - playlist = self.stored.create(u'../../test FOO baR') - self.assertEqual(u'test-foo-bar', playlist.name) + playlist = self.stored.create('../../test FOO baR') + self.assertEqual('test-foo-bar', playlist.name) self.assertTrue(os.path.exists(path)) def test_saved_playlist_is_persisted(self): path1 = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test1.m3u') path2 = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test2-foo-bar.m3u') - playlist = self.stored.create(u'test1') + playlist = self.stored.create('test1') self.assertTrue(os.path.exists(path1)) self.assertFalse(os.path.exists(path2)) - playlist = playlist.copy(name=u'test2 FOO baR') + playlist = playlist.copy(name='test2 FOO baR') playlist = self.stored.save(playlist) - self.assertEqual(u'test2-foo-bar', playlist.name) + self.assertEqual('test2-foo-bar', playlist.name) self.assertFalse(os.path.exists(path1)) self.assertTrue(os.path.exists(path2)) @@ -59,7 +61,7 @@ class LocalStoredPlaylistsControllerTest( path = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test.m3u') self.assertFalse(os.path.exists(path)) - playlist = self.stored.create(u'test') + playlist = self.stored.create('test') self.assertTrue(os.path.exists(path)) self.stored.delete(playlist.uri) @@ -68,7 +70,7 @@ class LocalStoredPlaylistsControllerTest( def test_playlist_contents_is_written_to_disk(self): track = Track(uri=generate_song(1)) track_path = track.uri[len('file://'):] - playlist = self.stored.create(u'test') + playlist = self.stored.create('test') playlist_path = playlist.uri[len('file://'):] playlist = playlist.copy(tracks=[track]) playlist = self.stored.save(playlist) @@ -82,7 +84,7 @@ class LocalStoredPlaylistsControllerTest( playlist_path = os.path.join(settings.LOCAL_PLAYLIST_PATH, 'test.m3u') track = Track(uri=path_to_uri(path_to_data_dir('uri2'))) - playlist = self.stored.create(u'test') + playlist = self.stored.create('test') playlist = playlist.copy(tracks=[track]) playlist = self.stored.save(playlist) diff --git a/tests/backends/local/translator_test.py b/tests/backends/local/translator_test.py index 6f754399..e18b13fe 100644 --- a/tests/backends/local/translator_test.py +++ b/tests/backends/local/translator_test.py @@ -1,5 +1,7 @@ # encoding: utf-8 +from __future__ import unicode_literals + import os import tempfile @@ -12,7 +14,7 @@ from tests import unittest, path_to_data_dir data_dir = path_to_data_dir('') song1_path = path_to_data_dir('song1.mp3') song2_path = path_to_data_dir('song2.mp3') -encoded_path = path_to_data_dir(u'æøå.mp3') +encoded_path = path_to_data_dir('æøå.mp3') song1_uri = path_to_uri(song1_path) song2_uri = path_to_uri(song2_path) encoded_uri = path_to_uri(encoded_path) @@ -138,10 +140,10 @@ class MPDTagCacheToTracksTest(unittest.TestCase): path_to_data_dir('utf8_tag_cache'), path_to_data_dir('')) uri = path_to_uri(path_to_data_dir('song1.mp3')) - artists = [Artist(name=u'æøå')] - album = Album(name=u'æøå', artists=artists) + artists = [Artist(name='æøå')] + album = Album(name='æøå', artists=artists) track = Track( - uri=uri, name=u'æøå', artists=artists, album=album, length=4000) + uri=uri, name='æøå', artists=artists, album=album, length=4000) self.assertEqual(track, list(tracks)[0]) diff --git a/tests/core/__init__.py b/tests/core/__init__.py index e69de29b..baffc488 100644 --- a/tests/core/__init__.py +++ b/tests/core/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/tests/core/actor_test.py b/tests/core/actor_test.py index 8212c1da..d86b8702 100644 --- a/tests/core/actor_test.py +++ b/tests/core/actor_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import mock import pykka @@ -26,8 +28,8 @@ class CoreActorTest(unittest.TestCase): self.assertIn('dummy2', result) def test_backends_with_colliding_uri_schemes_fails(self): - self.backend1.__class__.__name__ = 'B1' - self.backend2.__class__.__name__ = 'B2' + self.backend1.__class__.__name__ = b'B1' + self.backend2.__class__.__name__ = b'B2' self.backend2.uri_schemes.get.return_value = ['dummy1', 'dummy2'] self.assertRaisesRegexp( AssertionError, diff --git a/tests/core/library_test.py b/tests/core/library_test.py index 04f19909..cb590428 100644 --- a/tests/core/library_test.py +++ b/tests/core/library_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import mock from mopidy.backends import base diff --git a/tests/core/listener_test.py b/tests/core/listener_test.py index 2abd9479..0bc3f8fd 100644 --- a/tests/core/listener_test.py +++ b/tests/core/listener_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.core import CoreListener, PlaybackState from mopidy.models import Track diff --git a/tests/core/playback_test.py b/tests/core/playback_test.py index b3a75773..db39e716 100644 --- a/tests/core/playback_test.py +++ b/tests/core/playback_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import mock from mopidy.backends import base diff --git a/tests/core/stored_playlists_test.py b/tests/core/stored_playlists_test.py index b0d48512..4efb9acf 100644 --- a/tests/core/stored_playlists_test.py +++ b/tests/core/stored_playlists_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import mock from mopidy.backends import base diff --git a/tests/frontends/__init__.py b/tests/frontends/__init__.py index e69de29b..baffc488 100644 --- a/tests/frontends/__init__.py +++ b/tests/frontends/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/tests/frontends/mpd/__init__.py b/tests/frontends/mpd/__init__.py index e69de29b..baffc488 100644 --- a/tests/frontends/mpd/__init__.py +++ b/tests/frontends/mpd/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/tests/frontends/mpd/dispatcher_test.py b/tests/frontends/mpd/dispatcher_test.py index 9b047641..3404db95 100644 --- a/tests/frontends/mpd/dispatcher_test.py +++ b/tests/frontends/mpd/dispatcher_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import pykka from mopidy import core @@ -34,7 +36,7 @@ class MpdDispatcherTest(unittest.TestCase): except MpdAckError as e: self.assertEqual( e.get_mpd_ack(), - u'ACK [5@0] {} unknown command "an_unknown_command"') + 'ACK [5@0] {} unknown command "an_unknown_command"') def test_find_handler_for_known_command_returns_handler_and_kwargs(self): expected_handler = lambda x: None @@ -48,11 +50,11 @@ class MpdDispatcherTest(unittest.TestCase): def test_handling_unknown_request_yields_error(self): result = self.dispatcher.handle_request('an unhandled request') - self.assertEqual(result[0], u'ACK [5@0] {} unknown command "an"') + self.assertEqual(result[0], 'ACK [5@0] {} unknown command "an"') def test_handling_known_request(self): expected = 'magic' request_handlers['known request'] = lambda x: expected result = self.dispatcher.handle_request('known request') - self.assertIn(u'OK', result) + self.assertIn('OK', result) self.assertIn(expected, result) diff --git a/tests/frontends/mpd/exception_test.py b/tests/frontends/mpd/exception_test.py index 8fb0c933..fe834673 100644 --- a/tests/frontends/mpd/exception_test.py +++ b/tests/frontends/mpd/exception_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.frontends.mpd.exceptions import ( MpdAckError, MpdPermissionError, MpdUnknownCommand, MpdSystemError, MpdNotImplemented) @@ -9,35 +11,35 @@ class MpdExceptionsTest(unittest.TestCase): def test_key_error_wrapped_in_mpd_ack_error(self): try: try: - raise KeyError(u'Track X not found') + raise KeyError('Track X not found') except KeyError as e: raise MpdAckError(e[0]) except MpdAckError as e: - self.assertEqual(e.message, u'Track X not found') + self.assertEqual(e.message, 'Track X not found') def test_mpd_not_implemented_is_a_mpd_ack_error(self): try: raise MpdNotImplemented except MpdAckError as e: - self.assertEqual(e.message, u'Not implemented') + self.assertEqual(e.message, 'Not implemented') def test_get_mpd_ack_with_default_values(self): e = MpdAckError('A description') - self.assertEqual(e.get_mpd_ack(), u'ACK [0@0] {} A description') + self.assertEqual(e.get_mpd_ack(), 'ACK [0@0] {} A description') def test_get_mpd_ack_with_values(self): try: raise MpdAckError('A description', index=7, command='foo') except MpdAckError as e: - self.assertEqual(e.get_mpd_ack(), u'ACK [0@7] {foo} A description') + self.assertEqual(e.get_mpd_ack(), 'ACK [0@7] {foo} A description') def test_mpd_unknown_command(self): try: - raise MpdUnknownCommand(command=u'play') + raise MpdUnknownCommand(command='play') except MpdAckError as e: self.assertEqual( e.get_mpd_ack(), - u'ACK [5@0] {} unknown command "play"') + 'ACK [5@0] {} unknown command "play"') def test_mpd_system_error(self): try: @@ -45,7 +47,7 @@ class MpdExceptionsTest(unittest.TestCase): except MpdSystemError as e: self.assertEqual( e.get_mpd_ack(), - u'ACK [52@0] {} foo') + 'ACK [52@0] {} foo') def test_mpd_permission_error(self): try: @@ -53,4 +55,4 @@ class MpdExceptionsTest(unittest.TestCase): except MpdPermissionError as e: self.assertEqual( e.get_mpd_ack(), - u'ACK [4@0] {foo} you don\'t have permission for "foo"') + 'ACK [4@0] {foo} you don\'t have permission for "foo"') diff --git a/tests/frontends/mpd/protocol/__init__.py b/tests/frontends/mpd/protocol/__init__.py index f7b055fc..00594206 100644 --- a/tests/frontends/mpd/protocol/__init__.py +++ b/tests/frontends/mpd/protocol/__init__.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import mock import pykka @@ -46,20 +48,20 @@ class BaseTestCase(unittest.TestCase): def assertInResponse(self, value): self.assertIn( value, self.connection.response, - u'Did not find %s in %s' % ( + 'Did not find %s in %s' % ( repr(value), repr(self.connection.response))) def assertOnceInResponse(self, value): matched = len([r for r in self.connection.response if r == value]) self.assertEqual( 1, matched, - u'Expected to find %s once in %s' % ( + 'Expected to find %s once in %s' % ( repr(value), repr(self.connection.response))) def assertNotInResponse(self, value): self.assertNotIn( value, self.connection.response, - u'Found %s in %s' % ( + 'Found %s in %s' % ( repr(value), repr(self.connection.response))) def assertEqualResponse(self, value): diff --git a/tests/frontends/mpd/protocol/audio_output_test.py b/tests/frontends/mpd/protocol/audio_output_test.py index 3bb8dce8..11cd249e 100644 --- a/tests/frontends/mpd/protocol/audio_output_test.py +++ b/tests/frontends/mpd/protocol/audio_output_test.py @@ -1,18 +1,20 @@ +from __future__ import unicode_literals + from tests.frontends.mpd import protocol class AudioOutputHandlerTest(protocol.BaseTestCase): def test_enableoutput(self): - self.sendRequest(u'enableoutput "0"') - self.assertInResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('enableoutput "0"') + self.assertInResponse('ACK [0@0] {} Not implemented') def test_disableoutput(self): - self.sendRequest(u'disableoutput "0"') - self.assertInResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('disableoutput "0"') + self.assertInResponse('ACK [0@0] {} Not implemented') def test_outputs(self): - self.sendRequest(u'outputs') - self.assertInResponse(u'outputid: 0') - self.assertInResponse(u'outputname: None') - self.assertInResponse(u'outputenabled: 1') - self.assertInResponse(u'OK') + self.sendRequest('outputs') + self.assertInResponse('outputid: 0') + self.assertInResponse('outputname: None') + self.assertInResponse('outputenabled: 1') + self.assertInResponse('OK') diff --git a/tests/frontends/mpd/protocol/authentication_test.py b/tests/frontends/mpd/protocol/authentication_test.py index 0f0d9c86..26b03f45 100644 --- a/tests/frontends/mpd/protocol/authentication_test.py +++ b/tests/frontends/mpd/protocol/authentication_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy import settings from tests.frontends.mpd import protocol @@ -7,28 +9,28 @@ class AuthenticationTest(protocol.BaseTestCase): def test_authentication_with_valid_password_is_accepted(self): settings.MPD_SERVER_PASSWORD = u'topsecret' - self.sendRequest(u'password "topsecret"') + self.sendRequest('password "topsecret"') self.assertTrue(self.dispatcher.authenticated) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_authentication_with_invalid_password_is_not_accepted(self): settings.MPD_SERVER_PASSWORD = u'topsecret' - self.sendRequest(u'password "secret"') + self.sendRequest('password "secret"') self.assertFalse(self.dispatcher.authenticated) - self.assertEqualResponse(u'ACK [3@0] {password} incorrect password') + self.assertEqualResponse('ACK [3@0] {password} incorrect password') def test_authentication_with_anything_when_password_check_turned_off(self): settings.MPD_SERVER_PASSWORD = None - self.sendRequest(u'any request at all') + self.sendRequest('any request at all') self.assertTrue(self.dispatcher.authenticated) self.assertEqualResponse('ACK [5@0] {} unknown command "any"') def test_anything_when_not_authenticated_should_fail(self): settings.MPD_SERVER_PASSWORD = u'topsecret' - self.sendRequest(u'any request at all') + self.sendRequest('any request at all') self.assertFalse(self.dispatcher.authenticated) self.assertEqualResponse( u'ACK [4@0] {any} you don\'t have permission for "any"') @@ -36,26 +38,26 @@ class AuthenticationTest(protocol.BaseTestCase): def test_close_is_allowed_without_authentication(self): settings.MPD_SERVER_PASSWORD = u'topsecret' - self.sendRequest(u'close') + self.sendRequest('close') self.assertFalse(self.dispatcher.authenticated) def test_commands_is_allowed_without_authentication(self): settings.MPD_SERVER_PASSWORD = u'topsecret' - self.sendRequest(u'commands') + self.sendRequest('commands') self.assertFalse(self.dispatcher.authenticated) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_notcommands_is_allowed_without_authentication(self): settings.MPD_SERVER_PASSWORD = u'topsecret' - self.sendRequest(u'notcommands') + self.sendRequest('notcommands') self.assertFalse(self.dispatcher.authenticated) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_ping_is_allowed_without_authentication(self): settings.MPD_SERVER_PASSWORD = u'topsecret' - self.sendRequest(u'ping') + self.sendRequest('ping') self.assertFalse(self.dispatcher.authenticated) - self.assertInResponse(u'OK') + self.assertInResponse('OK') diff --git a/tests/frontends/mpd/protocol/command_list_test.py b/tests/frontends/mpd/protocol/command_list_test.py index dbd7f9c9..222dcb61 100644 --- a/tests/frontends/mpd/protocol/command_list_test.py +++ b/tests/frontends/mpd/protocol/command_list_test.py @@ -1,59 +1,61 @@ +from __future__ import unicode_literals + from tests.frontends.mpd import protocol class CommandListsTest(protocol.BaseTestCase): def test_command_list_begin(self): - response = self.sendRequest(u'command_list_begin') + response = self.sendRequest('command_list_begin') self.assertEquals([], response) def test_command_list_end(self): - self.sendRequest(u'command_list_begin') - self.sendRequest(u'command_list_end') - self.assertInResponse(u'OK') + self.sendRequest('command_list_begin') + self.sendRequest('command_list_end') + self.assertInResponse('OK') def test_command_list_end_without_start_first_is_an_unknown_command(self): - self.sendRequest(u'command_list_end') + self.sendRequest('command_list_end') self.assertEqualResponse( - u'ACK [5@0] {} unknown command "command_list_end"') + 'ACK [5@0] {} unknown command "command_list_end"') def test_command_list_with_ping(self): - self.sendRequest(u'command_list_begin') + self.sendRequest('command_list_begin') self.assertTrue(self.dispatcher.command_list_receiving) self.assertFalse(self.dispatcher.command_list_ok) self.assertEqual([], self.dispatcher.command_list) - self.sendRequest(u'ping') - self.assertIn(u'ping', self.dispatcher.command_list) + self.sendRequest('ping') + self.assertIn('ping', self.dispatcher.command_list) - self.sendRequest(u'command_list_end') - self.assertInResponse(u'OK') + self.sendRequest('command_list_end') + self.assertInResponse('OK') self.assertFalse(self.dispatcher.command_list_receiving) self.assertFalse(self.dispatcher.command_list_ok) self.assertEqual([], self.dispatcher.command_list) def test_command_list_with_error_returns_ack_with_correct_index(self): - self.sendRequest(u'command_list_begin') - self.sendRequest(u'play') # Known command - self.sendRequest(u'paly') # Unknown command - self.sendRequest(u'command_list_end') - self.assertEqualResponse(u'ACK [5@1] {} unknown command "paly"') + self.sendRequest('command_list_begin') + self.sendRequest('play') # Known command + self.sendRequest('paly') # Unknown command + self.sendRequest('command_list_end') + self.assertEqualResponse('ACK [5@1] {} unknown command "paly"') def test_command_list_ok_begin(self): - response = self.sendRequest(u'command_list_ok_begin') + response = self.sendRequest('command_list_ok_begin') self.assertEquals([], response) def test_command_list_ok_with_ping(self): - self.sendRequest(u'command_list_ok_begin') + self.sendRequest('command_list_ok_begin') self.assertTrue(self.dispatcher.command_list_receiving) self.assertTrue(self.dispatcher.command_list_ok) self.assertEqual([], self.dispatcher.command_list) - self.sendRequest(u'ping') - self.assertIn(u'ping', self.dispatcher.command_list) + self.sendRequest('ping') + self.assertIn('ping', self.dispatcher.command_list) - self.sendRequest(u'command_list_end') - self.assertInResponse(u'list_OK') - self.assertInResponse(u'OK') + self.sendRequest('command_list_end') + self.assertInResponse('list_OK') + self.assertInResponse('OK') self.assertFalse(self.dispatcher.command_list_receiving) self.assertFalse(self.dispatcher.command_list_ok) self.assertEqual([], self.dispatcher.command_list) diff --git a/tests/frontends/mpd/protocol/connection_test.py b/tests/frontends/mpd/protocol/connection_test.py index 9b8972d3..840ce48f 100644 --- a/tests/frontends/mpd/protocol/connection_test.py +++ b/tests/frontends/mpd/protocol/connection_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mock import patch from mopidy import settings @@ -8,37 +10,37 @@ from tests.frontends.mpd import protocol class ConnectionHandlerTest(protocol.BaseTestCase): def test_close_closes_the_client_connection(self): with patch.object(self.session, 'close') as close_mock: - self.sendRequest(u'close') + self.sendRequest('close') close_mock.assertEqualResponsecalled_once_with() - self.assertEqualResponse(u'OK') + self.assertEqualResponse('OK') def test_empty_request(self): - self.sendRequest(u'') - self.assertEqualResponse(u'OK') + self.sendRequest('') + self.assertEqualResponse('OK') - self.sendRequest(u' ') - self.assertEqualResponse(u'OK') + self.sendRequest(' ') + self.assertEqualResponse('OK') def test_kill(self): - self.sendRequest(u'kill') + self.sendRequest('kill') self.assertEqualResponse( - u'ACK [4@0] {kill} you don\'t have permission for "kill"') + 'ACK [4@0] {kill} you don\'t have permission for "kill"') def test_valid_password_is_accepted(self): - settings.MPD_SERVER_PASSWORD = u'topsecret' - self.sendRequest(u'password "topsecret"') - self.assertEqualResponse(u'OK') + settings.MPD_SERVER_PASSWORD = 'topsecret' + self.sendRequest('password "topsecret"') + self.assertEqualResponse('OK') def test_invalid_password_is_not_accepted(self): - settings.MPD_SERVER_PASSWORD = u'topsecret' - self.sendRequest(u'password "secret"') - self.assertEqualResponse(u'ACK [3@0] {password} incorrect password') + settings.MPD_SERVER_PASSWORD = 'topsecret' + self.sendRequest('password "secret"') + self.assertEqualResponse('ACK [3@0] {password} incorrect password') def test_any_password_is_not_accepted_when_password_check_turned_off(self): settings.MPD_SERVER_PASSWORD = None - self.sendRequest(u'password "secret"') - self.assertEqualResponse(u'ACK [3@0] {password} incorrect password') + self.sendRequest('password "secret"') + self.assertEqualResponse('ACK [3@0] {password} incorrect password') def test_ping(self): - self.sendRequest(u'ping') - self.assertEqualResponse(u'OK') + self.sendRequest('ping') + self.assertEqualResponse('OK') diff --git a/tests/frontends/mpd/protocol/current_playlist_test.py b/tests/frontends/mpd/protocol/current_playlist_test.py index bd58cf2d..184f7a9c 100644 --- a/tests/frontends/mpd/protocol/current_playlist_test.py +++ b/tests/frontends/mpd/protocol/current_playlist_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.models import Track from tests.frontends.mpd import protocol @@ -12,20 +14,20 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.sendRequest(u'add "dummy://foo"') + self.sendRequest('add "dummy://foo"') self.assertEqual(len(self.core.current_playlist.tracks.get()), 6) self.assertEqual(self.core.current_playlist.tracks.get()[5], needle) - self.assertEqualResponse(u'OK') + self.assertEqualResponse('OK') def test_add_with_uri_not_found_in_library_should_ack(self): - self.sendRequest(u'add "dummy://foo"') + self.sendRequest('add "dummy://foo"') self.assertEqualResponse( - u'ACK [50@0] {add} directory or file not found') + 'ACK [50@0] {add} directory or file not found') def test_add_with_empty_uri_should_add_all_known_tracks_and_ok(self): - self.sendRequest(u'add ""') + self.sendRequest('add ""') # TODO check that we add all tracks (we currently don't) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_addid_without_songpos(self): needle = Track(uri='dummy://foo') @@ -35,16 +37,16 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.sendRequest(u'addid "dummy://foo"') + self.sendRequest('addid "dummy://foo"') self.assertEqual(len(self.core.current_playlist.tracks.get()), 6) self.assertEqual(self.core.current_playlist.tracks.get()[5], needle) self.assertInResponse( - u'Id: %d' % self.core.current_playlist.cp_tracks.get()[5][0]) - self.assertInResponse(u'OK') + 'Id: %d' % self.core.current_playlist.cp_tracks.get()[5][0]) + self.assertInResponse('OK') def test_addid_with_empty_uri_acks(self): - self.sendRequest(u'addid ""') - self.assertEqualResponse(u'ACK [50@0] {addid} No such song') + self.sendRequest('addid ""') + self.assertEqualResponse('ACK [50@0] {addid} No such song') def test_addid_with_songpos(self): needle = Track(uri='dummy://foo') @@ -54,12 +56,12 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.sendRequest(u'addid "dummy://foo" "3"') + self.sendRequest('addid "dummy://foo" "3"') self.assertEqual(len(self.core.current_playlist.tracks.get()), 6) self.assertEqual(self.core.current_playlist.tracks.get()[3], needle) self.assertInResponse( - u'Id: %d' % self.core.current_playlist.cp_tracks.get()[3][0]) - self.assertInResponse(u'OK') + 'Id: %d' % self.core.current_playlist.cp_tracks.get()[3][0]) + self.assertInResponse('OK') def test_addid_with_songpos_out_of_bounds_should_ack(self): needle = Track(uri='dummy://foo') @@ -69,22 +71,22 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.sendRequest(u'addid "dummy://foo" "6"') - self.assertEqualResponse(u'ACK [2@0] {addid} Bad song index') + self.sendRequest('addid "dummy://foo" "6"') + self.assertEqualResponse('ACK [2@0] {addid} Bad song index') def test_addid_with_uri_not_found_in_library_should_ack(self): - self.sendRequest(u'addid "dummy://foo"') - self.assertEqualResponse(u'ACK [50@0] {addid} No such song') + self.sendRequest('addid "dummy://foo"') + self.assertEqualResponse('ACK [50@0] {addid} No such song') def test_clear(self): self.core.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.sendRequest(u'clear') + self.sendRequest('clear') self.assertEqual(len(self.core.current_playlist.tracks.get()), 0) self.assertEqual(self.core.playback.current_track.get(), None) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_delete_songpos(self): self.core.current_playlist.append( @@ -92,61 +94,61 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) self.sendRequest( - u'delete "%d"' % self.core.current_playlist.cp_tracks.get()[2][0]) + 'delete "%d"' % self.core.current_playlist.cp_tracks.get()[2][0]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 4) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_delete_songpos_out_of_bounds(self): self.core.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.sendRequest(u'delete "5"') + self.sendRequest('delete "5"') self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.assertEqualResponse(u'ACK [2@0] {delete} Bad song index') + self.assertEqualResponse('ACK [2@0] {delete} Bad song index') def test_delete_open_range(self): self.core.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.sendRequest(u'delete "1:"') + self.sendRequest('delete "1:"') self.assertEqual(len(self.core.current_playlist.tracks.get()), 1) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_delete_closed_range(self): self.core.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.sendRequest(u'delete "1:3"') + self.sendRequest('delete "1:3"') self.assertEqual(len(self.core.current_playlist.tracks.get()), 3) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_delete_range_out_of_bounds(self): self.core.current_playlist.append( [Track(), Track(), Track(), Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.sendRequest(u'delete "5:7"') + self.sendRequest('delete "5:7"') self.assertEqual(len(self.core.current_playlist.tracks.get()), 5) - self.assertEqualResponse(u'ACK [2@0] {delete} Bad song index') + self.assertEqualResponse('ACK [2@0] {delete} Bad song index') def test_deleteid(self): self.core.current_playlist.append([Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 2) - self.sendRequest(u'deleteid "1"') + self.sendRequest('deleteid "1"') self.assertEqual(len(self.core.current_playlist.tracks.get()), 1) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_deleteid_does_not_exist(self): self.core.current_playlist.append([Track(), Track()]) self.assertEqual(len(self.core.current_playlist.tracks.get()), 2) - self.sendRequest(u'deleteid "12345"') + self.sendRequest('deleteid "12345"') self.assertEqual(len(self.core.current_playlist.tracks.get()), 2) - self.assertEqualResponse(u'ACK [50@0] {deleteid} No such song') + self.assertEqualResponse('ACK [50@0] {deleteid} No such song') def test_move_songpos(self): self.core.current_playlist.append([ @@ -154,7 +156,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'move "1" "0"') + self.sendRequest('move "1" "0"') tracks = self.core.current_playlist.tracks.get() self.assertEqual(tracks[0].name, 'b') self.assertEqual(tracks[1].name, 'a') @@ -162,7 +164,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.assertEqual(tracks[3].name, 'd') self.assertEqual(tracks[4].name, 'e') self.assertEqual(tracks[5].name, 'f') - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_move_open_range(self): self.core.current_playlist.append([ @@ -170,7 +172,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'move "2:" "0"') + self.sendRequest('move "2:" "0"') tracks = self.core.current_playlist.tracks.get() self.assertEqual(tracks[0].name, 'c') self.assertEqual(tracks[1].name, 'd') @@ -178,7 +180,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.assertEqual(tracks[3].name, 'f') self.assertEqual(tracks[4].name, 'a') self.assertEqual(tracks[5].name, 'b') - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_move_closed_range(self): self.core.current_playlist.append([ @@ -186,7 +188,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'move "1:3" "0"') + self.sendRequest('move "1:3" "0"') tracks = self.core.current_playlist.tracks.get() self.assertEqual(tracks[0].name, 'b') self.assertEqual(tracks[1].name, 'c') @@ -194,7 +196,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.assertEqual(tracks[3].name, 'd') self.assertEqual(tracks[4].name, 'e') self.assertEqual(tracks[5].name, 'f') - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_moveid(self): self.core.current_playlist.append([ @@ -202,7 +204,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'moveid "4" "2"') + self.sendRequest('moveid "4" "2"') tracks = self.core.current_playlist.tracks.get() self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[1].name, 'b') @@ -210,58 +212,58 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.assertEqual(tracks[3].name, 'c') self.assertEqual(tracks[4].name, 'd') self.assertEqual(tracks[5].name, 'f') - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_playlist_returns_same_as_playlistinfo(self): - playlist_response = self.sendRequest(u'playlist') - playlistinfo_response = self.sendRequest(u'playlistinfo') + playlist_response = self.sendRequest('playlist') + playlistinfo_response = self.sendRequest('playlistinfo') self.assertEqual(playlist_response, playlistinfo_response) def test_playlistfind(self): - self.sendRequest(u'playlistfind "tag" "needle"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('playlistfind "tag" "needle"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_playlistfind_by_filename_not_in_current_playlist(self): - self.sendRequest(u'playlistfind "filename" "file:///dev/null"') - self.assertEqualResponse(u'OK') + self.sendRequest('playlistfind "filename" "file:///dev/null"') + self.assertEqualResponse('OK') def test_playlistfind_by_filename_without_quotes(self): - self.sendRequest(u'playlistfind filename "file:///dev/null"') - self.assertEqualResponse(u'OK') + self.sendRequest('playlistfind filename "file:///dev/null"') + self.assertEqualResponse('OK') def test_playlistfind_by_filename_in_current_playlist(self): self.core.current_playlist.append([ Track(uri='file:///exists')]) - self.sendRequest(u'playlistfind filename "file:///exists"') - self.assertInResponse(u'file: file:///exists') - self.assertInResponse(u'Id: 0') - self.assertInResponse(u'Pos: 0') - self.assertInResponse(u'OK') + self.sendRequest('playlistfind filename "file:///exists"') + self.assertInResponse('file: file:///exists') + self.assertInResponse('Id: 0') + self.assertInResponse('Pos: 0') + self.assertInResponse('OK') def test_playlistid_without_songid(self): self.core.current_playlist.append([Track(name='a'), Track(name='b')]) - self.sendRequest(u'playlistid') - self.assertInResponse(u'Title: a') - self.assertInResponse(u'Title: b') - self.assertInResponse(u'OK') + self.sendRequest('playlistid') + self.assertInResponse('Title: a') + self.assertInResponse('Title: b') + self.assertInResponse('OK') def test_playlistid_with_songid(self): self.core.current_playlist.append([Track(name='a'), Track(name='b')]) - self.sendRequest(u'playlistid "1"') - self.assertNotInResponse(u'Title: a') - self.assertNotInResponse(u'Id: 0') - self.assertInResponse(u'Title: b') - self.assertInResponse(u'Id: 1') - self.assertInResponse(u'OK') + self.sendRequest('playlistid "1"') + self.assertNotInResponse('Title: a') + self.assertNotInResponse('Id: 0') + self.assertInResponse('Title: b') + self.assertInResponse('Id: 1') + self.assertInResponse('OK') def test_playlistid_with_not_existing_songid_fails(self): self.core.current_playlist.append([Track(name='a'), Track(name='b')]) - self.sendRequest(u'playlistid "25"') - self.assertEqualResponse(u'ACK [50@0] {playlistid} No such song') + self.sendRequest('playlistid "25"') + self.assertEqualResponse('ACK [50@0] {playlistid} No such song') def test_playlistinfo_without_songpos_or_range(self): self.core.current_playlist.append([ @@ -269,20 +271,20 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'playlistinfo') - self.assertInResponse(u'Title: a') - self.assertInResponse(u'Pos: 0') - self.assertInResponse(u'Title: b') - self.assertInResponse(u'Pos: 1') - self.assertInResponse(u'Title: c') - self.assertInResponse(u'Pos: 2') - self.assertInResponse(u'Title: d') - self.assertInResponse(u'Pos: 3') - self.assertInResponse(u'Title: e') - self.assertInResponse(u'Pos: 4') - self.assertInResponse(u'Title: f') - self.assertInResponse(u'Pos: 5') - self.assertInResponse(u'OK') + self.sendRequest('playlistinfo') + self.assertInResponse('Title: a') + self.assertInResponse('Pos: 0') + self.assertInResponse('Title: b') + self.assertInResponse('Pos: 1') + self.assertInResponse('Title: c') + self.assertInResponse('Pos: 2') + self.assertInResponse('Title: d') + self.assertInResponse('Pos: 3') + self.assertInResponse('Title: e') + self.assertInResponse('Pos: 4') + self.assertInResponse('Title: f') + self.assertInResponse('Pos: 5') + self.assertInResponse('OK') def test_playlistinfo_with_songpos(self): # Make the track's CPID not match the playlist position @@ -292,24 +294,24 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'playlistinfo "4"') - self.assertNotInResponse(u'Title: a') - self.assertNotInResponse(u'Pos: 0') - self.assertNotInResponse(u'Title: b') - self.assertNotInResponse(u'Pos: 1') - self.assertNotInResponse(u'Title: c') - self.assertNotInResponse(u'Pos: 2') - self.assertNotInResponse(u'Title: d') - self.assertNotInResponse(u'Pos: 3') - self.assertInResponse(u'Title: e') - self.assertInResponse(u'Pos: 4') - self.assertNotInResponse(u'Title: f') - self.assertNotInResponse(u'Pos: 5') - self.assertInResponse(u'OK') + self.sendRequest('playlistinfo "4"') + self.assertNotInResponse('Title: a') + self.assertNotInResponse('Pos: 0') + self.assertNotInResponse('Title: b') + self.assertNotInResponse('Pos: 1') + self.assertNotInResponse('Title: c') + self.assertNotInResponse('Pos: 2') + self.assertNotInResponse('Title: d') + self.assertNotInResponse('Pos: 3') + self.assertInResponse('Title: e') + self.assertInResponse('Pos: 4') + self.assertNotInResponse('Title: f') + self.assertNotInResponse('Pos: 5') + self.assertInResponse('OK') def test_playlistinfo_with_negative_songpos_same_as_playlistinfo(self): - response1 = self.sendRequest(u'playlistinfo "-1"') - response2 = self.sendRequest(u'playlistinfo') + response1 = self.sendRequest('playlistinfo "-1"') + response2 = self.sendRequest('playlistinfo') self.assertEqual(response1, response2) def test_playlistinfo_with_open_range(self): @@ -318,20 +320,20 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'playlistinfo "2:"') - self.assertNotInResponse(u'Title: a') - self.assertNotInResponse(u'Pos: 0') - self.assertNotInResponse(u'Title: b') - self.assertNotInResponse(u'Pos: 1') - self.assertInResponse(u'Title: c') - self.assertInResponse(u'Pos: 2') - self.assertInResponse(u'Title: d') - self.assertInResponse(u'Pos: 3') - self.assertInResponse(u'Title: e') - self.assertInResponse(u'Pos: 4') - self.assertInResponse(u'Title: f') - self.assertInResponse(u'Pos: 5') - self.assertInResponse(u'OK') + self.sendRequest('playlistinfo "2:"') + self.assertNotInResponse('Title: a') + self.assertNotInResponse('Pos: 0') + self.assertNotInResponse('Title: b') + self.assertNotInResponse('Pos: 1') + self.assertInResponse('Title: c') + self.assertInResponse('Pos: 2') + self.assertInResponse('Title: d') + self.assertInResponse('Pos: 3') + self.assertInResponse('Title: e') + self.assertInResponse('Pos: 4') + self.assertInResponse('Title: f') + self.assertInResponse('Pos: 5') + self.assertInResponse('OK') def test_playlistinfo_with_closed_range(self): self.core.current_playlist.append([ @@ -339,95 +341,95 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'playlistinfo "2:4"') - self.assertNotInResponse(u'Title: a') - self.assertNotInResponse(u'Title: b') - self.assertInResponse(u'Title: c') - self.assertInResponse(u'Title: d') - self.assertNotInResponse(u'Title: e') - self.assertNotInResponse(u'Title: f') - self.assertInResponse(u'OK') + self.sendRequest('playlistinfo "2:4"') + self.assertNotInResponse('Title: a') + self.assertNotInResponse('Title: b') + self.assertInResponse('Title: c') + self.assertInResponse('Title: d') + self.assertNotInResponse('Title: e') + self.assertNotInResponse('Title: f') + self.assertInResponse('OK') def test_playlistinfo_with_too_high_start_of_range_returns_arg_error(self): - self.sendRequest(u'playlistinfo "10:20"') - self.assertEqualResponse(u'ACK [2@0] {playlistinfo} Bad song index') + self.sendRequest('playlistinfo "10:20"') + self.assertEqualResponse('ACK [2@0] {playlistinfo} Bad song index') def test_playlistinfo_with_too_high_end_of_range_returns_ok(self): - self.sendRequest(u'playlistinfo "0:20"') - self.assertInResponse(u'OK') + self.sendRequest('playlistinfo "0:20"') + self.assertInResponse('OK') def test_playlistsearch(self): - self.sendRequest(u'playlistsearch "any" "needle"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('playlistsearch "any" "needle"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_playlistsearch_without_quotes(self): - self.sendRequest(u'playlistsearch any "needle"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('playlistsearch any "needle"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_plchanges_with_lower_version_returns_changes(self): self.core.current_playlist.append( [Track(name='a'), Track(name='b'), Track(name='c')]) - self.sendRequest(u'plchanges "0"') - self.assertInResponse(u'Title: a') - self.assertInResponse(u'Title: b') - self.assertInResponse(u'Title: c') - self.assertInResponse(u'OK') + self.sendRequest('plchanges "0"') + self.assertInResponse('Title: a') + self.assertInResponse('Title: b') + self.assertInResponse('Title: c') + self.assertInResponse('OK') def test_plchanges_with_equal_version_returns_nothing(self): self.core.current_playlist.append( [Track(name='a'), Track(name='b'), Track(name='c')]) self.assertEqual(self.core.current_playlist.version.get(), 1) - self.sendRequest(u'plchanges "1"') - self.assertNotInResponse(u'Title: a') - self.assertNotInResponse(u'Title: b') - self.assertNotInResponse(u'Title: c') - self.assertInResponse(u'OK') + self.sendRequest('plchanges "1"') + self.assertNotInResponse('Title: a') + self.assertNotInResponse('Title: b') + self.assertNotInResponse('Title: c') + self.assertInResponse('OK') def test_plchanges_with_greater_version_returns_nothing(self): self.core.current_playlist.append( [Track(name='a'), Track(name='b'), Track(name='c')]) self.assertEqual(self.core.current_playlist.version.get(), 1) - self.sendRequest(u'plchanges "2"') - self.assertNotInResponse(u'Title: a') - self.assertNotInResponse(u'Title: b') - self.assertNotInResponse(u'Title: c') - self.assertInResponse(u'OK') + self.sendRequest('plchanges "2"') + self.assertNotInResponse('Title: a') + self.assertNotInResponse('Title: b') + self.assertNotInResponse('Title: c') + self.assertInResponse('OK') def test_plchanges_with_minus_one_returns_entire_playlist(self): self.core.current_playlist.append( [Track(name='a'), Track(name='b'), Track(name='c')]) - self.sendRequest(u'plchanges "-1"') - self.assertInResponse(u'Title: a') - self.assertInResponse(u'Title: b') - self.assertInResponse(u'Title: c') - self.assertInResponse(u'OK') + self.sendRequest('plchanges "-1"') + self.assertInResponse('Title: a') + self.assertInResponse('Title: b') + self.assertInResponse('Title: c') + self.assertInResponse('OK') def test_plchanges_without_quotes_works(self): self.core.current_playlist.append( [Track(name='a'), Track(name='b'), Track(name='c')]) - self.sendRequest(u'plchanges 0') - self.assertInResponse(u'Title: a') - self.assertInResponse(u'Title: b') - self.assertInResponse(u'Title: c') - self.assertInResponse(u'OK') + self.sendRequest('plchanges 0') + self.assertInResponse('Title: a') + self.assertInResponse('Title: b') + self.assertInResponse('Title: c') + self.assertInResponse('OK') def test_plchangesposid(self): self.core.current_playlist.append([Track(), Track(), Track()]) - self.sendRequest(u'plchangesposid "0"') + self.sendRequest('plchangesposid "0"') cp_tracks = self.core.current_playlist.cp_tracks.get() - self.assertInResponse(u'cpos: 0') - self.assertInResponse(u'Id: %d' % cp_tracks[0][0]) - self.assertInResponse(u'cpos: 2') - self.assertInResponse(u'Id: %d' % cp_tracks[1][0]) - self.assertInResponse(u'cpos: 2') - self.assertInResponse(u'Id: %d' % cp_tracks[2][0]) - self.assertInResponse(u'OK') + self.assertInResponse('cpos: 0') + self.assertInResponse('Id: %d' % cp_tracks[0][0]) + self.assertInResponse('cpos: 2') + self.assertInResponse('Id: %d' % cp_tracks[1][0]) + self.assertInResponse('cpos: 2') + self.assertInResponse('Id: %d' % cp_tracks[2][0]) + self.assertInResponse('OK') def test_shuffle_without_range(self): self.core.current_playlist.append([ @@ -436,9 +438,9 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): ]) version = self.core.current_playlist.version.get() - self.sendRequest(u'shuffle') + self.sendRequest('shuffle') self.assertLess(version, self.core.current_playlist.version.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_shuffle_with_open_range(self): self.core.current_playlist.append([ @@ -447,14 +449,14 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): ]) version = self.core.current_playlist.version.get() - self.sendRequest(u'shuffle "4:"') + self.sendRequest('shuffle "4:"') self.assertLess(version, self.core.current_playlist.version.get()) tracks = self.core.current_playlist.tracks.get() self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[1].name, 'b') self.assertEqual(tracks[2].name, 'c') self.assertEqual(tracks[3].name, 'd') - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_shuffle_with_closed_range(self): self.core.current_playlist.append([ @@ -463,14 +465,14 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): ]) version = self.core.current_playlist.version.get() - self.sendRequest(u'shuffle "1:3"') + self.sendRequest('shuffle "1:3"') self.assertLess(version, self.core.current_playlist.version.get()) tracks = self.core.current_playlist.tracks.get() self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[3].name, 'd') self.assertEqual(tracks[4].name, 'e') self.assertEqual(tracks[5].name, 'f') - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_swap(self): self.core.current_playlist.append([ @@ -478,7 +480,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'swap "1" "4"') + self.sendRequest('swap "1" "4"') tracks = self.core.current_playlist.tracks.get() self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[1].name, 'e') @@ -486,7 +488,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.assertEqual(tracks[3].name, 'd') self.assertEqual(tracks[4].name, 'b') self.assertEqual(tracks[5].name, 'f') - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_swapid(self): self.core.current_playlist.append([ @@ -494,7 +496,7 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): Track(name='d'), Track(name='e'), Track(name='f'), ]) - self.sendRequest(u'swapid "1" "4"') + self.sendRequest('swapid "1" "4"') tracks = self.core.current_playlist.tracks.get() self.assertEqual(tracks[0].name, 'a') self.assertEqual(tracks[1].name, 'e') @@ -502,4 +504,4 @@ class CurrentPlaylistHandlerTest(protocol.BaseTestCase): self.assertEqual(tracks[3].name, 'd') self.assertEqual(tracks[4].name, 'b') self.assertEqual(tracks[5].name, 'f') - self.assertInResponse(u'OK') + self.assertInResponse('OK') diff --git a/tests/frontends/mpd/protocol/idle_test.py b/tests/frontends/mpd/protocol/idle_test.py index ae23c88e..e6910988 100644 --- a/tests/frontends/mpd/protocol/idle_test.py +++ b/tests/frontends/mpd/protocol/idle_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mock import patch from mopidy.frontends.mpd.protocol.status import SUBSYSTEMS @@ -27,180 +29,180 @@ class IdleHandlerTest(protocol.BaseTestCase): self.assertNoResponse() def test_idle(self): - self.sendRequest(u'idle') + self.sendRequest('idle') self.assertEqualSubscriptions(SUBSYSTEMS) self.assertNoEvents() self.assertNoResponse() def test_idle_disables_timeout(self): - self.sendRequest(u'idle') + self.sendRequest('idle') self.connection.disable_timeout.assert_called_once_with() def test_noidle(self): - self.sendRequest(u'noidle') + self.sendRequest('noidle') self.assertNoSubscriptions() self.assertNoEvents() self.assertNoResponse() def test_idle_player(self): - self.sendRequest(u'idle player') + self.sendRequest('idle player') self.assertEqualSubscriptions(['player']) self.assertNoEvents() self.assertNoResponse() def test_idle_player_playlist(self): - self.sendRequest(u'idle player playlist') + self.sendRequest('idle player playlist') self.assertEqualSubscriptions(['player', 'playlist']) self.assertNoEvents() self.assertNoResponse() def test_idle_then_noidle(self): - self.sendRequest(u'idle') - self.sendRequest(u'noidle') + self.sendRequest('idle') + self.sendRequest('noidle') self.assertNoSubscriptions() self.assertNoEvents() - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('OK') def test_idle_then_noidle_enables_timeout(self): - self.sendRequest(u'idle') - self.sendRequest(u'noidle') + self.sendRequest('idle') + self.sendRequest('noidle') self.connection.enable_timeout.assert_called_once_with() def test_idle_then_play(self): with patch.object(self.session, 'stop') as stop_mock: - self.sendRequest(u'idle') - self.sendRequest(u'play') + self.sendRequest('idle') + self.sendRequest('play') stop_mock.assert_called_once_with() def test_idle_then_idle(self): with patch.object(self.session, 'stop') as stop_mock: - self.sendRequest(u'idle') - self.sendRequest(u'idle') + self.sendRequest('idle') + self.sendRequest('idle') stop_mock.assert_called_once_with() def test_idle_player_then_play(self): with patch.object(self.session, 'stop') as stop_mock: - self.sendRequest(u'idle player') - self.sendRequest(u'play') + self.sendRequest('idle player') + self.sendRequest('play') stop_mock.assert_called_once_with() def test_idle_then_player(self): - self.sendRequest(u'idle') - self.idleEvent(u'player') + self.sendRequest('idle') + self.idleEvent('player') self.assertNoSubscriptions() self.assertNoEvents() - self.assertOnceInResponse(u'changed: player') - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('changed: player') + self.assertOnceInResponse('OK') def test_idle_player_then_event_player(self): - self.sendRequest(u'idle player') - self.idleEvent(u'player') + self.sendRequest('idle player') + self.idleEvent('player') self.assertNoSubscriptions() self.assertNoEvents() - self.assertOnceInResponse(u'changed: player') - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('changed: player') + self.assertOnceInResponse('OK') def test_idle_player_then_noidle(self): - self.sendRequest(u'idle player') - self.sendRequest(u'noidle') + self.sendRequest('idle player') + self.sendRequest('noidle') self.assertNoSubscriptions() self.assertNoEvents() - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('OK') def test_idle_player_playlist_then_noidle(self): - self.sendRequest(u'idle player playlist') - self.sendRequest(u'noidle') + self.sendRequest('idle player playlist') + self.sendRequest('noidle') self.assertNoEvents() self.assertNoSubscriptions() - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('OK') def test_idle_player_playlist_then_player(self): - self.sendRequest(u'idle player playlist') - self.idleEvent(u'player') + self.sendRequest('idle player playlist') + self.idleEvent('player') self.assertNoEvents() self.assertNoSubscriptions() - self.assertOnceInResponse(u'changed: player') - self.assertNotInResponse(u'changed: playlist') - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('changed: player') + self.assertNotInResponse('changed: playlist') + self.assertOnceInResponse('OK') def test_idle_playlist_then_player(self): - self.sendRequest(u'idle playlist') - self.idleEvent(u'player') + self.sendRequest('idle playlist') + self.idleEvent('player') self.assertEqualEvents(['player']) self.assertEqualSubscriptions(['playlist']) self.assertNoResponse() def test_idle_playlist_then_player_then_playlist(self): - self.sendRequest(u'idle playlist') - self.idleEvent(u'player') - self.idleEvent(u'playlist') + self.sendRequest('idle playlist') + self.idleEvent('player') + self.idleEvent('playlist') self.assertNoEvents() self.assertNoSubscriptions() - self.assertNotInResponse(u'changed: player') - self.assertOnceInResponse(u'changed: playlist') - self.assertOnceInResponse(u'OK') + self.assertNotInResponse('changed: player') + self.assertOnceInResponse('changed: playlist') + self.assertOnceInResponse('OK') def test_player(self): - self.idleEvent(u'player') + self.idleEvent('player') self.assertEqualEvents(['player']) self.assertNoSubscriptions() self.assertNoResponse() def test_player_then_idle_player(self): - self.idleEvent(u'player') - self.sendRequest(u'idle player') + self.idleEvent('player') + self.sendRequest('idle player') self.assertNoEvents() self.assertNoSubscriptions() - self.assertOnceInResponse(u'changed: player') - self.assertNotInResponse(u'changed: playlist') - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('changed: player') + self.assertNotInResponse('changed: playlist') + self.assertOnceInResponse('OK') def test_player_then_playlist(self): - self.idleEvent(u'player') - self.idleEvent(u'playlist') + self.idleEvent('player') + self.idleEvent('playlist') self.assertEqualEvents(['player', 'playlist']) self.assertNoSubscriptions() self.assertNoResponse() def test_player_then_idle(self): - self.idleEvent(u'player') - self.sendRequest(u'idle') + self.idleEvent('player') + self.sendRequest('idle') self.assertNoEvents() self.assertNoSubscriptions() - self.assertOnceInResponse(u'changed: player') - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('changed: player') + self.assertOnceInResponse('OK') def test_player_then_playlist_then_idle(self): - self.idleEvent(u'player') - self.idleEvent(u'playlist') - self.sendRequest(u'idle') + self.idleEvent('player') + self.idleEvent('playlist') + self.sendRequest('idle') self.assertNoEvents() self.assertNoSubscriptions() - self.assertOnceInResponse(u'changed: player') - self.assertOnceInResponse(u'changed: playlist') - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('changed: player') + self.assertOnceInResponse('changed: playlist') + self.assertOnceInResponse('OK') def test_player_then_idle_playlist(self): - self.idleEvent(u'player') - self.sendRequest(u'idle playlist') + self.idleEvent('player') + self.sendRequest('idle playlist') self.assertEqualEvents(['player']) self.assertEqualSubscriptions(['playlist']) self.assertNoResponse() def test_player_then_idle_playlist_then_noidle(self): - self.idleEvent(u'player') - self.sendRequest(u'idle playlist') - self.sendRequest(u'noidle') + self.idleEvent('player') + self.sendRequest('idle playlist') + self.sendRequest('noidle') self.assertNoEvents() self.assertNoSubscriptions() - self.assertOnceInResponse(u'OK') + self.assertOnceInResponse('OK') def test_player_then_playlist_then_idle_playlist(self): - self.idleEvent(u'player') - self.idleEvent(u'playlist') - self.sendRequest(u'idle playlist') + self.idleEvent('player') + self.idleEvent('playlist') + self.sendRequest('idle playlist') self.assertNoEvents() self.assertNoSubscriptions() - self.assertNotInResponse(u'changed: player') - self.assertOnceInResponse(u'changed: playlist') - self.assertOnceInResponse(u'OK') + self.assertNotInResponse('changed: player') + self.assertOnceInResponse('changed: playlist') + self.assertOnceInResponse('OK') diff --git a/tests/frontends/mpd/protocol/music_db_test.py b/tests/frontends/mpd/protocol/music_db_test.py index 088502c4..e1c571f5 100644 --- a/tests/frontends/mpd/protocol/music_db_test.py +++ b/tests/frontends/mpd/protocol/music_db_test.py @@ -1,344 +1,346 @@ +from __future__ import unicode_literals + from tests.frontends.mpd import protocol class MusicDatabaseHandlerTest(protocol.BaseTestCase): def test_count(self): - self.sendRequest(u'count "tag" "needle"') - self.assertInResponse(u'songs: 0') - self.assertInResponse(u'playtime: 0') - self.assertInResponse(u'OK') + self.sendRequest('count "tag" "needle"') + self.assertInResponse('songs: 0') + self.assertInResponse('playtime: 0') + self.assertInResponse('OK') def test_findadd(self): - self.sendRequest(u'findadd "album" "what"') - self.assertInResponse(u'OK') + self.sendRequest('findadd "album" "what"') + self.assertInResponse('OK') def test_listall(self): - self.sendRequest(u'listall "file:///dev/urandom"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('listall "file:///dev/urandom"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_listallinfo(self): - self.sendRequest(u'listallinfo "file:///dev/urandom"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('listallinfo "file:///dev/urandom"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_lsinfo_without_path_returns_same_as_listplaylists(self): - lsinfo_response = self.sendRequest(u'lsinfo') - listplaylists_response = self.sendRequest(u'listplaylists') + lsinfo_response = self.sendRequest('lsinfo') + listplaylists_response = self.sendRequest('listplaylists') self.assertEqual(lsinfo_response, listplaylists_response) def test_lsinfo_with_empty_path_returns_same_as_listplaylists(self): - lsinfo_response = self.sendRequest(u'lsinfo ""') - listplaylists_response = self.sendRequest(u'listplaylists') + lsinfo_response = self.sendRequest('lsinfo ""') + listplaylists_response = self.sendRequest('listplaylists') self.assertEqual(lsinfo_response, listplaylists_response) def test_lsinfo_for_root_returns_same_as_listplaylists(self): - lsinfo_response = self.sendRequest(u'lsinfo "/"') - listplaylists_response = self.sendRequest(u'listplaylists') + lsinfo_response = self.sendRequest('lsinfo "/"') + listplaylists_response = self.sendRequest('listplaylists') self.assertEqual(lsinfo_response, listplaylists_response) def test_update_without_uri(self): - self.sendRequest(u'update') - self.assertInResponse(u'updating_db: 0') - self.assertInResponse(u'OK') + self.sendRequest('update') + self.assertInResponse('updating_db: 0') + self.assertInResponse('OK') def test_update_with_uri(self): - self.sendRequest(u'update "file:///dev/urandom"') - self.assertInResponse(u'updating_db: 0') - self.assertInResponse(u'OK') + self.sendRequest('update "file:///dev/urandom"') + self.assertInResponse('updating_db: 0') + self.assertInResponse('OK') def test_rescan_without_uri(self): - self.sendRequest(u'rescan') - self.assertInResponse(u'updating_db: 0') - self.assertInResponse(u'OK') + self.sendRequest('rescan') + self.assertInResponse('updating_db: 0') + self.assertInResponse('OK') def test_rescan_with_uri(self): - self.sendRequest(u'rescan "file:///dev/urandom"') - self.assertInResponse(u'updating_db: 0') - self.assertInResponse(u'OK') + self.sendRequest('rescan "file:///dev/urandom"') + self.assertInResponse('updating_db: 0') + self.assertInResponse('OK') class MusicDatabaseFindTest(protocol.BaseTestCase): def test_find_album(self): - self.sendRequest(u'find "album" "what"') - self.assertInResponse(u'OK') + self.sendRequest('find "album" "what"') + self.assertInResponse('OK') def test_find_album_without_quotes(self): - self.sendRequest(u'find album "what"') - self.assertInResponse(u'OK') + self.sendRequest('find album "what"') + self.assertInResponse('OK') def test_find_artist(self): - self.sendRequest(u'find "artist" "what"') - self.assertInResponse(u'OK') + self.sendRequest('find "artist" "what"') + self.assertInResponse('OK') def test_find_artist_without_quotes(self): - self.sendRequest(u'find artist "what"') - self.assertInResponse(u'OK') + self.sendRequest('find artist "what"') + self.assertInResponse('OK') def test_find_title(self): - self.sendRequest(u'find "title" "what"') - self.assertInResponse(u'OK') + self.sendRequest('find "title" "what"') + self.assertInResponse('OK') def test_find_title_without_quotes(self): - self.sendRequest(u'find title "what"') - self.assertInResponse(u'OK') + self.sendRequest('find title "what"') + self.assertInResponse('OK') def test_find_date(self): - self.sendRequest(u'find "date" "2002-01-01"') - self.assertInResponse(u'OK') + self.sendRequest('find "date" "2002-01-01"') + self.assertInResponse('OK') def test_find_date_without_quotes(self): - self.sendRequest(u'find date "2002-01-01"') - self.assertInResponse(u'OK') + self.sendRequest('find date "2002-01-01"') + self.assertInResponse('OK') def test_find_date_with_capital_d_and_incomplete_date(self): - self.sendRequest(u'find Date "2005"') - self.assertInResponse(u'OK') + self.sendRequest('find Date "2005"') + self.assertInResponse('OK') def test_find_else_should_fail(self): - self.sendRequest(u'find "somethingelse" "what"') - self.assertEqualResponse(u'ACK [2@0] {find} incorrect arguments') + self.sendRequest('find "somethingelse" "what"') + self.assertEqualResponse('ACK [2@0] {find} incorrect arguments') def test_find_album_and_artist(self): - self.sendRequest(u'find album "album_what" artist "artist_what"') - self.assertInResponse(u'OK') + self.sendRequest('find album "album_what" artist "artist_what"') + self.assertInResponse('OK') class MusicDatabaseListTest(protocol.BaseTestCase): def test_list_foo_returns_ack(self): - self.sendRequest(u'list "foo"') - self.assertEqualResponse(u'ACK [2@0] {list} incorrect arguments') + self.sendRequest('list "foo"') + self.assertEqualResponse('ACK [2@0] {list} incorrect arguments') ### Artist def test_list_artist_with_quotes(self): - self.sendRequest(u'list "artist"') - self.assertInResponse(u'OK') + self.sendRequest('list "artist"') + self.assertInResponse('OK') def test_list_artist_without_quotes(self): - self.sendRequest(u'list artist') - self.assertInResponse(u'OK') + self.sendRequest('list artist') + self.assertInResponse('OK') def test_list_artist_without_quotes_and_capitalized(self): - self.sendRequest(u'list Artist') - self.assertInResponse(u'OK') + self.sendRequest('list Artist') + self.assertInResponse('OK') def test_list_artist_with_query_of_one_token(self): - self.sendRequest(u'list "artist" "anartist"') + self.sendRequest('list "artist" "anartist"') self.assertEqualResponse( - u'ACK [2@0] {list} should be "Album" for 3 arguments') + 'ACK [2@0] {list} should be "Album" for 3 arguments') def test_list_artist_with_unknown_field_in_query_returns_ack(self): - self.sendRequest(u'list "artist" "foo" "bar"') - self.assertEqualResponse(u'ACK [2@0] {list} not able to parse args') + self.sendRequest('list "artist" "foo" "bar"') + self.assertEqualResponse('ACK [2@0] {list} not able to parse args') def test_list_artist_by_artist(self): - self.sendRequest(u'list "artist" "artist" "anartist"') - self.assertInResponse(u'OK') + self.sendRequest('list "artist" "artist" "anartist"') + self.assertInResponse('OK') def test_list_artist_by_album(self): - self.sendRequest(u'list "artist" "album" "analbum"') - self.assertInResponse(u'OK') + self.sendRequest('list "artist" "album" "analbum"') + self.assertInResponse('OK') def test_list_artist_by_full_date(self): - self.sendRequest(u'list "artist" "date" "2001-01-01"') - self.assertInResponse(u'OK') + self.sendRequest('list "artist" "date" "2001-01-01"') + self.assertInResponse('OK') def test_list_artist_by_year(self): - self.sendRequest(u'list "artist" "date" "2001"') - self.assertInResponse(u'OK') + self.sendRequest('list "artist" "date" "2001"') + self.assertInResponse('OK') def test_list_artist_by_genre(self): - self.sendRequest(u'list "artist" "genre" "agenre"') - self.assertInResponse(u'OK') + self.sendRequest('list "artist" "genre" "agenre"') + self.assertInResponse('OK') def test_list_artist_by_artist_and_album(self): self.sendRequest( - u'list "artist" "artist" "anartist" "album" "analbum"') - self.assertInResponse(u'OK') + 'list "artist" "artist" "anartist" "album" "analbum"') + self.assertInResponse('OK') ### Album def test_list_album_with_quotes(self): - self.sendRequest(u'list "album"') - self.assertInResponse(u'OK') + self.sendRequest('list "album"') + self.assertInResponse('OK') def test_list_album_without_quotes(self): - self.sendRequest(u'list album') - self.assertInResponse(u'OK') + self.sendRequest('list album') + self.assertInResponse('OK') def test_list_album_without_quotes_and_capitalized(self): - self.sendRequest(u'list Album') - self.assertInResponse(u'OK') + self.sendRequest('list Album') + self.assertInResponse('OK') def test_list_album_with_artist_name(self): - self.sendRequest(u'list "album" "anartist"') - self.assertInResponse(u'OK') + self.sendRequest('list "album" "anartist"') + self.assertInResponse('OK') def test_list_album_by_artist(self): - self.sendRequest(u'list "album" "artist" "anartist"') - self.assertInResponse(u'OK') + self.sendRequest('list "album" "artist" "anartist"') + self.assertInResponse('OK') def test_list_album_by_album(self): - self.sendRequest(u'list "album" "album" "analbum"') - self.assertInResponse(u'OK') + self.sendRequest('list "album" "album" "analbum"') + self.assertInResponse('OK') def test_list_album_by_full_date(self): - self.sendRequest(u'list "album" "date" "2001-01-01"') - self.assertInResponse(u'OK') + self.sendRequest('list "album" "date" "2001-01-01"') + self.assertInResponse('OK') def test_list_album_by_year(self): - self.sendRequest(u'list "album" "date" "2001"') - self.assertInResponse(u'OK') + self.sendRequest('list "album" "date" "2001"') + self.assertInResponse('OK') def test_list_album_by_genre(self): - self.sendRequest(u'list "album" "genre" "agenre"') - self.assertInResponse(u'OK') + self.sendRequest('list "album" "genre" "agenre"') + self.assertInResponse('OK') def test_list_album_by_artist_and_album(self): self.sendRequest( - u'list "album" "artist" "anartist" "album" "analbum"') - self.assertInResponse(u'OK') + 'list "album" "artist" "anartist" "album" "analbum"') + self.assertInResponse('OK') ### Date def test_list_date_with_quotes(self): - self.sendRequest(u'list "date"') - self.assertInResponse(u'OK') + self.sendRequest('list "date"') + self.assertInResponse('OK') def test_list_date_without_quotes(self): - self.sendRequest(u'list date') - self.assertInResponse(u'OK') + self.sendRequest('list date') + self.assertInResponse('OK') def test_list_date_without_quotes_and_capitalized(self): - self.sendRequest(u'list Date') - self.assertInResponse(u'OK') + self.sendRequest('list Date') + self.assertInResponse('OK') def test_list_date_with_query_of_one_token(self): - self.sendRequest(u'list "date" "anartist"') + self.sendRequest('list "date" "anartist"') self.assertEqualResponse( - u'ACK [2@0] {list} should be "Album" for 3 arguments') + 'ACK [2@0] {list} should be "Album" for 3 arguments') def test_list_date_by_artist(self): - self.sendRequest(u'list "date" "artist" "anartist"') - self.assertInResponse(u'OK') + self.sendRequest('list "date" "artist" "anartist"') + self.assertInResponse('OK') def test_list_date_by_album(self): - self.sendRequest(u'list "date" "album" "analbum"') - self.assertInResponse(u'OK') + self.sendRequest('list "date" "album" "analbum"') + self.assertInResponse('OK') def test_list_date_by_full_date(self): - self.sendRequest(u'list "date" "date" "2001-01-01"') - self.assertInResponse(u'OK') + self.sendRequest('list "date" "date" "2001-01-01"') + self.assertInResponse('OK') def test_list_date_by_year(self): - self.sendRequest(u'list "date" "date" "2001"') - self.assertInResponse(u'OK') + self.sendRequest('list "date" "date" "2001"') + self.assertInResponse('OK') def test_list_date_by_genre(self): - self.sendRequest(u'list "date" "genre" "agenre"') - self.assertInResponse(u'OK') + self.sendRequest('list "date" "genre" "agenre"') + self.assertInResponse('OK') def test_list_date_by_artist_and_album(self): - self.sendRequest(u'list "date" "artist" "anartist" "album" "analbum"') - self.assertInResponse(u'OK') + self.sendRequest('list "date" "artist" "anartist" "album" "analbum"') + self.assertInResponse('OK') ### Genre def test_list_genre_with_quotes(self): - self.sendRequest(u'list "genre"') - self.assertInResponse(u'OK') + self.sendRequest('list "genre"') + self.assertInResponse('OK') def test_list_genre_without_quotes(self): - self.sendRequest(u'list genre') - self.assertInResponse(u'OK') + self.sendRequest('list genre') + self.assertInResponse('OK') def test_list_genre_without_quotes_and_capitalized(self): - self.sendRequest(u'list Genre') - self.assertInResponse(u'OK') + self.sendRequest('list Genre') + self.assertInResponse('OK') def test_list_genre_with_query_of_one_token(self): - self.sendRequest(u'list "genre" "anartist"') + self.sendRequest('list "genre" "anartist"') self.assertEqualResponse( - u'ACK [2@0] {list} should be "Album" for 3 arguments') + 'ACK [2@0] {list} should be "Album" for 3 arguments') def test_list_genre_by_artist(self): - self.sendRequest(u'list "genre" "artist" "anartist"') - self.assertInResponse(u'OK') + self.sendRequest('list "genre" "artist" "anartist"') + self.assertInResponse('OK') def test_list_genre_by_album(self): - self.sendRequest(u'list "genre" "album" "analbum"') - self.assertInResponse(u'OK') + self.sendRequest('list "genre" "album" "analbum"') + self.assertInResponse('OK') def test_list_genre_by_full_date(self): - self.sendRequest(u'list "genre" "date" "2001-01-01"') - self.assertInResponse(u'OK') + self.sendRequest('list "genre" "date" "2001-01-01"') + self.assertInResponse('OK') def test_list_genre_by_year(self): - self.sendRequest(u'list "genre" "date" "2001"') - self.assertInResponse(u'OK') + self.sendRequest('list "genre" "date" "2001"') + self.assertInResponse('OK') def test_list_genre_by_genre(self): - self.sendRequest(u'list "genre" "genre" "agenre"') - self.assertInResponse(u'OK') + self.sendRequest('list "genre" "genre" "agenre"') + self.assertInResponse('OK') def test_list_genre_by_artist_and_album(self): self.sendRequest( - u'list "genre" "artist" "anartist" "album" "analbum"') - self.assertInResponse(u'OK') + 'list "genre" "artist" "anartist" "album" "analbum"') + self.assertInResponse('OK') class MusicDatabaseSearchTest(protocol.BaseTestCase): def test_search_album(self): - self.sendRequest(u'search "album" "analbum"') - self.assertInResponse(u'OK') + self.sendRequest('search "album" "analbum"') + self.assertInResponse('OK') def test_search_album_without_quotes(self): - self.sendRequest(u'search album "analbum"') - self.assertInResponse(u'OK') + self.sendRequest('search album "analbum"') + self.assertInResponse('OK') def test_search_artist(self): - self.sendRequest(u'search "artist" "anartist"') - self.assertInResponse(u'OK') + self.sendRequest('search "artist" "anartist"') + self.assertInResponse('OK') def test_search_artist_without_quotes(self): - self.sendRequest(u'search artist "anartist"') - self.assertInResponse(u'OK') + self.sendRequest('search artist "anartist"') + self.assertInResponse('OK') def test_search_filename(self): - self.sendRequest(u'search "filename" "afilename"') - self.assertInResponse(u'OK') + self.sendRequest('search "filename" "afilename"') + self.assertInResponse('OK') def test_search_filename_without_quotes(self): - self.sendRequest(u'search filename "afilename"') - self.assertInResponse(u'OK') + self.sendRequest('search filename "afilename"') + self.assertInResponse('OK') def test_search_title(self): - self.sendRequest(u'search "title" "atitle"') - self.assertInResponse(u'OK') + self.sendRequest('search "title" "atitle"') + self.assertInResponse('OK') def test_search_title_without_quotes(self): - self.sendRequest(u'search title "atitle"') - self.assertInResponse(u'OK') + self.sendRequest('search title "atitle"') + self.assertInResponse('OK') def test_search_any(self): - self.sendRequest(u'search "any" "anything"') - self.assertInResponse(u'OK') + self.sendRequest('search "any" "anything"') + self.assertInResponse('OK') def test_search_any_without_quotes(self): - self.sendRequest(u'search any "anything"') - self.assertInResponse(u'OK') + self.sendRequest('search any "anything"') + self.assertInResponse('OK') def test_search_date(self): - self.sendRequest(u'search "date" "2002-01-01"') - self.assertInResponse(u'OK') + self.sendRequest('search "date" "2002-01-01"') + self.assertInResponse('OK') def test_search_date_without_quotes(self): - self.sendRequest(u'search date "2002-01-01"') - self.assertInResponse(u'OK') + self.sendRequest('search date "2002-01-01"') + self.assertInResponse('OK') def test_search_date_with_capital_d_and_incomplete_date(self): - self.sendRequest(u'search Date "2005"') - self.assertInResponse(u'OK') + self.sendRequest('search Date "2005"') + self.assertInResponse('OK') def test_search_else_should_fail(self): - self.sendRequest(u'search "sometype" "something"') - self.assertEqualResponse(u'ACK [2@0] {search} incorrect arguments') + self.sendRequest('search "sometype" "something"') + self.assertEqualResponse('ACK [2@0] {search} incorrect arguments') diff --git a/tests/frontends/mpd/protocol/playback_test.py b/tests/frontends/mpd/protocol/playback_test.py index 202ac649..b09ac481 100644 --- a/tests/frontends/mpd/protocol/playback_test.py +++ b/tests/frontends/mpd/protocol/playback_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.core import PlaybackState from mopidy.models import Track @@ -12,140 +14,140 @@ STOPPED = PlaybackState.STOPPED class PlaybackOptionsHandlerTest(protocol.BaseTestCase): def test_consume_off(self): - self.sendRequest(u'consume "0"') + self.sendRequest('consume "0"') self.assertFalse(self.core.playback.consume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_consume_off_without_quotes(self): - self.sendRequest(u'consume 0') + self.sendRequest('consume 0') self.assertFalse(self.core.playback.consume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_consume_on(self): - self.sendRequest(u'consume "1"') + self.sendRequest('consume "1"') self.assertTrue(self.core.playback.consume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_consume_on_without_quotes(self): - self.sendRequest(u'consume 1') + self.sendRequest('consume 1') self.assertTrue(self.core.playback.consume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_crossfade(self): - self.sendRequest(u'crossfade "10"') - self.assertInResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('crossfade "10"') + self.assertInResponse('ACK [0@0] {} Not implemented') def test_random_off(self): - self.sendRequest(u'random "0"') + self.sendRequest('random "0"') self.assertFalse(self.core.playback.random.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_random_off_without_quotes(self): - self.sendRequest(u'random 0') + self.sendRequest('random 0') self.assertFalse(self.core.playback.random.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_random_on(self): - self.sendRequest(u'random "1"') + self.sendRequest('random "1"') self.assertTrue(self.core.playback.random.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_random_on_without_quotes(self): - self.sendRequest(u'random 1') + self.sendRequest('random 1') self.assertTrue(self.core.playback.random.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_repeat_off(self): - self.sendRequest(u'repeat "0"') + self.sendRequest('repeat "0"') self.assertFalse(self.core.playback.repeat.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_repeat_off_without_quotes(self): - self.sendRequest(u'repeat 0') + self.sendRequest('repeat 0') self.assertFalse(self.core.playback.repeat.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_repeat_on(self): - self.sendRequest(u'repeat "1"') + self.sendRequest('repeat "1"') self.assertTrue(self.core.playback.repeat.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_repeat_on_without_quotes(self): - self.sendRequest(u'repeat 1') + self.sendRequest('repeat 1') self.assertTrue(self.core.playback.repeat.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_setvol_below_min(self): - self.sendRequest(u'setvol "-10"') + self.sendRequest('setvol "-10"') self.assertEqual(0, self.core.playback.volume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_setvol_min(self): - self.sendRequest(u'setvol "0"') + self.sendRequest('setvol "0"') self.assertEqual(0, self.core.playback.volume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_setvol_middle(self): - self.sendRequest(u'setvol "50"') + self.sendRequest('setvol "50"') self.assertEqual(50, self.core.playback.volume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_setvol_max(self): - self.sendRequest(u'setvol "100"') + self.sendRequest('setvol "100"') self.assertEqual(100, self.core.playback.volume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_setvol_above_max(self): - self.sendRequest(u'setvol "110"') + self.sendRequest('setvol "110"') self.assertEqual(100, self.core.playback.volume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_setvol_plus_is_ignored(self): - self.sendRequest(u'setvol "+10"') + self.sendRequest('setvol "+10"') self.assertEqual(10, self.core.playback.volume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_setvol_without_quotes(self): - self.sendRequest(u'setvol 50') + self.sendRequest('setvol 50') self.assertEqual(50, self.core.playback.volume.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_single_off(self): - self.sendRequest(u'single "0"') + self.sendRequest('single "0"') self.assertFalse(self.core.playback.single.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_single_off_without_quotes(self): - self.sendRequest(u'single 0') + self.sendRequest('single 0') self.assertFalse(self.core.playback.single.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_single_on(self): - self.sendRequest(u'single "1"') + self.sendRequest('single "1"') self.assertTrue(self.core.playback.single.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_single_on_without_quotes(self): - self.sendRequest(u'single 1') + self.sendRequest('single 1') self.assertTrue(self.core.playback.single.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_replay_gain_mode_off(self): - self.sendRequest(u'replay_gain_mode "off"') - self.assertInResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('replay_gain_mode "off"') + self.assertInResponse('ACK [0@0] {} Not implemented') def test_replay_gain_mode_track(self): - self.sendRequest(u'replay_gain_mode "track"') - self.assertInResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('replay_gain_mode "track"') + self.assertInResponse('ACK [0@0] {} Not implemented') def test_replay_gain_mode_album(self): - self.sendRequest(u'replay_gain_mode "album"') - self.assertInResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('replay_gain_mode "album"') + self.assertInResponse('ACK [0@0] {} Not implemented') def test_replay_gain_status_default(self): - self.sendRequest(u'replay_gain_status') - self.assertInResponse(u'OK') - self.assertInResponse(u'off') + self.sendRequest('replay_gain_status') + self.assertInResponse('OK') + self.assertInResponse('off') @unittest.SkipTest def test_replay_gain_status_off(self): @@ -162,68 +164,68 @@ class PlaybackOptionsHandlerTest(protocol.BaseTestCase): class PlaybackControlHandlerTest(protocol.BaseTestCase): def test_next(self): - self.sendRequest(u'next') - self.assertInResponse(u'OK') + self.sendRequest('next') + self.assertInResponse('OK') def test_pause_off(self): self.core.current_playlist.append([Track(uri='dummy:a')]) - self.sendRequest(u'play "0"') - self.sendRequest(u'pause "1"') - self.sendRequest(u'pause "0"') + self.sendRequest('play "0"') + self.sendRequest('pause "1"') + self.sendRequest('pause "0"') self.assertEqual(PLAYING, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_pause_on(self): self.core.current_playlist.append([Track(uri='dummy:a')]) - self.sendRequest(u'play "0"') - self.sendRequest(u'pause "1"') + self.sendRequest('play "0"') + self.sendRequest('pause "1"') self.assertEqual(PAUSED, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_pause_toggle(self): self.core.current_playlist.append([Track(uri='dummy:a')]) - self.sendRequest(u'play "0"') + self.sendRequest('play "0"') self.assertEqual(PLAYING, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') - self.sendRequest(u'pause') + self.sendRequest('pause') self.assertEqual(PAUSED, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') - self.sendRequest(u'pause') + self.sendRequest('pause') self.assertEqual(PLAYING, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_play_without_pos(self): self.core.current_playlist.append([Track(uri='dummy:a')]) - self.sendRequest(u'play') + self.sendRequest('play') self.assertEqual(PLAYING, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_play_with_pos(self): self.core.current_playlist.append([Track(uri='dummy:a')]) - self.sendRequest(u'play "0"') + self.sendRequest('play "0"') self.assertEqual(PLAYING, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_play_with_pos_without_quotes(self): self.core.current_playlist.append([Track(uri='dummy:a')]) - self.sendRequest(u'play 0') + self.sendRequest('play 0') self.assertEqual(PLAYING, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_play_with_pos_out_of_bounds(self): self.core.current_playlist.append([]) - self.sendRequest(u'play "0"') + self.sendRequest('play "0"') self.assertEqual(STOPPED, self.core.playback.state.get()) - self.assertInResponse(u'ACK [2@0] {play} Bad song index') + self.assertInResponse('ACK [2@0] {play} Bad song index') def test_play_minus_one_plays_first_in_playlist_if_no_current_track(self): self.assertEqual(self.core.playback.current_track.get(), None) @@ -232,11 +234,11 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase): Track(uri='dummy:b'), ]) - self.sendRequest(u'play "-1"') + self.sendRequest('play "-1"') self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual('dummy:a', self.core.playback.current_track.get().uri) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_play_minus_one_plays_current_track_if_current_track_is_set(self): self.core.current_playlist.append([ @@ -249,19 +251,19 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase): self.core.playback.stop() self.assertNotEqual(self.core.playback.current_track.get(), None) - self.sendRequest(u'play "-1"') + self.sendRequest('play "-1"') self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual('dummy:b', self.core.playback.current_track.get().uri) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_play_minus_one_on_empty_playlist_does_not_ack(self): self.core.current_playlist.clear() - self.sendRequest(u'play "-1"') + self.sendRequest('play "-1"') self.assertEqual(STOPPED, self.core.playback.state.get()) self.assertEqual(None, self.core.playback.current_track.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_play_minus_is_ignored_if_playing(self): self.core.current_playlist.append([ @@ -271,11 +273,11 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase): self.core.playback.time_position.get(), 30000) self.assertEquals(PLAYING, self.core.playback.state.get()) - self.sendRequest(u'play "-1"') + self.sendRequest('play "-1"') self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertGreaterEqual( self.core.playback.time_position.get(), 30000) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_play_minus_one_resumes_if_paused(self): self.core.current_playlist.append([ @@ -287,25 +289,25 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase): self.core.playback.pause() self.assertEquals(PAUSED, self.core.playback.state.get()) - self.sendRequest(u'play "-1"') + self.sendRequest('play "-1"') self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertGreaterEqual( self.core.playback.time_position.get(), 30000) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_playid(self): self.core.current_playlist.append([Track(uri='dummy:a')]) - self.sendRequest(u'playid "0"') + self.sendRequest('playid "0"') self.assertEqual(PLAYING, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_playid_without_quotes(self): self.core.current_playlist.append([Track(uri='dummy:a')]) - self.sendRequest(u'playid 0') + self.sendRequest('playid 0') self.assertEqual(PLAYING, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_playid_minus_1_plays_first_in_playlist_if_no_current_track(self): self.assertEqual(self.core.playback.current_track.get(), None) @@ -314,11 +316,11 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase): Track(uri='dummy:b'), ]) - self.sendRequest(u'playid "-1"') + self.sendRequest('playid "-1"') self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual('dummy:a', self.core.playback.current_track.get().uri) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_playid_minus_1_plays_current_track_if_current_track_is_set(self): self.core.current_playlist.append([ @@ -331,19 +333,19 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase): self.core.playback.stop() self.assertNotEqual(None, self.core.playback.current_track.get()) - self.sendRequest(u'playid "-1"') + self.sendRequest('playid "-1"') self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertEqual('dummy:b', self.core.playback.current_track.get().uri) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_playid_minus_one_on_empty_playlist_does_not_ack(self): self.core.current_playlist.clear() - self.sendRequest(u'playid "-1"') + self.sendRequest('playid "-1"') self.assertEqual(STOPPED, self.core.playback.state.get()) self.assertEqual(None, self.core.playback.current_track.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_playid_minus_is_ignored_if_playing(self): self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) @@ -352,11 +354,11 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase): self.core.playback.time_position.get(), 30000) self.assertEquals(PLAYING, self.core.playback.state.get()) - self.sendRequest(u'playid "-1"') + self.sendRequest('playid "-1"') self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertGreaterEqual( self.core.playback.time_position.get(), 30000) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_playid_minus_one_resumes_if_paused(self): self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) @@ -367,66 +369,66 @@ class PlaybackControlHandlerTest(protocol.BaseTestCase): self.core.playback.pause() self.assertEquals(PAUSED, self.core.playback.state.get()) - self.sendRequest(u'playid "-1"') + self.sendRequest('playid "-1"') self.assertEqual(PLAYING, self.core.playback.state.get()) self.assertGreaterEqual( self.core.playback.time_position.get(), 30000) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_playid_which_does_not_exist(self): self.core.current_playlist.append([Track(uri='dummy:a')]) - self.sendRequest(u'playid "12345"') - self.assertInResponse(u'ACK [50@0] {playid} No such song') + self.sendRequest('playid "12345"') + self.assertInResponse('ACK [50@0] {playid} No such song') def test_previous(self): - self.sendRequest(u'previous') - self.assertInResponse(u'OK') + self.sendRequest('previous') + self.assertInResponse('OK') def test_seek(self): self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) - self.sendRequest(u'seek "0"') - self.sendRequest(u'seek "0" "30"') + self.sendRequest('seek "0"') + self.sendRequest('seek "0" "30"') self.assertGreaterEqual(self.core.playback.time_position, 30000) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_seek_with_songpos(self): seek_track = Track(uri='dummy:b', length=40000) self.core.current_playlist.append( [Track(uri='dummy:a', length=40000), seek_track]) - self.sendRequest(u'seek "1" "30"') + self.sendRequest('seek "1" "30"') self.assertEqual(self.core.playback.current_track.get(), seek_track) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_seek_without_quotes(self): self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) - self.sendRequest(u'seek 0') - self.sendRequest(u'seek 0 30') + self.sendRequest('seek 0') + self.sendRequest('seek 0 30') self.assertGreaterEqual( self.core.playback.time_position.get(), 30000) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_seekid(self): self.core.current_playlist.append([Track(uri='dummy:a', length=40000)]) - self.sendRequest(u'seekid "0" "30"') + self.sendRequest('seekid "0" "30"') self.assertGreaterEqual( self.core.playback.time_position.get(), 30000) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_seekid_with_cpid(self): seek_track = Track(uri='dummy:b', length=40000) self.core.current_playlist.append( [Track(uri='dummy:a', length=40000), seek_track]) - self.sendRequest(u'seekid "1" "30"') + self.sendRequest('seekid "1" "30"') self.assertEqual(1, self.core.playback.current_cpid.get()) self.assertEqual(seek_track, self.core.playback.current_track.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_stop(self): - self.sendRequest(u'stop') + self.sendRequest('stop') self.assertEqual(STOPPED, self.core.playback.state.get()) - self.assertInResponse(u'OK') + self.assertInResponse('OK') diff --git a/tests/frontends/mpd/protocol/reflection_test.py b/tests/frontends/mpd/protocol/reflection_test.py index 8bd9b7e0..33032d73 100644 --- a/tests/frontends/mpd/protocol/reflection_test.py +++ b/tests/frontends/mpd/protocol/reflection_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy import settings from tests.frontends.mpd import protocol @@ -5,63 +7,63 @@ from tests.frontends.mpd import protocol class ReflectionHandlerTest(protocol.BaseTestCase): def test_commands_returns_list_of_all_commands(self): - self.sendRequest(u'commands') + self.sendRequest('commands') # Check if some random commands are included - self.assertInResponse(u'command: commands') - self.assertInResponse(u'command: play') - self.assertInResponse(u'command: status') + self.assertInResponse('command: commands') + self.assertInResponse('command: play') + self.assertInResponse('command: status') # Check if commands you do not have access to are not present - self.assertNotInResponse(u'command: kill') + self.assertNotInResponse('command: kill') # Check if the blacklisted commands are not present - self.assertNotInResponse(u'command: command_list_begin') - self.assertNotInResponse(u'command: command_list_ok_begin') - self.assertNotInResponse(u'command: command_list_end') - self.assertNotInResponse(u'command: idle') - self.assertNotInResponse(u'command: noidle') - self.assertNotInResponse(u'command: sticker') - self.assertInResponse(u'OK') + self.assertNotInResponse('command: command_list_begin') + self.assertNotInResponse('command: command_list_ok_begin') + self.assertNotInResponse('command: command_list_end') + self.assertNotInResponse('command: idle') + self.assertNotInResponse('command: noidle') + self.assertNotInResponse('command: sticker') + self.assertInResponse('OK') def test_commands_show_less_if_auth_required_and_not_authed(self): settings.MPD_SERVER_PASSWORD = u'secret' - self.sendRequest(u'commands') + self.sendRequest('commands') # Not requiring auth - self.assertInResponse(u'command: close') - self.assertInResponse(u'command: commands') - self.assertInResponse(u'command: notcommands') - self.assertInResponse(u'command: password') - self.assertInResponse(u'command: ping') + self.assertInResponse('command: close') + self.assertInResponse('command: commands') + self.assertInResponse('command: notcommands') + self.assertInResponse('command: password') + self.assertInResponse('command: ping') # Requiring auth - self.assertNotInResponse(u'command: play') - self.assertNotInResponse(u'command: status') + self.assertNotInResponse('command: play') + self.assertNotInResponse('command: status') def test_decoders(self): - self.sendRequest(u'decoders') - self.assertInResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('decoders') + self.assertInResponse('ACK [0@0] {} Not implemented') def test_notcommands_returns_only_kill_and_ok(self): - response = self.sendRequest(u'notcommands') + response = self.sendRequest('notcommands') self.assertEqual(2, len(response)) - self.assertInResponse(u'command: kill') - self.assertInResponse(u'OK') + self.assertInResponse('command: kill') + self.assertInResponse('OK') def test_notcommands_returns_more_if_auth_required_and_not_authed(self): settings.MPD_SERVER_PASSWORD = u'secret' - self.sendRequest(u'notcommands') + self.sendRequest('notcommands') # Not requiring auth - self.assertNotInResponse(u'command: close') - self.assertNotInResponse(u'command: commands') - self.assertNotInResponse(u'command: notcommands') - self.assertNotInResponse(u'command: password') - self.assertNotInResponse(u'command: ping') + self.assertNotInResponse('command: close') + self.assertNotInResponse('command: commands') + self.assertNotInResponse('command: notcommands') + self.assertNotInResponse('command: password') + self.assertNotInResponse('command: ping') # Requiring auth - self.assertInResponse(u'command: play') - self.assertInResponse(u'command: status') + self.assertInResponse('command: play') + self.assertInResponse('command: status') def test_tagtypes(self): - self.sendRequest(u'tagtypes') - self.assertInResponse(u'OK') + self.sendRequest('tagtypes') + self.assertInResponse('OK') def test_urlhandlers(self): - self.sendRequest(u'urlhandlers') - self.assertInResponse(u'OK') - self.assertInResponse(u'handler: dummy') + self.sendRequest('urlhandlers') + self.assertInResponse('OK') + self.assertInResponse('handler: dummy') diff --git a/tests/frontends/mpd/protocol/regression_test.py b/tests/frontends/mpd/protocol/regression_test.py index a90e37ab..ede93d88 100644 --- a/tests/frontends/mpd/protocol/regression_test.py +++ b/tests/frontends/mpd/protocol/regression_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import random from mopidy.models import Track @@ -26,21 +28,21 @@ class IssueGH17RegressionTest(protocol.BaseTestCase): ]) random.seed(1) # Playlist order: abcfde - self.sendRequest(u'play') + self.sendRequest('play') self.assertEquals('dummy:a', self.core.playback.current_track.get().uri) - self.sendRequest(u'random "1"') - self.sendRequest(u'next') + self.sendRequest('random "1"') + self.sendRequest('next') self.assertEquals('dummy:b', self.core.playback.current_track.get().uri) - self.sendRequest(u'next') + self.sendRequest('next') # Should now be at track 'c', but playback fails and it skips ahead self.assertEquals('dummy:f', self.core.playback.current_track.get().uri) - self.sendRequest(u'next') + self.sendRequest('next') self.assertEquals('dummy:d', self.core.playback.current_track.get().uri) - self.sendRequest(u'next') + self.sendRequest('next') self.assertEquals('dummy:e', self.core.playback.current_track.get().uri) @@ -62,17 +64,17 @@ class IssueGH18RegressionTest(protocol.BaseTestCase): Track(uri='dummy:d'), Track(uri='dummy:e'), Track(uri='dummy:f')]) random.seed(1) - self.sendRequest(u'play') - self.sendRequest(u'random "1"') - self.sendRequest(u'next') - self.sendRequest(u'random "0"') - self.sendRequest(u'next') + self.sendRequest('play') + self.sendRequest('random "1"') + self.sendRequest('next') + self.sendRequest('random "0"') + self.sendRequest('next') - self.sendRequest(u'next') + self.sendRequest('next') cp_track_1 = self.core.playback.current_cp_track.get() - self.sendRequest(u'next') + self.sendRequest('next') cp_track_2 = self.core.playback.current_cp_track.get() - self.sendRequest(u'next') + self.sendRequest('next') cp_track_3 = self.core.playback.current_cp_track.get() self.assertNotEqual(cp_track_1, cp_track_2) @@ -98,15 +100,15 @@ class IssueGH22RegressionTest(protocol.BaseTestCase): Track(uri='dummy:d'), Track(uri='dummy:e'), Track(uri='dummy:f')]) random.seed(1) - self.sendRequest(u'play') - self.sendRequest(u'random "1"') - self.sendRequest(u'deleteid "1"') - self.sendRequest(u'deleteid "2"') - self.sendRequest(u'deleteid "3"') - self.sendRequest(u'deleteid "4"') - self.sendRequest(u'deleteid "5"') - self.sendRequest(u'deleteid "6"') - self.sendRequest(u'status') + self.sendRequest('play') + self.sendRequest('random "1"') + self.sendRequest('deleteid "1"') + self.sendRequest('deleteid "2"') + self.sendRequest('deleteid "3"') + self.sendRequest('deleteid "4"') + self.sendRequest('deleteid "5"') + self.sendRequest('deleteid "6"') + self.sendRequest('status') class IssueGH69RegressionTest(protocol.BaseTestCase): @@ -126,10 +128,10 @@ class IssueGH69RegressionTest(protocol.BaseTestCase): Track(uri='dummy:a'), Track(uri='dummy:b'), Track(uri='dummy:c'), Track(uri='dummy:d'), Track(uri='dummy:e'), Track(uri='dummy:f')]) - self.sendRequest(u'play') - self.sendRequest(u'stop') - self.sendRequest(u'clear') - self.sendRequest(u'load "foo"') + self.sendRequest('play') + self.sendRequest('stop') + self.sendRequest('clear') + self.sendRequest('load "foo"') self.assertNotInResponse('song: None') @@ -149,7 +151,7 @@ class IssueGH113RegressionTest(protocol.BaseTestCase): self.core.stored_playlists.create( u'all lart spotify:track:\w\{22\} pastes') - self.sendRequest(u'lsinfo "/"') + self.sendRequest('lsinfo "/"') self.assertInResponse( u'playlist: all lart spotify:track:\w\{22\} pastes') diff --git a/tests/frontends/mpd/protocol/status_test.py b/tests/frontends/mpd/protocol/status_test.py index e2f0df9c..6d406961 100644 --- a/tests/frontends/mpd/protocol/status_test.py +++ b/tests/frontends/mpd/protocol/status_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.models import Track from tests.frontends.mpd import protocol @@ -5,33 +7,33 @@ from tests.frontends.mpd import protocol class StatusHandlerTest(protocol.BaseTestCase): def test_clearerror(self): - self.sendRequest(u'clearerror') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('clearerror') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_currentsong(self): track = Track() self.core.current_playlist.append([track]) self.core.playback.play() - self.sendRequest(u'currentsong') - self.assertInResponse(u'file: ') - self.assertInResponse(u'Time: 0') - self.assertInResponse(u'Artist: ') - self.assertInResponse(u'Title: ') - self.assertInResponse(u'Album: ') - self.assertInResponse(u'Track: 0') - self.assertInResponse(u'Date: ') - self.assertInResponse(u'Pos: 0') - self.assertInResponse(u'Id: 0') - self.assertInResponse(u'OK') + self.sendRequest('currentsong') + self.assertInResponse('file: ') + self.assertInResponse('Time: 0') + self.assertInResponse('Artist: ') + self.assertInResponse('Title: ') + self.assertInResponse('Album: ') + self.assertInResponse('Track: 0') + self.assertInResponse('Date: ') + self.assertInResponse('Pos: 0') + self.assertInResponse('Id: 0') + self.assertInResponse('OK') def test_currentsong_without_song(self): - self.sendRequest(u'currentsong') - self.assertInResponse(u'OK') + self.sendRequest('currentsong') + self.assertInResponse('OK') def test_stats_command(self): - self.sendRequest(u'stats') - self.assertInResponse(u'OK') + self.sendRequest('stats') + self.assertInResponse('OK') def test_status_command(self): - self.sendRequest(u'status') - self.assertInResponse(u'OK') + self.sendRequest('status') + self.assertInResponse('OK') diff --git a/tests/frontends/mpd/protocol/stickers_test.py b/tests/frontends/mpd/protocol/stickers_test.py index 3e8b687f..de610521 100644 --- a/tests/frontends/mpd/protocol/stickers_test.py +++ b/tests/frontends/mpd/protocol/stickers_test.py @@ -1,33 +1,35 @@ +from __future__ import unicode_literals + from tests.frontends.mpd import protocol class StickersHandlerTest(protocol.BaseTestCase): def test_sticker_get(self): self.sendRequest( - u'sticker get "song" "file:///dev/urandom" "a_name"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + 'sticker get "song" "file:///dev/urandom" "a_name"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_sticker_set(self): self.sendRequest( - u'sticker set "song" "file:///dev/urandom" "a_name" "a_value"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + 'sticker set "song" "file:///dev/urandom" "a_name" "a_value"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_sticker_delete_with_name(self): self.sendRequest( - u'sticker delete "song" "file:///dev/urandom" "a_name"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + 'sticker delete "song" "file:///dev/urandom" "a_name"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_sticker_delete_without_name(self): self.sendRequest( - u'sticker delete "song" "file:///dev/urandom"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + 'sticker delete "song" "file:///dev/urandom"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_sticker_list(self): self.sendRequest( - u'sticker list "song" "file:///dev/urandom"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + 'sticker list "song" "file:///dev/urandom"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_sticker_find(self): self.sendRequest( - u'sticker find "song" "file:///dev/urandom" "a_name"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + 'sticker find "song" "file:///dev/urandom" "a_name"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') diff --git a/tests/frontends/mpd/protocol/stored_playlists_test.py b/tests/frontends/mpd/protocol/stored_playlists_test.py index c8db3f8f..e2eefbd4 100644 --- a/tests/frontends/mpd/protocol/stored_playlists_test.py +++ b/tests/frontends/mpd/protocol/stored_playlists_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import datetime from mopidy.models import Track, Playlist @@ -10,57 +12,57 @@ class StoredPlaylistsHandlerTest(protocol.BaseTestCase): self.backend.stored_playlists.playlists = [ Playlist(name='name', tracks=[Track(uri='file:///dev/urandom')])] - self.sendRequest(u'listplaylist "name"') - self.assertInResponse(u'file: file:///dev/urandom') - self.assertInResponse(u'OK') + self.sendRequest('listplaylist "name"') + self.assertInResponse('file: file:///dev/urandom') + self.assertInResponse('OK') def test_listplaylist_without_quotes(self): self.backend.stored_playlists.playlists = [ Playlist(name='name', tracks=[Track(uri='file:///dev/urandom')])] - self.sendRequest(u'listplaylist name') - self.assertInResponse(u'file: file:///dev/urandom') - self.assertInResponse(u'OK') + self.sendRequest('listplaylist name') + self.assertInResponse('file: file:///dev/urandom') + self.assertInResponse('OK') def test_listplaylist_fails_if_no_playlist_is_found(self): - self.sendRequest(u'listplaylist "name"') - self.assertEqualResponse(u'ACK [50@0] {listplaylist} No such playlist') + self.sendRequest('listplaylist "name"') + self.assertEqualResponse('ACK [50@0] {listplaylist} No such playlist') def test_listplaylistinfo(self): self.backend.stored_playlists.playlists = [ Playlist(name='name', tracks=[Track(uri='file:///dev/urandom')])] - self.sendRequest(u'listplaylistinfo "name"') - self.assertInResponse(u'file: file:///dev/urandom') - self.assertInResponse(u'Track: 0') - self.assertNotInResponse(u'Pos: 0') - self.assertInResponse(u'OK') + self.sendRequest('listplaylistinfo "name"') + self.assertInResponse('file: file:///dev/urandom') + self.assertInResponse('Track: 0') + self.assertNotInResponse('Pos: 0') + self.assertInResponse('OK') def test_listplaylistinfo_without_quotes(self): self.backend.stored_playlists.playlists = [ Playlist(name='name', tracks=[Track(uri='file:///dev/urandom')])] - self.sendRequest(u'listplaylistinfo name') - self.assertInResponse(u'file: file:///dev/urandom') - self.assertInResponse(u'Track: 0') - self.assertNotInResponse(u'Pos: 0') - self.assertInResponse(u'OK') + self.sendRequest('listplaylistinfo name') + self.assertInResponse('file: file:///dev/urandom') + self.assertInResponse('Track: 0') + self.assertNotInResponse('Pos: 0') + self.assertInResponse('OK') def test_listplaylistinfo_fails_if_no_playlist_is_found(self): - self.sendRequest(u'listplaylistinfo "name"') + self.sendRequest('listplaylistinfo "name"') self.assertEqualResponse( - u'ACK [50@0] {listplaylistinfo} No such playlist') + 'ACK [50@0] {listplaylistinfo} No such playlist') def test_listplaylists(self): last_modified = datetime.datetime(2001, 3, 17, 13, 41, 17, 12345) self.backend.stored_playlists.playlists = [ Playlist(name='a', last_modified=last_modified)] - self.sendRequest(u'listplaylists') - self.assertInResponse(u'playlist: a') + self.sendRequest('listplaylists') + self.assertInResponse('playlist: a') # Date without microseconds and with time zone information - self.assertInResponse(u'Last-Modified: 2001-03-17T13:41:17Z') - self.assertInResponse(u'OK') + self.assertInResponse('Last-Modified: 2001-03-17T13:41:17Z') + self.assertInResponse('OK') def test_load_known_playlist_appends_to_current_playlist(self): self.core.current_playlist.append([Track(uri='a'), Track(uri='b')]) @@ -69,7 +71,7 @@ class StoredPlaylistsHandlerTest(protocol.BaseTestCase): Playlist(name='A-list', tracks=[ Track(uri='c'), Track(uri='d'), Track(uri='e')])] - self.sendRequest(u'load "A-list"') + self.sendRequest('load "A-list"') tracks = self.core.current_playlist.tracks.get() self.assertEqual(5, len(tracks)) self.assertEqual('a', tracks[0].uri) @@ -77,37 +79,37 @@ class StoredPlaylistsHandlerTest(protocol.BaseTestCase): self.assertEqual('c', tracks[2].uri) self.assertEqual('d', tracks[3].uri) self.assertEqual('e', tracks[4].uri) - self.assertInResponse(u'OK') + self.assertInResponse('OK') def test_load_unknown_playlist_acks(self): - self.sendRequest(u'load "unknown playlist"') + self.sendRequest('load "unknown playlist"') self.assertEqual(0, len(self.core.current_playlist.tracks.get())) - self.assertEqualResponse(u'ACK [50@0] {load} No such playlist') + self.assertEqualResponse('ACK [50@0] {load} No such playlist') def test_playlistadd(self): - self.sendRequest(u'playlistadd "name" "file:///dev/urandom"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('playlistadd "name" "file:///dev/urandom"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_playlistclear(self): - self.sendRequest(u'playlistclear "name"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('playlistclear "name"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_playlistdelete(self): - self.sendRequest(u'playlistdelete "name" "5"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('playlistdelete "name" "5"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_playlistmove(self): - self.sendRequest(u'playlistmove "name" "5" "10"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('playlistmove "name" "5" "10"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_rename(self): - self.sendRequest(u'rename "old_name" "new_name"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('rename "old_name" "new_name"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_rm(self): - self.sendRequest(u'rm "name"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('rm "name"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') def test_save(self): - self.sendRequest(u'save "name"') - self.assertEqualResponse(u'ACK [0@0] {} Not implemented') + self.sendRequest('save "name"') + self.assertEqualResponse('ACK [0@0] {} Not implemented') diff --git a/tests/frontends/mpd/serializer_test.py b/tests/frontends/mpd/serializer_test.py index 2d2a9f87..b1f59076 100644 --- a/tests/frontends/mpd/serializer_test.py +++ b/tests/frontends/mpd/serializer_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import datetime import os @@ -11,11 +13,11 @@ from tests import unittest class TrackMpdFormatTest(unittest.TestCase): track = Track( - uri=u'a uri', - artists=[Artist(name=u'an artist')], - name=u'a name', - album=Album(name=u'an album', num_tracks=13, - artists=[Artist(name=u'an other artist')]), + uri='a uri', + artists=[Artist(name='an artist')], + name='a name', + album=Album(name='an album', num_tracks=13, + artists=[Artist(name='an other artist')]), track_no=7, date=datetime.date(1977, 1, 1), length=137000, @@ -94,14 +96,14 @@ class TrackMpdFormatTest(unittest.TestCase): self.assertIn(('MUSICBRAINZ_ARTISTID', 'foo'), result) def test_artists_to_mpd_format(self): - artists = [Artist(name=u'ABBA'), Artist(name=u'Beatles')] + artists = [Artist(name='ABBA'), Artist(name='Beatles')] translated = translator.artists_to_mpd_format(artists) - self.assertEqual(translated, u'ABBA, Beatles') + self.assertEqual(translated, 'ABBA, Beatles') def test_artists_to_mpd_format_artist_with_no_name(self): artists = [Artist(name=None)] translated = translator.artists_to_mpd_format(artists) - self.assertEqual(translated, u'') + self.assertEqual(translated, '') class PlaylistMpdFormatTest(unittest.TestCase): diff --git a/tests/frontends/mpd/status_test.py b/tests/frontends/mpd/status_test.py index 9f2395e5..7d71b0bd 100644 --- a/tests/frontends/mpd/status_test.py +++ b/tests/frontends/mpd/status_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import pykka from mopidy import core diff --git a/tests/frontends/mpris/__init__.py b/tests/frontends/mpris/__init__.py index e69de29b..baffc488 100644 --- a/tests/frontends/mpris/__init__.py +++ b/tests/frontends/mpris/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/tests/frontends/mpris/events_test.py b/tests/frontends/mpris/events_test.py index a4efe344..94f48115 100644 --- a/tests/frontends/mpris/events_test.py +++ b/tests/frontends/mpris/events_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import sys import mock diff --git a/tests/frontends/mpris/player_interface_test.py b/tests/frontends/mpris/player_interface_test.py index 620845e4..6043551a 100644 --- a/tests/frontends/mpris/player_interface_test.py +++ b/tests/frontends/mpris/player_interface_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import sys import mock diff --git a/tests/frontends/mpris/root_interface_test.py b/tests/frontends/mpris/root_interface_test.py index 79a8b07f..9e16c6bb 100644 --- a/tests/frontends/mpris/root_interface_test.py +++ b/tests/frontends/mpris/root_interface_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import sys import mock diff --git a/tests/help_test.py b/tests/help_test.py index a2803b72..fdef0f52 100644 --- a/tests/help_test.py +++ b/tests/help_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import os import subprocess import sys diff --git a/tests/models_test.py b/tests/models_test.py index 004c0a28..b59ed0e4 100644 --- a/tests/models_test.py +++ b/tests/models_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import datetime from mopidy.models import Artist, Album, CpTrack, Track, Playlist @@ -52,19 +54,19 @@ class GenericCopyTets(unittest.TestCase): class ArtistTest(unittest.TestCase): def test_uri(self): - uri = u'an_uri' + uri = 'an_uri' artist = Artist(uri=uri) self.assertEqual(artist.uri, uri) self.assertRaises(AttributeError, setattr, artist, 'uri', None) def test_name(self): - name = u'a name' + name = 'a name' artist = Artist(name=name) self.assertEqual(artist.name, name) self.assertRaises(AttributeError, setattr, artist, 'name', None) def test_musicbrainz_id(self): - mb_id = u'mb-id' + mb_id = 'mb-id' artist = Artist(musicbrainz_id=mb_id) self.assertEqual(artist.musicbrainz_id, mb_id) self.assertRaises( @@ -76,7 +78,7 @@ class ArtistTest(unittest.TestCase): def test_repr(self): self.assertEquals( - "Artist(name='name', uri='uri')", + "Artist(name=u'name', uri=u'uri')", repr(Artist(uri='uri', name='name'))) def test_serialize(self): @@ -85,26 +87,26 @@ class ArtistTest(unittest.TestCase): Artist(uri='uri', name='name').serialize()) def test_eq_name(self): - artist1 = Artist(name=u'name') - artist2 = Artist(name=u'name') + artist1 = Artist(name='name') + artist2 = Artist(name='name') self.assertEqual(artist1, artist2) self.assertEqual(hash(artist1), hash(artist2)) def test_eq_uri(self): - artist1 = Artist(uri=u'uri') - artist2 = Artist(uri=u'uri') + artist1 = Artist(uri='uri') + artist2 = Artist(uri='uri') self.assertEqual(artist1, artist2) self.assertEqual(hash(artist1), hash(artist2)) def test_eq_musibrainz_id(self): - artist1 = Artist(musicbrainz_id=u'id') - artist2 = Artist(musicbrainz_id=u'id') + artist1 = Artist(musicbrainz_id='id') + artist2 = Artist(musicbrainz_id='id') self.assertEqual(artist1, artist2) self.assertEqual(hash(artist1), hash(artist2)) def test_eq(self): - artist1 = Artist(uri=u'uri', name=u'name', musicbrainz_id='id') - artist2 = Artist(uri=u'uri', name=u'name', musicbrainz_id='id') + artist1 = Artist(uri='uri', name='name', musicbrainz_id='id') + artist2 = Artist(uri='uri', name='name', musicbrainz_id='id') self.assertEqual(artist1, artist2) self.assertEqual(hash(artist1), hash(artist2)) @@ -115,39 +117,39 @@ class ArtistTest(unittest.TestCase): self.assertNotEqual(Artist(), 'other') def test_ne_name(self): - artist1 = Artist(name=u'name1') - artist2 = Artist(name=u'name2') + artist1 = Artist(name='name1') + artist2 = Artist(name='name2') self.assertNotEqual(artist1, artist2) self.assertNotEqual(hash(artist1), hash(artist2)) def test_ne_uri(self): - artist1 = Artist(uri=u'uri1') - artist2 = Artist(uri=u'uri2') + artist1 = Artist(uri='uri1') + artist2 = Artist(uri='uri2') self.assertNotEqual(artist1, artist2) self.assertNotEqual(hash(artist1), hash(artist2)) def test_ne_musicbrainz_id(self): - artist1 = Artist(musicbrainz_id=u'id1') - artist2 = Artist(musicbrainz_id=u'id2') + artist1 = Artist(musicbrainz_id='id1') + artist2 = Artist(musicbrainz_id='id2') self.assertNotEqual(artist1, artist2) self.assertNotEqual(hash(artist1), hash(artist2)) def test_ne(self): - artist1 = Artist(uri=u'uri1', name=u'name1', musicbrainz_id='id1') - artist2 = Artist(uri=u'uri2', name=u'name2', musicbrainz_id='id2') + artist1 = Artist(uri='uri1', name='name1', musicbrainz_id='id1') + artist2 = Artist(uri='uri2', name='name2', musicbrainz_id='id2') self.assertNotEqual(artist1, artist2) self.assertNotEqual(hash(artist1), hash(artist2)) class AlbumTest(unittest.TestCase): def test_uri(self): - uri = u'an_uri' + uri = 'an_uri' album = Album(uri=uri) self.assertEqual(album.uri, uri) self.assertRaises(AttributeError, setattr, album, 'uri', None) def test_name(self): - name = u'a name' + name = 'a name' album = Album(name=name) self.assertEqual(album.name, name) self.assertRaises(AttributeError, setattr, album, 'name', None) @@ -171,7 +173,7 @@ class AlbumTest(unittest.TestCase): self.assertRaises(AttributeError, setattr, album, 'date', None) def test_musicbrainz_id(self): - mb_id = u'mb-id' + mb_id = 'mb-id' album = Album(musicbrainz_id=mb_id) self.assertEqual(album.musicbrainz_id, mb_id) self.assertRaises( @@ -183,12 +185,12 @@ class AlbumTest(unittest.TestCase): def test_repr_without_artists(self): self.assertEquals( - "Album(artists=[], name='name', uri='uri')", + "Album(artists=[], name=u'name', uri=u'uri')", repr(Album(uri='uri', name='name'))) def test_repr_with_artists(self): self.assertEquals( - "Album(artists=[Artist(name='foo')], name='name', uri='uri')", + "Album(artists=[Artist(name=u'foo')], name=u'name', uri=u'uri')", repr(Album(uri='uri', name='name', artists=[Artist(name='foo')]))) def test_serialize_without_artists(self): @@ -203,14 +205,14 @@ class AlbumTest(unittest.TestCase): Album(uri='uri', name='name', artists=[artist]).serialize()) def test_eq_name(self): - album1 = Album(name=u'name') - album2 = Album(name=u'name') + album1 = Album(name='name') + album2 = Album(name='name') self.assertEqual(album1, album2) self.assertEqual(hash(album1), hash(album2)) def test_eq_uri(self): - album1 = Album(uri=u'uri') - album2 = Album(uri=u'uri') + album1 = Album(uri='uri') + album2 = Album(uri='uri') self.assertEqual(album1, album2) self.assertEqual(hash(album1), hash(album2)) @@ -222,8 +224,8 @@ class AlbumTest(unittest.TestCase): self.assertEqual(hash(album1), hash(album2)) def test_eq_artists_order(self): - artist1 = Artist(name=u'name1') - artist2 = Artist(name=u'name2') + artist1 = Artist(name='name1') + artist2 = Artist(name='name2') album1 = Album(artists=[artist1, artist2]) album2 = Album(artists=[artist2, artist1]) self.assertEqual(album1, album2) @@ -243,18 +245,18 @@ class AlbumTest(unittest.TestCase): self.assertEqual(hash(album1), hash(album2)) def test_eq_musibrainz_id(self): - album1 = Album(musicbrainz_id=u'id') - album2 = Album(musicbrainz_id=u'id') + album1 = Album(musicbrainz_id='id') + album2 = Album(musicbrainz_id='id') self.assertEqual(album1, album2) self.assertEqual(hash(album1), hash(album2)) def test_eq(self): artists = [Artist()] album1 = Album( - name=u'name', uri=u'uri', artists=artists, num_tracks=2, + name='name', uri='uri', artists=artists, num_tracks=2, musicbrainz_id='id') album2 = Album( - name=u'name', uri=u'uri', artists=artists, num_tracks=2, + name='name', uri='uri', artists=artists, num_tracks=2, musicbrainz_id='id') self.assertEqual(album1, album2) self.assertEqual(hash(album1), hash(album2)) @@ -266,20 +268,20 @@ class AlbumTest(unittest.TestCase): self.assertNotEqual(Album(), 'other') def test_ne_name(self): - album1 = Album(name=u'name1') - album2 = Album(name=u'name2') + album1 = Album(name='name1') + album2 = Album(name='name2') self.assertNotEqual(album1, album2) self.assertNotEqual(hash(album1), hash(album2)) def test_ne_uri(self): - album1 = Album(uri=u'uri1') - album2 = Album(uri=u'uri2') + album1 = Album(uri='uri1') + album2 = Album(uri='uri2') self.assertNotEqual(album1, album2) self.assertNotEqual(hash(album1), hash(album2)) def test_ne_artists(self): - album1 = Album(artists=[Artist(name=u'name1')]) - album2 = Album(artists=[Artist(name=u'name2')]) + album1 = Album(artists=[Artist(name='name1')]) + album2 = Album(artists=[Artist(name='name2')]) self.assertNotEqual(album1, album2) self.assertNotEqual(hash(album1), hash(album2)) @@ -296,17 +298,17 @@ class AlbumTest(unittest.TestCase): self.assertNotEqual(hash(album1), hash(album2)) def test_ne_musicbrainz_id(self): - album1 = Album(musicbrainz_id=u'id1') - album2 = Album(musicbrainz_id=u'id2') + album1 = Album(musicbrainz_id='id1') + album2 = Album(musicbrainz_id='id2') self.assertNotEqual(album1, album2) self.assertNotEqual(hash(album1), hash(album2)) def test_ne(self): album1 = Album( - name=u'name1', uri=u'uri1', artists=[Artist(name=u'name1')], + name='name1', uri='uri1', artists=[Artist(name='name1')], num_tracks=1, musicbrainz_id='id1') album2 = Album( - name=u'name2', uri=u'uri2', artists=[Artist(name=u'name2')], + name='name2', uri='uri2', artists=[Artist(name='name2')], num_tracks=2, musicbrainz_id='id2') self.assertNotEqual(album1, album2) self.assertNotEqual(hash(album1), hash(album2)) @@ -329,19 +331,19 @@ class CpTrackTest(unittest.TestCase): class TrackTest(unittest.TestCase): def test_uri(self): - uri = u'an_uri' + uri = 'an_uri' track = Track(uri=uri) self.assertEqual(track.uri, uri) self.assertRaises(AttributeError, setattr, track, 'uri', None) def test_name(self): - name = u'a name' + name = 'a name' track = Track(name=name) self.assertEqual(track.name, name) self.assertRaises(AttributeError, setattr, track, 'name', None) def test_artists(self): - artists = [Artist(name=u'name1'), Artist(name=u'name2')] + artists = [Artist(name='name1'), Artist(name='name2')] track = Track(artists=artists) self.assertEqual(set(track.artists), set(artists)) self.assertRaises(AttributeError, setattr, track, 'artists', None) @@ -377,7 +379,7 @@ class TrackTest(unittest.TestCase): self.assertRaises(AttributeError, setattr, track, 'bitrate', None) def test_musicbrainz_id(self): - mb_id = u'mb-id' + mb_id = 'mb-id' track = Track(musicbrainz_id=mb_id) self.assertEqual(track.musicbrainz_id, mb_id) self.assertRaises( @@ -389,12 +391,12 @@ class TrackTest(unittest.TestCase): def test_repr_without_artists(self): self.assertEquals( - "Track(artists=[], name='name', uri='uri')", + "Track(artists=[], name=u'name', uri=u'uri')", repr(Track(uri='uri', name='name'))) def test_repr_with_artists(self): self.assertEquals( - "Track(artists=[Artist(name='foo')], name='name', uri='uri')", + "Track(artists=[Artist(name=u'foo')], name=u'name', uri=u'uri')", repr(Track(uri='uri', name='name', artists=[Artist(name='foo')]))) def test_serialize_without_artists(self): @@ -415,14 +417,14 @@ class TrackTest(unittest.TestCase): Track(uri='uri', name='name', album=album).serialize()) def test_eq_uri(self): - track1 = Track(uri=u'uri1') - track2 = Track(uri=u'uri1') + track1 = Track(uri='uri1') + track2 = Track(uri='uri1') self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2)) def test_eq_name(self): - track1 = Track(name=u'name1') - track2 = Track(name=u'name1') + track1 = Track(name='name1') + track2 = Track(name='name1') self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2)) @@ -434,8 +436,8 @@ class TrackTest(unittest.TestCase): self.assertEqual(hash(track1), hash(track2)) def test_eq_artists_order(self): - artist1 = Artist(name=u'name1') - artist2 = Artist(name=u'name2') + artist1 = Artist(name='name1') + artist2 = Artist(name='name2') track1 = Track(artists=[artist1, artist2]) track2 = Track(artists=[artist2, artist1]) self.assertEqual(track1, track2) @@ -474,8 +476,8 @@ class TrackTest(unittest.TestCase): self.assertEqual(hash(track1), hash(track2)) def test_eq_musibrainz_id(self): - track1 = Track(musicbrainz_id=u'id') - track2 = Track(musicbrainz_id=u'id') + track1 = Track(musicbrainz_id='id') + track2 = Track(musicbrainz_id='id') self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2)) @@ -484,10 +486,10 @@ class TrackTest(unittest.TestCase): artists = [Artist()] album = Album() track1 = Track( - uri=u'uri', name=u'name', artists=artists, album=album, track_no=1, + uri='uri', name='name', artists=artists, album=album, track_no=1, date=date, length=100, bitrate=100, musicbrainz_id='id') track2 = Track( - uri=u'uri', name=u'name', artists=artists, album=album, track_no=1, + uri='uri', name='name', artists=artists, album=album, track_no=1, date=date, length=100, bitrate=100, musicbrainz_id='id') self.assertEqual(track1, track2) self.assertEqual(hash(track1), hash(track2)) @@ -499,26 +501,26 @@ class TrackTest(unittest.TestCase): self.assertNotEqual(Track(), 'other') def test_ne_uri(self): - track1 = Track(uri=u'uri1') - track2 = Track(uri=u'uri2') + track1 = Track(uri='uri1') + track2 = Track(uri='uri2') self.assertNotEqual(track1, track2) self.assertNotEqual(hash(track1), hash(track2)) def test_ne_name(self): - track1 = Track(name=u'name1') - track2 = Track(name=u'name2') + track1 = Track(name='name1') + track2 = Track(name='name2') self.assertNotEqual(track1, track2) self.assertNotEqual(hash(track1), hash(track2)) def test_ne_artists(self): - track1 = Track(artists=[Artist(name=u'name1')]) - track2 = Track(artists=[Artist(name=u'name2')]) + track1 = Track(artists=[Artist(name='name1')]) + track2 = Track(artists=[Artist(name='name2')]) self.assertNotEqual(track1, track2) self.assertNotEqual(hash(track1), hash(track2)) def test_ne_album(self): - track1 = Track(album=Album(name=u'name1')) - track2 = Track(album=Album(name=u'name2')) + track1 = Track(album=Album(name='name1')) + track2 = Track(album=Album(name='name2')) self.assertNotEqual(track1, track2) self.assertNotEqual(hash(track1), hash(track2)) @@ -547,19 +549,19 @@ class TrackTest(unittest.TestCase): self.assertNotEqual(hash(track1), hash(track2)) def test_ne_musicbrainz_id(self): - track1 = Track(musicbrainz_id=u'id1') - track2 = Track(musicbrainz_id=u'id2') + track1 = Track(musicbrainz_id='id1') + track2 = Track(musicbrainz_id='id2') self.assertNotEqual(track1, track2) self.assertNotEqual(hash(track1), hash(track2)) def test_ne(self): track1 = Track( - uri=u'uri1', name=u'name1', artists=[Artist(name=u'name1')], - album=Album(name=u'name1'), track_no=1, date='1977-01-01', + uri='uri1', name='name1', artists=[Artist(name='name1')], + album=Album(name='name1'), track_no=1, date='1977-01-01', length=100, bitrate=100, musicbrainz_id='id1') track2 = Track( - uri=u'uri2', name=u'name2', artists=[Artist(name=u'name2')], - album=Album(name=u'name2'), track_no=2, date='1977-01-02', + uri='uri2', name='name2', artists=[Artist(name='name2')], + album=Album(name='name2'), track_no=2, date='1977-01-02', length=200, bitrate=200, musicbrainz_id='id2') self.assertNotEqual(track1, track2) self.assertNotEqual(hash(track1), hash(track2)) @@ -567,13 +569,13 @@ class TrackTest(unittest.TestCase): class PlaylistTest(unittest.TestCase): def test_uri(self): - uri = u'an_uri' + uri = 'an_uri' playlist = Playlist(uri=uri) self.assertEqual(playlist.uri, uri) self.assertRaises(AttributeError, setattr, playlist, 'uri', None) def test_name(self): - name = u'a name' + name = 'a name' playlist = Playlist(name=name) self.assertEqual(playlist.name, name) self.assertRaises(AttributeError, setattr, playlist, 'name', None) @@ -600,11 +602,11 @@ class PlaylistTest(unittest.TestCase): tracks = [Track()] last_modified = datetime.datetime.now() playlist = Playlist( - uri=u'an uri', name=u'a name', tracks=tracks, + uri='an uri', name='a name', tracks=tracks, last_modified=last_modified) - new_playlist = playlist.copy(uri=u'another uri') - self.assertEqual(new_playlist.uri, u'another uri') - self.assertEqual(new_playlist.name, u'a name') + new_playlist = playlist.copy(uri='another uri') + self.assertEqual(new_playlist.uri, 'another uri') + self.assertEqual(new_playlist.name, 'a name') self.assertEqual(list(new_playlist.tracks), tracks) self.assertEqual(new_playlist.last_modified, last_modified) @@ -612,11 +614,11 @@ class PlaylistTest(unittest.TestCase): tracks = [Track()] last_modified = datetime.datetime.now() playlist = Playlist( - uri=u'an uri', name=u'a name', tracks=tracks, + uri='an uri', name='a name', tracks=tracks, last_modified=last_modified) - new_playlist = playlist.copy(name=u'another name') - self.assertEqual(new_playlist.uri, u'an uri') - self.assertEqual(new_playlist.name, u'another name') + new_playlist = playlist.copy(name='another name') + self.assertEqual(new_playlist.uri, 'an uri') + self.assertEqual(new_playlist.name, 'another name') self.assertEqual(list(new_playlist.tracks), tracks) self.assertEqual(new_playlist.last_modified, last_modified) @@ -624,12 +626,12 @@ class PlaylistTest(unittest.TestCase): tracks = [Track()] last_modified = datetime.datetime.now() playlist = Playlist( - uri=u'an uri', name=u'a name', tracks=tracks, + uri='an uri', name='a name', tracks=tracks, last_modified=last_modified) new_tracks = [Track(), Track()] new_playlist = playlist.copy(tracks=new_tracks) - self.assertEqual(new_playlist.uri, u'an uri') - self.assertEqual(new_playlist.name, u'a name') + self.assertEqual(new_playlist.uri, 'an uri') + self.assertEqual(new_playlist.name, 'a name') self.assertEqual(list(new_playlist.tracks), new_tracks) self.assertEqual(new_playlist.last_modified, last_modified) @@ -638,11 +640,11 @@ class PlaylistTest(unittest.TestCase): last_modified = datetime.datetime.now() new_last_modified = last_modified + datetime.timedelta(1) playlist = Playlist( - uri=u'an uri', name=u'a name', tracks=tracks, + uri='an uri', name='a name', tracks=tracks, last_modified=last_modified) new_playlist = playlist.copy(last_modified=new_last_modified) - self.assertEqual(new_playlist.uri, u'an uri') - self.assertEqual(new_playlist.name, u'a name') + self.assertEqual(new_playlist.uri, 'an uri') + self.assertEqual(new_playlist.name, 'a name') self.assertEqual(list(new_playlist.tracks), tracks) self.assertEqual(new_playlist.last_modified, new_last_modified) @@ -652,13 +654,13 @@ class PlaylistTest(unittest.TestCase): def test_repr_without_tracks(self): self.assertEquals( - "Playlist(name='name', tracks=[], uri='uri')", + "Playlist(name=u'name', tracks=[], uri=u'uri')", repr(Playlist(uri='uri', name='name'))) def test_repr_with_tracks(self): self.assertEquals( - "Playlist(name='name', tracks=[Track(artists=[], name='foo')], " - "uri='uri')", + "Playlist(name=u'name', tracks=[Track(artists=[], name=u'foo')], " + "uri=u'uri')", repr(Playlist(uri='uri', name='name', tracks=[Track(name='foo')]))) def test_serialize_without_tracks(self): @@ -673,14 +675,14 @@ class PlaylistTest(unittest.TestCase): Playlist(uri='uri', name='name', tracks=[track]).serialize()) def test_eq_name(self): - playlist1 = Playlist(name=u'name') - playlist2 = Playlist(name=u'name') + playlist1 = Playlist(name='name') + playlist2 = Playlist(name='name') self.assertEqual(playlist1, playlist2) self.assertEqual(hash(playlist1), hash(playlist2)) def test_eq_uri(self): - playlist1 = Playlist(uri=u'uri') - playlist2 = Playlist(uri=u'uri') + playlist1 = Playlist(uri='uri') + playlist2 = Playlist(uri='uri') self.assertEqual(playlist1, playlist2) self.assertEqual(hash(playlist1), hash(playlist2)) @@ -700,9 +702,9 @@ class PlaylistTest(unittest.TestCase): def test_eq(self): tracks = [Track()] playlist1 = Playlist( - uri=u'uri', name=u'name', tracks=tracks, last_modified=1) + uri='uri', name='name', tracks=tracks, last_modified=1) playlist2 = Playlist( - uri=u'uri', name=u'name', tracks=tracks, last_modified=1) + uri='uri', name='name', tracks=tracks, last_modified=1) self.assertEqual(playlist1, playlist2) self.assertEqual(hash(playlist1), hash(playlist2)) @@ -713,20 +715,20 @@ class PlaylistTest(unittest.TestCase): self.assertNotEqual(Playlist(), 'other') def test_ne_name(self): - playlist1 = Playlist(name=u'name1') - playlist2 = Playlist(name=u'name2') + playlist1 = Playlist(name='name1') + playlist2 = Playlist(name='name2') self.assertNotEqual(playlist1, playlist2) self.assertNotEqual(hash(playlist1), hash(playlist2)) def test_ne_uri(self): - playlist1 = Playlist(uri=u'uri1') - playlist2 = Playlist(uri=u'uri2') + playlist1 = Playlist(uri='uri1') + playlist2 = Playlist(uri='uri2') self.assertNotEqual(playlist1, playlist2) self.assertNotEqual(hash(playlist1), hash(playlist2)) def test_ne_tracks(self): - playlist1 = Playlist(tracks=[Track(uri=u'uri1')]) - playlist2 = Playlist(tracks=[Track(uri=u'uri2')]) + playlist1 = Playlist(tracks=[Track(uri='uri1')]) + playlist2 = Playlist(tracks=[Track(uri='uri2')]) self.assertNotEqual(playlist1, playlist2) self.assertNotEqual(hash(playlist1), hash(playlist2)) @@ -738,10 +740,10 @@ class PlaylistTest(unittest.TestCase): def test_ne(self): playlist1 = Playlist( - uri=u'uri1', name=u'name2', tracks=[Track(uri=u'uri1')], + uri='uri1', name='name2', tracks=[Track(uri='uri1')], last_modified=1) playlist2 = Playlist( - uri=u'uri2', name=u'name2', tracks=[Track(uri=u'uri2')], + uri='uri2', name='name2', tracks=[Track(uri='uri2')], last_modified=2) self.assertNotEqual(playlist1, playlist2) self.assertNotEqual(hash(playlist1), hash(playlist2)) diff --git a/tests/outputs/__init__.py b/tests/outputs/__init__.py index e69de29b..baffc488 100644 --- a/tests/outputs/__init__.py +++ b/tests/outputs/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/tests/scanner_test.py b/tests/scanner_test.py index 6af48bb5..08784458 100644 --- a/tests/scanner_test.py +++ b/tests/scanner_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from datetime import date from mopidy.scanner import Scanner, translator @@ -17,14 +19,14 @@ class TranslatorTest(unittest.TestCase): def setUp(self): self.data = { 'uri': 'uri', - 'album': u'albumname', + 'album': 'albumname', 'track-number': 1, - 'artist': u'name', + 'artist': 'name', 'album-artist': 'albumartistname', - 'title': u'trackname', + 'title': 'trackname', 'track-count': 2, 'date': FakeGstDate(2006, 1, 1,), - 'container-format': u'ID3 tag', + 'container-format': 'ID3 tag', 'duration': 4531, 'musicbrainz-trackid': 'mbtrackid', 'musicbrainz-albumid': 'mbalbumid', diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py index e69de29b..baffc488 100644 --- a/tests/utils/__init__.py +++ b/tests/utils/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/tests/utils/deps_test.py b/tests/utils/deps_test.py index 42c8b299..168f98e5 100644 --- a/tests/utils/deps_test.py +++ b/tests/utils/deps_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import platform import pygst diff --git a/tests/utils/encoding_test.py b/tests/utils/encoding_test.py index da50d9be..1a4e56c5 100644 --- a/tests/utils/encoding_test.py +++ b/tests/utils/encoding_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import mock from mopidy.utils.encoding import locale_decode @@ -11,22 +13,22 @@ class LocaleDecodeTest(unittest.TestCase): mock.return_value = 'UTF-8' result = locale_decode( - '[Errno 98] Adresse d\xc3\xa9j\xc3\xa0 utilis\xc3\xa9e') + b'[Errno 98] Adresse d\xc3\xa9j\xc3\xa0 utilis\xc3\xa9e') - self.assertEquals(u'[Errno 98] Adresse d\xe9j\xe0 utilis\xe9e', result) + self.assertEquals('[Errno 98] Adresse d\xe9j\xe0 utilis\xe9e', result) def test_can_decode_an_ioerror_with_french_content(self, mock): mock.return_value = 'UTF-8' - error = IOError(98, 'Adresse d\xc3\xa9j\xc3\xa0 utilis\xc3\xa9e') + error = IOError(98, b'Adresse d\xc3\xa9j\xc3\xa0 utilis\xc3\xa9e') result = locale_decode(error) - self.assertEquals(u'[Errno 98] Adresse d\xe9j\xe0 utilis\xe9e', result) + self.assertEquals('[Errno 98] Adresse d\xe9j\xe0 utilis\xe9e', result) def test_does_not_use_locale_to_decode_unicode_strings(self, mock): mock.return_value = 'UTF-8' - locale_decode(u'abc') + locale_decode('abc') self.assertFalse(mock.called) diff --git a/tests/utils/importing_test.py b/tests/utils/importing_test.py index 271f9dbe..5be4078b 100644 --- a/tests/utils/importing_test.py +++ b/tests/utils/importing_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from mopidy.utils import importing from tests import unittest diff --git a/tests/utils/network/__init__.py b/tests/utils/network/__init__.py index e69de29b..baffc488 100644 --- a/tests/utils/network/__init__.py +++ b/tests/utils/network/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/tests/utils/network/connection_test.py b/tests/utils/network/connection_test.py index c9fe9a05..3e63cdfc 100644 --- a/tests/utils/network/connection_test.py +++ b/tests/utils/network/connection_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import errno import gobject import logging diff --git a/tests/utils/network/lineprotocol_test.py b/tests/utils/network/lineprotocol_test.py index 9a19e12e..530c708c 100644 --- a/tests/utils/network/lineprotocol_test.py +++ b/tests/utils/network/lineprotocol_test.py @@ -1,4 +1,6 @@ -#encoding: utf-8 +# encoding: utf-8 + +from __future__ import unicode_literals import re from mock import sentinel, Mock @@ -159,10 +161,10 @@ class LineProtocolTest(unittest.TestCase): def test_parse_lines_unicode(self): self.mock.delimiter = re.compile(r'\n') - self.mock.recv_buffer = u'æøå\n'.encode('utf-8') + self.mock.recv_buffer = 'æøå\n'.encode('utf-8') lines = network.LineProtocol.parse_lines(self.mock) - self.assertEqual(u'æøå'.encode('utf-8'), lines.next()) + self.assertEqual('æøå'.encode('utf-8'), lines.next()) self.assertRaises(StopIteration, lines.next) self.assertEqual('', self.mock.recv_buffer) @@ -208,10 +210,10 @@ class LineProtocolTest(unittest.TestCase): def test_send_line_encodes_joined_lines_with_final_terminator(self): self.mock.connection = Mock(spec=network.Connection) - self.mock.join_lines.return_value = u'lines\n' + self.mock.join_lines.return_value = 'lines\n' network.LineProtocol.send_lines(self.mock, sentinel.lines) - self.mock.encode.assert_called_once_with(u'lines\n') + self.mock.encode.assert_called_once_with('lines\n') def test_send_lines_sends_encoded_string(self): self.mock.connection = Mock(spec=network.Connection) @@ -222,11 +224,11 @@ class LineProtocolTest(unittest.TestCase): self.mock.connection.queue_send.assert_called_once_with(sentinel.data) def test_join_lines_returns_empty_string_for_no_lines(self): - self.assertEqual(u'', network.LineProtocol.join_lines(self.mock, [])) + self.assertEqual('', network.LineProtocol.join_lines(self.mock, [])) def test_join_lines_returns_joined_lines(self): - self.assertEqual(u'1\n2\n', network.LineProtocol.join_lines( - self.mock, [u'1', u'2'])) + self.assertEqual('1\n2\n', network.LineProtocol.join_lines( + self.mock, ['1', '2'])) def test_decode_calls_decode_on_string(self): string = Mock() @@ -236,13 +238,13 @@ class LineProtocolTest(unittest.TestCase): def test_decode_plain_ascii(self): result = network.LineProtocol.decode(self.mock, 'abc') - self.assertEqual(u'abc', result) + self.assertEqual('abc', result) self.assertEqual(unicode, type(result)) def test_decode_utf8(self): result = network.LineProtocol.decode( - self.mock, u'æøå'.encode('utf-8')) - self.assertEqual(u'æøå', result) + self.mock, 'æøå'.encode('utf-8')) + self.assertEqual('æøå', result) self.assertEqual(unicode, type(result)) def test_decode_invalid_data(self): @@ -259,13 +261,13 @@ class LineProtocolTest(unittest.TestCase): string.encode.assert_called_once_with(self.mock.encoding) def test_encode_plain_ascii(self): - result = network.LineProtocol.encode(self.mock, u'abc') + result = network.LineProtocol.encode(self.mock, 'abc') self.assertEqual('abc', result) self.assertEqual(str, type(result)) def test_encode_utf8(self): - result = network.LineProtocol.encode(self.mock, u'æøå') - self.assertEqual(u'æøå'.encode('utf-8'), result) + result = network.LineProtocol.encode(self.mock, 'æøå') + self.assertEqual('æøå'.encode('utf-8'), result) self.assertEqual(str, type(result)) def test_encode_invalid_data(self): diff --git a/tests/utils/network/server_test.py b/tests/utils/network/server_test.py index 6090077d..3f7da337 100644 --- a/tests/utils/network/server_test.py +++ b/tests/utils/network/server_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import errno import gobject import socket diff --git a/tests/utils/network/utils_test.py b/tests/utils/network/utils_test.py index f28aeb4b..ff8af9bd 100644 --- a/tests/utils/network/utils_test.py +++ b/tests/utils/network/utils_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import socket from mock import patch, Mock diff --git a/tests/utils/path_test.py b/tests/utils/path_test.py index 91951ac7..512a3ba1 100644 --- a/tests/utils/path_test.py +++ b/tests/utils/path_test.py @@ -1,5 +1,7 @@ # encoding: utf-8 +from __future__ import unicode_literals + import glib import os import shutil @@ -58,61 +60,61 @@ class GetOrCreateFolderTest(unittest.TestCase): class PathToFileURITest(unittest.TestCase): def test_simple_path(self): if sys.platform == 'win32': - result = path.path_to_uri(u'C:/WINDOWS/clock.avi') + result = path.path_to_uri('C:/WINDOWS/clock.avi') self.assertEqual(result, 'file:///C://WINDOWS/clock.avi') else: - result = path.path_to_uri(u'/etc/fstab') + result = path.path_to_uri('/etc/fstab') self.assertEqual(result, 'file:///etc/fstab') def test_folder_and_path(self): if sys.platform == 'win32': - result = path.path_to_uri(u'C:/WINDOWS/', u'clock.avi') + result = path.path_to_uri('C:/WINDOWS/', 'clock.avi') self.assertEqual(result, 'file:///C://WINDOWS/clock.avi') else: - result = path.path_to_uri(u'/etc', u'fstab') - self.assertEqual(result, u'file:///etc/fstab') + result = path.path_to_uri('/etc', 'fstab') + self.assertEqual(result, 'file:///etc/fstab') def test_space_in_path(self): if sys.platform == 'win32': - result = path.path_to_uri(u'C:/test this') + result = path.path_to_uri('C:/test this') self.assertEqual(result, 'file:///C://test%20this') else: - result = path.path_to_uri(u'/tmp/test this') - self.assertEqual(result, u'file:///tmp/test%20this') + result = path.path_to_uri('/tmp/test this') + self.assertEqual(result, 'file:///tmp/test%20this') def test_unicode_in_path(self): if sys.platform == 'win32': - result = path.path_to_uri(u'C:/æøå') + result = path.path_to_uri('C:/æøå') self.assertEqual(result, 'file:///C://%C3%A6%C3%B8%C3%A5') else: - result = path.path_to_uri(u'/tmp/æøå') - self.assertEqual(result, u'file:///tmp/%C3%A6%C3%B8%C3%A5') + result = path.path_to_uri('/tmp/æøå') + self.assertEqual(result, 'file:///tmp/%C3%A6%C3%B8%C3%A5') class UriToPathTest(unittest.TestCase): def test_simple_uri(self): if sys.platform == 'win32': result = path.uri_to_path('file:///C://WINDOWS/clock.avi') - self.assertEqual(result, u'C:/WINDOWS/clock.avi') + self.assertEqual(result, 'C:/WINDOWS/clock.avi') else: result = path.uri_to_path('file:///etc/fstab') - self.assertEqual(result, u'/etc/fstab') + self.assertEqual(result, '/etc/fstab') def test_space_in_uri(self): if sys.platform == 'win32': result = path.uri_to_path('file:///C://test%20this') - self.assertEqual(result, u'C:/test this') + self.assertEqual(result, 'C:/test this') else: - result = path.uri_to_path(u'file:///tmp/test%20this') - self.assertEqual(result, u'/tmp/test this') + result = path.uri_to_path('file:///tmp/test%20this') + self.assertEqual(result, '/tmp/test this') def test_unicode_in_uri(self): if sys.platform == 'win32': result = path.uri_to_path('file:///C://%C3%A6%C3%B8%C3%A5') - self.assertEqual(result, u'C:/æøå') + self.assertEqual(result, 'C:/æøå') else: - result = path.uri_to_path(u'file:///tmp/%C3%A6%C3%B8%C3%A5') - self.assertEqual(result, u'/tmp/æøå') + result = path.uri_to_path('file:///tmp/%C3%A6%C3%B8%C3%A5') + self.assertEqual(result, '/tmp/æøå') class SplitPathTest(unittest.TestCase): diff --git a/tests/utils/settings_test.py b/tests/utils/settings_test.py index c98527cd..0362dee3 100644 --- a/tests/utils/settings_test.py +++ b/tests/utils/settings_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import os from mopidy import exceptions, settings @@ -25,29 +27,29 @@ class ValidateSettingsTest(unittest.TestCase): self.defaults, {'MPD_SERVER_HOSTNMAE': '127.0.0.1'}) self.assertEqual( result['MPD_SERVER_HOSTNMAE'], - u'Unknown setting. Did you mean MPD_SERVER_HOSTNAME?') + 'Unknown setting. Did you mean MPD_SERVER_HOSTNAME?') def test_not_renamed_setting_returns_error(self): result = setting_utils.validate_settings( self.defaults, {'SERVER_HOSTNAME': '127.0.0.1'}) self.assertEqual( result['SERVER_HOSTNAME'], - u'Deprecated setting. Use MPD_SERVER_HOSTNAME.') + 'Deprecated setting. Use MPD_SERVER_HOSTNAME.') def test_unneeded_settings_returns_error(self): result = setting_utils.validate_settings( self.defaults, {'SPOTIFY_LIB_APPKEY': '/tmp/foo'}) self.assertEqual( result['SPOTIFY_LIB_APPKEY'], - u'Deprecated setting. It may be removed.') + 'Deprecated setting. It may be removed.') def test_unavailable_bitrate_setting_returns_error(self): result = setting_utils.validate_settings( self.defaults, {'SPOTIFY_BITRATE': 50}) self.assertEqual( result['SPOTIFY_BITRATE'], - u'Unavailable Spotify bitrate. ' - u'Available bitrates are 96, 160, and 320.') + 'Unavailable Spotify bitrate. ' + 'Available bitrates are 96, 160, and 320.') def test_two_errors_are_both_reported(self): result = setting_utils.validate_settings( @@ -56,7 +58,7 @@ class ValidateSettingsTest(unittest.TestCase): def test_masks_value_if_secret(self): secret = setting_utils.mask_value_if_secret('SPOTIFY_PASSWORD', 'bar') - self.assertEqual(u'********', secret) + self.assertEqual('********', secret) def test_does_not_mask_value_if_not_secret(self): not_secret = setting_utils.mask_value_if_secret( @@ -72,13 +74,13 @@ class ValidateSettingsTest(unittest.TestCase): result = setting_utils.validate_settings( self.defaults, {'FRONTENDS': []}) self.assertEqual( - result['FRONTENDS'], u'Must contain at least one value.') + result['FRONTENDS'], 'Must contain at least one value.') def test_empty_backends_list_returns_error(self): result = setting_utils.validate_settings( self.defaults, {'BACKENDS': []}) self.assertEqual( - result['BACKENDS'], u'Must contain at least one value.') + result['BACKENDS'], 'Must contain at least one value.') class SettingsProxyTest(unittest.TestCase): @@ -93,17 +95,17 @@ class SettingsProxyTest(unittest.TestCase): def test_getattr_raises_error_on_missing_setting(self): try: self.settings.TEST - self.fail(u'Should raise exception') + self.fail('Should raise exception') except exceptions.SettingsError as e: - self.assertEqual(u'Setting "TEST" is not set.', e.message) + self.assertEqual('Setting "TEST" is not set.', e.message) def test_getattr_raises_error_on_empty_setting(self): - self.settings.TEST = u'' + self.settings.TEST = '' try: self.settings.TEST - self.fail(u'Should raise exception') + self.fail('Should raise exception') except exceptions.SettingsError as e: - self.assertEqual(u'Setting "TEST" is empty.', e.message) + self.assertEqual('Setting "TEST" is empty.', e.message) def test_getattr_does_not_raise_error_if_setting_is_false(self): self.settings.TEST = False @@ -191,12 +193,12 @@ class FormatSettingListTest(unittest.TestCase): self.settings = setting_utils.SettingsProxy(settings) def test_contains_the_setting_name(self): - self.settings.TEST = u'test' + self.settings.TEST = 'test' result = setting_utils.format_settings_list(self.settings) self.assertIn('TEST:', result, result) def test_repr_of_a_string_value(self): - self.settings.TEST = u'test' + self.settings.TEST = 'test' result = setting_utils.format_settings_list(self.settings) self.assertIn("TEST: u'test'", result, result) @@ -206,18 +208,18 @@ class FormatSettingListTest(unittest.TestCase): self.assertIn("TEST: 123", result, result) def test_repr_of_a_tuple_value(self): - self.settings.TEST = (123, u'abc') + self.settings.TEST = (123, 'abc') result = setting_utils.format_settings_list(self.settings) self.assertIn("TEST: (123, u'abc')", result, result) def test_passwords_are_masked(self): - self.settings.TEST_PASSWORD = u'secret' + self.settings.TEST_PASSWORD = 'secret' result = setting_utils.format_settings_list(self.settings) self.assertNotIn("TEST_PASSWORD: u'secret'", result, result) self.assertIn("TEST_PASSWORD: u'********'", result, result) def test_short_values_are_not_pretty_printed(self): - self.settings.FRONTEND = (u'mopidy.frontends.mpd.MpdFrontend',) + self.settings.FRONTEND = ('mopidy.frontends.mpd.MpdFrontend',) result = setting_utils.format_settings_list(self.settings) self.assertIn( "FRONTEND: (u'mopidy.frontends.mpd.MpdFrontend',)", result) diff --git a/tests/version_test.py b/tests/version_test.py index 2689a716..978660b0 100644 --- a/tests/version_test.py +++ b/tests/version_test.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from distutils.version import StrictVersion as SV from mopidy import __version__ diff --git a/tools/debug-proxy.py b/tools/debug-proxy.py index 4fb39b5b..938afa57 100755 --- a/tools/debug-proxy.py +++ b/tools/debug-proxy.py @@ -1,5 +1,7 @@ #! /usr/bin/env python +from __future__ import unicode_literals + import argparse import difflib import sys diff --git a/tools/idle.py b/tools/idle.py index fc9cb021..122e998d 100644 --- a/tools/idle.py +++ b/tools/idle.py @@ -3,6 +3,8 @@ # This script is helper to systematicly test the behaviour of MPD's idle # command. It is simply provided as a quick hack, expect nothing more. +from __future__ import unicode_literals + import logging import pprint import socket