Import unicode_literals in beets package

This commit is contained in:
Bruno Cauet 2015-01-19 15:43:17 +01:00
parent 6fff7a954c
commit 2dab8e5fd6
16 changed files with 106 additions and 91 deletions

View file

@ -12,7 +12,7 @@
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
from __future__ import division, absolute_import, print_function
from __future__ import absolute_import, unicode_literals
__version__ = '1.3.11'
__author__ = 'Adrian Sampson <adrian@radbox.org>'

View file

@ -12,7 +12,8 @@
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
"""Provides the basic, interface-agnostic workflow for importing and
autotagging music files.

View file

@ -14,7 +14,8 @@
"""The core data store and collection logic for beets.
"""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import os
import sys
@ -44,7 +45,7 @@ class PathQuery(dbcore.FieldQuery):
"""A query that matches all items under a given path."""
escape_re = re.compile(r'[\\_%]')
escape_char = '\\'
escape_char = b'\\'
def __init__(self, field, pattern, fast=True):
super(PathQuery, self).__init__(field, pattern, fast)
@ -52,7 +53,7 @@ class PathQuery(dbcore.FieldQuery):
# Match the path as a single file.
self.file_path = util.bytestring_path(util.normpath(pattern))
# As a directory (prefix).
self.dir_path = util.bytestring_path(os.path.join(self.file_path, ''))
self.dir_path = util.bytestring_path(os.path.join(self.file_path, b''))
def match(self, item):
return (item.path == self.file_path) or \
@ -61,7 +62,7 @@ class PathQuery(dbcore.FieldQuery):
def clause(self):
escape = lambda m: self.escape_char + m.group(0)
dir_pattern = self.escape_re.sub(escape, self.dir_path)
dir_pattern = buffer(dir_pattern + '%')
dir_pattern = buffer(dir_pattern + b'%')
file_blob = buffer(self.file_path)
return '({0} = ?) || ({0} LIKE ? ESCAPE ?)'.format(self.field), \
(file_blob, dir_pattern, self.escape_char)

View file

@ -20,7 +20,8 @@ that when getLogger(name) instantiates a logger that logger uses
{}-style formatting.
"""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
from copy import copy
from logging import * # noqa

View file

@ -32,7 +32,8 @@ Internally ``MediaFile`` uses ``MediaField`` descriptors to access the
data from the tags. In turn ``MediaField`` uses a number of
``StorageStyle`` strategies to handle format specific logic.
"""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import mutagen
import mutagen.mp3
@ -178,15 +179,15 @@ def _unpack_asf_image(data):
of exceptions (out-of-bounds, etc.). We should clean this up
sometime so that the failure modes are well-defined.
"""
type, size = struct.unpack_from("<bi", data)
type, size = struct.unpack_from(b'<bi', data)
pos = 5
mime = ""
while data[pos:pos + 2] != "\x00\x00":
while data[pos:pos + 2] != b'\x00\x00':
mime += data[pos:pos + 2]
pos += 2
pos += 2
description = ""
while data[pos:pos + 2] != "\x00\x00":
while data[pos:pos + 2] != b'\x00\x00':
description += data[pos:pos + 2]
pos += 2
pos += 2
@ -198,9 +199,9 @@ def _unpack_asf_image(data):
def _pack_asf_image(mime, data, type=3, description=""):
"""Pack image data for a WM/Picture tag.
"""
tag_data = struct.pack("<bi", type, len(data))
tag_data += mime.encode("utf-16-le") + "\x00\x00"
tag_data += description.encode("utf-16-le") + "\x00\x00"
tag_data = struct.pack(b'<bi', type, len(data))
tag_data += mime.encode("utf-16-le") + b'\x00\x00'
tag_data += description.encode("utf-16-le") + b'\x00\x00'
tag_data += data
return tag_data
@ -215,7 +216,7 @@ def _sc_decode(soundcheck):
# characters of ASCII hex preceded by a space.
try:
soundcheck = soundcheck.replace(' ', '').decode('hex')
soundcheck = struct.unpack('!iiiiiiiiii', soundcheck)
soundcheck = struct.unpack(b'!iiiiiiiiii', soundcheck)
except (struct.error, TypeError, UnicodeEncodeError):
# SoundCheck isn't in the format we expect, so return default
# values.
@ -562,7 +563,7 @@ class MP4StorageStyle(StorageStyle):
def serialize(self, value):
value = super(MP4StorageStyle, self).serialize(value)
if self.key.startswith('----:') and isinstance(value, unicode):
if self.key.startswith(b'----:') and isinstance(value, unicode):
value = value.encode('utf8')
return value
@ -637,7 +638,7 @@ class MP4ImageStorageStyle(MP4ListStorageStyle):
"""Store images as MPEG-4 image atoms. Values are `Image` objects.
"""
def __init__(self, **kwargs):
super(MP4ImageStorageStyle, self).__init__(key='covr', **kwargs)
super(MP4ImageStorageStyle, self).__init__(key=b'covr', **kwargs)
def deserialize(self, data):
return Image(data)
@ -992,7 +993,7 @@ class APEv2ImageStorageStyle(ListStorageStyle):
for cover_type, cover_tag in self.TAG_NAMES.items():
try:
frame = mutagen_file[cover_tag]
text_delimiter_index = frame.value.find('\x00')
text_delimiter_index = frame.value.find(b'\x00')
comment = frame.value[0:text_delimiter_index] \
if text_delimiter_index > 0 else None
image_data = frame.value[text_delimiter_index + 1:]
@ -1009,7 +1010,7 @@ class APEv2ImageStorageStyle(ListStorageStyle):
for image in values:
image_type = image.type or ImageType.other
comment = image.desc or ''
image_data = comment + "\x00" + image.data
image_data = comment.encode('utf8') + b'\x00' + image.data
cover_tag = self.TAG_NAMES[image_type]
mutagen_file[cover_tag] = image_data
@ -1474,25 +1475,25 @@ class MediaFile(object):
title = MediaField(
MP3StorageStyle('TIT2'),
MP4StorageStyle("\xa9nam"),
MP4StorageStyle(b"\xa9nam"),
StorageStyle('TITLE'),
ASFStorageStyle('Title'),
)
artist = MediaField(
MP3StorageStyle('TPE1'),
MP4StorageStyle("\xa9ART"),
MP4StorageStyle(b"\xa9ART"),
StorageStyle('ARTIST'),
ASFStorageStyle('Author'),
)
album = MediaField(
MP3StorageStyle('TALB'),
MP4StorageStyle("\xa9alb"),
MP4StorageStyle(b"\xa9alb"),
StorageStyle('ALBUM'),
ASFStorageStyle('WM/AlbumTitle'),
)
genres = ListMediaField(
MP3ListStorageStyle('TCON'),
MP4ListStorageStyle("\xa9gen"),
MP4ListStorageStyle(b"\xa9gen"),
ListStorageStyle('GENRE'),
ASFStorageStyle('WM/Genre'),
)
@ -1500,19 +1501,19 @@ class MediaFile(object):
composer = MediaField(
MP3StorageStyle('TCOM'),
MP4StorageStyle("\xa9wrt"),
MP4StorageStyle(b"\xa9wrt"),
StorageStyle('COMPOSER'),
ASFStorageStyle('WM/Composer'),
)
grouping = MediaField(
MP3StorageStyle('TIT1'),
MP4StorageStyle("\xa9grp"),
MP4StorageStyle(b"\xa9grp"),
StorageStyle('GROUPING'),
ASFStorageStyle('WM/ContentGroupDescription'),
)
track = MediaField(
MP3SlashPackStorageStyle('TRCK', pack_pos=0),
MP4TupleStorageStyle('trkn', index=0),
MP4TupleStorageStyle(b'trkn', index=0),
StorageStyle('TRACK'),
StorageStyle('TRACKNUMBER'),
ASFStorageStyle('WM/TrackNumber'),
@ -1520,7 +1521,7 @@ class MediaFile(object):
)
tracktotal = MediaField(
MP3SlashPackStorageStyle('TRCK', pack_pos=1),
MP4TupleStorageStyle('trkn', index=1),
MP4TupleStorageStyle(b'trkn', index=1),
StorageStyle('TRACKTOTAL'),
StorageStyle('TRACKC'),
StorageStyle('TOTALTRACKS'),
@ -1529,7 +1530,7 @@ class MediaFile(object):
)
disc = MediaField(
MP3SlashPackStorageStyle('TPOS', pack_pos=0),
MP4TupleStorageStyle('disk', index=0),
MP4TupleStorageStyle(b'disk', index=0),
StorageStyle('DISC'),
StorageStyle('DISCNUMBER'),
ASFStorageStyle('WM/PartOfSet'),
@ -1537,7 +1538,7 @@ class MediaFile(object):
)
disctotal = MediaField(
MP3SlashPackStorageStyle('TPOS', pack_pos=1),
MP4TupleStorageStyle('disk', index=1),
MP4TupleStorageStyle(b'disk', index=1),
StorageStyle('DISCTOTAL'),
StorageStyle('DISCC'),
StorageStyle('TOTALDISCS'),
@ -1546,13 +1547,13 @@ class MediaFile(object):
)
lyrics = MediaField(
MP3DescStorageStyle(key='USLT'),
MP4StorageStyle("\xa9lyr"),
MP4StorageStyle(b"\xa9lyr"),
StorageStyle('LYRICS'),
ASFStorageStyle('WM/Lyrics'),
)
comments = MediaField(
MP3DescStorageStyle(key='COMM'),
MP4StorageStyle("\xa9cmt"),
MP4StorageStyle(b"\xa9cmt"),
StorageStyle('DESCRIPTION'),
StorageStyle('COMMENT'),
ASFStorageStyle('WM/Comments'),
@ -1560,111 +1561,111 @@ class MediaFile(object):
)
bpm = MediaField(
MP3StorageStyle('TBPM'),
MP4StorageStyle('tmpo', as_type=int),
MP4StorageStyle(b'tmpo', as_type=int),
StorageStyle('BPM'),
ASFStorageStyle('WM/BeatsPerMinute'),
out_type=int,
)
comp = MediaField(
MP3StorageStyle('TCMP'),
MP4BoolStorageStyle('cpil'),
MP4BoolStorageStyle(b'cpil'),
StorageStyle('COMPILATION'),
ASFStorageStyle('WM/IsCompilation', as_type=bool),
out_type=bool,
)
albumartist = MediaField(
MP3StorageStyle('TPE2'),
MP4StorageStyle('aART'),
MP4StorageStyle(b'aART'),
StorageStyle('ALBUM ARTIST'),
StorageStyle('ALBUMARTIST'),
ASFStorageStyle('WM/AlbumArtist'),
)
albumtype = MediaField(
MP3DescStorageStyle(u'MusicBrainz Album Type'),
MP4StorageStyle('----:com.apple.iTunes:MusicBrainz Album Type'),
MP4StorageStyle(b'----:com.apple.iTunes:MusicBrainz Album Type'),
StorageStyle('MUSICBRAINZ_ALBUMTYPE'),
ASFStorageStyle('MusicBrainz/Album Type'),
)
label = MediaField(
MP3StorageStyle('TPUB'),
MP4StorageStyle('----:com.apple.iTunes:Label'),
MP4StorageStyle('----:com.apple.iTunes:publisher'),
MP4StorageStyle(b'----:com.apple.iTunes:Label'),
MP4StorageStyle(b'----:com.apple.iTunes:publisher'),
StorageStyle('LABEL'),
StorageStyle('PUBLISHER'), # Traktor
ASFStorageStyle('WM/Publisher'),
)
artist_sort = MediaField(
MP3StorageStyle('TSOP'),
MP4StorageStyle("soar"),
MP4StorageStyle(b"soar"),
StorageStyle('ARTISTSORT'),
ASFStorageStyle('WM/ArtistSortOrder'),
)
albumartist_sort = MediaField(
MP3DescStorageStyle(u'ALBUMARTISTSORT'),
MP4StorageStyle("soaa"),
MP4StorageStyle(b"soaa"),
StorageStyle('ALBUMARTISTSORT'),
ASFStorageStyle('WM/AlbumArtistSortOrder'),
)
asin = MediaField(
MP3DescStorageStyle(u'ASIN'),
MP4StorageStyle("----:com.apple.iTunes:ASIN"),
MP4StorageStyle(b"----:com.apple.iTunes:ASIN"),
StorageStyle('ASIN'),
ASFStorageStyle('MusicBrainz/ASIN'),
)
catalognum = MediaField(
MP3DescStorageStyle(u'CATALOGNUMBER'),
MP4StorageStyle("----:com.apple.iTunes:CATALOGNUMBER"),
MP4StorageStyle(b"----:com.apple.iTunes:CATALOGNUMBER"),
StorageStyle('CATALOGNUMBER'),
ASFStorageStyle('WM/CatalogNo'),
)
disctitle = MediaField(
MP3StorageStyle('TSST'),
MP4StorageStyle("----:com.apple.iTunes:DISCSUBTITLE"),
MP4StorageStyle(b"----:com.apple.iTunes:DISCSUBTITLE"),
StorageStyle('DISCSUBTITLE'),
ASFStorageStyle('WM/SetSubTitle'),
)
encoder = MediaField(
MP3StorageStyle('TENC'),
MP4StorageStyle("\xa9too"),
MP4StorageStyle(b"\xa9too"),
StorageStyle('ENCODEDBY'),
StorageStyle('ENCODER'),
ASFStorageStyle('WM/EncodedBy'),
)
script = MediaField(
MP3DescStorageStyle(u'Script'),
MP4StorageStyle("----:com.apple.iTunes:SCRIPT"),
MP4StorageStyle(b"----:com.apple.iTunes:SCRIPT"),
StorageStyle('SCRIPT'),
ASFStorageStyle('WM/Script'),
)
language = MediaField(
MP3StorageStyle('TLAN'),
MP4StorageStyle("----:com.apple.iTunes:LANGUAGE"),
MP4StorageStyle(b"----:com.apple.iTunes:LANGUAGE"),
StorageStyle('LANGUAGE'),
ASFStorageStyle('WM/Language'),
)
country = MediaField(
MP3DescStorageStyle('MusicBrainz Album Release Country'),
MP4StorageStyle("----:com.apple.iTunes:MusicBrainz "
"Album Release Country"),
MP4StorageStyle(b"----:com.apple.iTunes:MusicBrainz "
b"Album Release Country"),
StorageStyle('RELEASECOUNTRY'),
ASFStorageStyle('MusicBrainz/Album Release Country'),
)
albumstatus = MediaField(
MP3DescStorageStyle(u'MusicBrainz Album Status'),
MP4StorageStyle("----:com.apple.iTunes:MusicBrainz Album Status"),
MP4StorageStyle(b"----:com.apple.iTunes:MusicBrainz Album Status"),
StorageStyle('MUSICBRAINZ_ALBUMSTATUS'),
ASFStorageStyle('MusicBrainz/Album Status'),
)
media = MediaField(
MP3StorageStyle('TMED'),
MP4StorageStyle("----:com.apple.iTunes:MEDIA"),
MP4StorageStyle(b"----:com.apple.iTunes:MEDIA"),
StorageStyle('MEDIA'),
ASFStorageStyle('WM/Media'),
)
albumdisambig = MediaField(
# This tag mapping was invented for beets (not used by Picard, etc).
MP3DescStorageStyle(u'MusicBrainz Album Comment'),
MP4StorageStyle("----:com.apple.iTunes:MusicBrainz Album Comment"),
MP4StorageStyle(b"----:com.apple.iTunes:MusicBrainz Album Comment"),
StorageStyle('MUSICBRAINZ_ALBUMCOMMENT'),
ASFStorageStyle('MusicBrainz/Album Comment'),
)
@ -1672,7 +1673,7 @@ class MediaFile(object):
# Release date.
date = DateField(
MP3StorageStyle('TDRC'),
MP4StorageStyle("\xa9day"),
MP4StorageStyle(b"\xa9day"),
StorageStyle('DATE'),
ASFStorageStyle('WM/Year'),
year=(StorageStyle('YEAR'),))
@ -1684,7 +1685,7 @@ class MediaFile(object):
# *Original* release date.
original_date = DateField(
MP3StorageStyle('TDOR'),
MP4StorageStyle('----:com.apple.iTunes:ORIGINAL YEAR'),
MP4StorageStyle(b'----:com.apple.iTunes:ORIGINAL YEAR'),
StorageStyle('ORIGINALDATE'),
ASFStorageStyle('WM/OriginalReleaseYear'))
@ -1695,13 +1696,13 @@ class MediaFile(object):
# Nonstandard metadata.
artist_credit = MediaField(
MP3DescStorageStyle(u'Artist Credit'),
MP4StorageStyle("----:com.apple.iTunes:Artist Credit"),
MP4StorageStyle(b"----:com.apple.iTunes:Artist Credit"),
StorageStyle('ARTIST_CREDIT'),
ASFStorageStyle('beets/Artist Credit'),
)
albumartist_credit = MediaField(
MP3DescStorageStyle(u'Album Artist Credit'),
MP4StorageStyle("----:com.apple.iTunes:Album Artist Credit"),
MP4StorageStyle(b"----:com.apple.iTunes:Album Artist Credit"),
StorageStyle('ALBUMARTIST_CREDIT'),
ASFStorageStyle('beets/Album Artist Credit'),
)
@ -1715,31 +1716,31 @@ class MediaFile(object):
# MusicBrainz IDs.
mb_trackid = MediaField(
MP3UFIDStorageStyle(owner='http://musicbrainz.org'),
MP4StorageStyle('----:com.apple.iTunes:MusicBrainz Track Id'),
MP4StorageStyle(b'----:com.apple.iTunes:MusicBrainz Track Id'),
StorageStyle('MUSICBRAINZ_TRACKID'),
ASFStorageStyle('MusicBrainz/Track Id'),
)
mb_albumid = MediaField(
MP3DescStorageStyle(u'MusicBrainz Album Id'),
MP4StorageStyle('----:com.apple.iTunes:MusicBrainz Album Id'),
MP4StorageStyle(b'----:com.apple.iTunes:MusicBrainz Album Id'),
StorageStyle('MUSICBRAINZ_ALBUMID'),
ASFStorageStyle('MusicBrainz/Album Id'),
)
mb_artistid = MediaField(
MP3DescStorageStyle(u'MusicBrainz Artist Id'),
MP4StorageStyle('----:com.apple.iTunes:MusicBrainz Artist Id'),
MP4StorageStyle(b'----:com.apple.iTunes:MusicBrainz Artist Id'),
StorageStyle('MUSICBRAINZ_ARTISTID'),
ASFStorageStyle('MusicBrainz/Artist Id'),
)
mb_albumartistid = MediaField(
MP3DescStorageStyle(u'MusicBrainz Album Artist Id'),
MP4StorageStyle('----:com.apple.iTunes:MusicBrainz Album Artist Id'),
MP4StorageStyle(b'----:com.apple.iTunes:MusicBrainz Album Artist Id'),
StorageStyle('MUSICBRAINZ_ALBUMARTISTID'),
ASFStorageStyle('MusicBrainz/Album Artist Id'),
)
mb_releasegroupid = MediaField(
MP3DescStorageStyle(u'MusicBrainz Release Group Id'),
MP4StorageStyle('----:com.apple.iTunes:MusicBrainz Release Group Id'),
MP4StorageStyle(b'----:com.apple.iTunes:MusicBrainz Release Group Id'),
StorageStyle('MUSICBRAINZ_RELEASEGROUPID'),
ASFStorageStyle('MusicBrainz/Release Group Id'),
)
@ -1747,13 +1748,13 @@ class MediaFile(object):
# Acoustid fields.
acoustid_fingerprint = MediaField(
MP3DescStorageStyle(u'Acoustid Fingerprint'),
MP4StorageStyle('----:com.apple.iTunes:Acoustid Fingerprint'),
MP4StorageStyle(b'----:com.apple.iTunes:Acoustid Fingerprint'),
StorageStyle('ACOUSTID_FINGERPRINT'),
ASFStorageStyle('Acoustid/Fingerprint'),
)
acoustid_id = MediaField(
MP3DescStorageStyle(u'Acoustid Id'),
MP4StorageStyle('----:com.apple.iTunes:Acoustid Id'),
MP4StorageStyle(b'----:com.apple.iTunes:Acoustid Id'),
StorageStyle('ACOUSTID_ID'),
ASFStorageStyle('Acoustid/Id'),
)
@ -1774,11 +1775,11 @@ class MediaFile(object):
id3_lang='eng'
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_track_gain',
b'----:com.apple.iTunes:replaygain_track_gain',
float_places=2, suffix=b' dB'
),
MP4SoundCheckStorageStyle(
'----:com.apple.iTunes:iTunNORM',
b'----:com.apple.iTunes:iTunNORM',
index=0
),
StorageStyle(
@ -1801,7 +1802,7 @@ class MediaFile(object):
float_places=2, suffix=u' dB'
),
MP4SoundCheckStorageStyle(
'----:com.apple.iTunes:iTunNORM',
b'----:com.apple.iTunes:iTunNORM',
index=1
),
StorageStyle(
@ -1829,11 +1830,11 @@ class MediaFile(object):
id3_lang='eng'
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_track_peak',
b'----:com.apple.iTunes:replaygain_track_peak',
float_places=6
),
MP4SoundCheckStorageStyle(
'----:com.apple.iTunes:iTunNORM',
b'----:com.apple.iTunes:iTunNORM',
index=1
),
StorageStyle(u'REPLAYGAIN_TRACK_PEAK', float_places=6),
@ -1850,7 +1851,7 @@ class MediaFile(object):
float_places=6
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_album_peak',
b'----:com.apple.iTunes:replaygain_album_peak',
float_places=6
),
StorageStyle(u'REPLAYGAIN_ALBUM_PEAK', float_places=6),
@ -1860,7 +1861,7 @@ class MediaFile(object):
initial_key = MediaField(
MP3StorageStyle('TKEY'),
MP4StorageStyle('----:com.apple.iTunes:initialkey'),
MP4StorageStyle(b'----:com.apple.iTunes:initialkey'),
StorageStyle('INITIALKEY'),
ASFStorageStyle('INITIALKEY'),
)

View file

@ -14,7 +14,8 @@
"""Support for beets plugins."""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import traceback
import inspect

View file

@ -15,7 +15,8 @@
"""A simple utility for constructing filesystem-like trees from beets
libraries.
"""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
from collections import namedtuple
from beets import util

View file

@ -42,7 +42,7 @@ beetsplug.__path__ = [os.path.abspath(
)]
# Test resources path.
RSRC = os.path.join(os.path.dirname(__file__), 'rsrc')
RSRC = os.path.join(os.path.dirname(__file__), b'rsrc')
# Propagate to root loger so nosetest can capture it
log = logging.getLogger('beets')

View file

@ -12,7 +12,8 @@
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import re
import os.path

View file

@ -13,7 +13,8 @@
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
"""Tests for the general importer functionality.
"""

View file

@ -14,7 +14,8 @@
"""Tests for non-query database functions of Item.
"""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import os
import os.path
@ -58,7 +59,7 @@ class StoreTest(_common.LibTestCase):
self.i.store()
new_year = self.lib._connection().execute(
'select year from items where '
'title="the title"').fetchone()['year']
'title="the title"').fetchone()[b'year']
self.assertEqual(new_year, 1987)
def test_store_only_writes_dirty_fields(self):
@ -67,7 +68,7 @@ class StoreTest(_common.LibTestCase):
self.i.store()
new_genre = self.lib._connection().execute(
'select genre from items where '
'title="the title"').fetchone()['genre']
'title="the title"').fetchone()[b'genre']
self.assertEqual(new_genre, original_genre)
def test_store_clears_dirty_flags(self):
@ -86,7 +87,7 @@ class AddTest(_common.TestCase):
self.lib.add(self.i)
new_grouping = self.lib._connection().execute(
'select grouping from items '
'where composer="the composer"').fetchone()['grouping']
'where composer="the composer"').fetchone()[b'grouping']
self.assertEqual(new_grouping, self.i.grouping)
def test_library_add_path_inserts_row(self):
@ -96,7 +97,7 @@ class AddTest(_common.TestCase):
self.lib.add(i)
new_grouping = self.lib._connection().execute(
'select grouping from items '
'where composer="the composer"').fetchone()['grouping']
'where composer="the composer"').fetchone()[b'grouping']
self.assertEqual(new_grouping, self.i.grouping)
@ -441,7 +442,7 @@ class DestinationTest(_common.TestCase):
self.i.title = u'h\u0259d'
self.lib.path_formats = [('default', '$title')]
p = self.i.destination()
self.assertFalse('?' in p)
self.assertFalse(b'?' in p)
# We use UTF-8 to encode Windows paths now.
self.assertTrue(u'h\u0259d'.encode('utf8') in p)
finally:
@ -941,7 +942,7 @@ class PathStringTest(_common.TestCase):
self.assert_(isinstance(i.path, str))
def test_special_chars_preserved_in_database(self):
path = 'b\xe1r'
path = 'b\xe1r'.encode('utf8')
self.i.path = path
self.i.store()
i = list(self.lib.items())[0]
@ -949,7 +950,7 @@ class PathStringTest(_common.TestCase):
def test_special_char_path_added_to_database(self):
self.i.remove()
path = 'b\xe1r'
path = 'b\xe1r'.encode('utf8')
i = item()
i.path = path
self.lib.add(i)

View file

@ -1,5 +1,6 @@
"""Stupid tests that ensure logging works as expected"""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import logging as log
from StringIO import StringIO

View file

@ -15,7 +15,8 @@
"""Automatically-generated blanket testing for the MediaFile metadata
layer.
"""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import os
import shutil
@ -285,10 +286,10 @@ class GenreListTestMixin(object):
field_extension = MediaField(
MP3DescStorageStyle('customtag'),
MP4StorageStyle('----:com.apple.iTunes:customtag'),
StorageStyle('customtag'),
ASFStorageStyle('customtag'),
MP3DescStorageStyle(b'customtag'),
MP4StorageStyle(b'----:com.apple.iTunes:customtag'),
StorageStyle(b'customtag'),
ASFStorageStyle(b'customtag'),
)
@ -681,7 +682,7 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin,
# ReplayGain is float
tags[key] = 1.0
else:
tags[key] = 'value\u2010%s' % key
tags[key] = b'value\u2010%s' % key
for key in ['disc', 'disctotal', 'track', 'tracktotal', 'bpm']:
tags[key] = 1
@ -700,6 +701,7 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin,
tags['original_year'] = original_date.year
tags['original_month'] = original_date.month
tags['original_day'] = original_date.day
return tags

View file

@ -14,7 +14,8 @@
"""Specific, edge-case tests for the MediaFile metadata layer.
"""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import os
import shutil

View file

@ -12,7 +12,8 @@
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
from mock import patch
from test._common import unittest

View file

@ -13,7 +13,8 @@
# included in all copies or substantial portions of the Software.
"""Tests for the virtual filesystem builder.."""
from __future__ import division, absolute_import, print_function
from __future__ import (division, absolute_import, print_function,
unicode_literals)
from test import _common
from test._common import unittest