Query tests: use normalized paths

Match ordinary beets behavior by storing normalized paths in the
database. This matters on Windows, where normalization adds backslashes
and drive letters.
This commit is contained in:
Adrian Sampson 2016-05-31 13:12:32 -07:00
parent 33a4767eaf
commit 1eb03a0de5
2 changed files with 12 additions and 2 deletions

View file

@ -52,6 +52,7 @@ from beets import importer
from beets.autotag.hooks import AlbumInfo, TrackInfo
from beets.mediafile import MediaFile, Image
from beets.ui import _arg_encoding
from beets import util
# TODO Move AutotagMock here
from test import _common
@ -306,11 +307,19 @@ class TestHelper(object):
If `path` is not set in `values` it is set to `item.destination()`.
"""
# When specifying a path, store it normalized (as beets does
# ordinarily).
if 'path' in values:
values['path'] = util.normpath(values['path'])
item = self.create_item(**values)
item.add(self.lib)
# Ensure every item has a path.
if 'path' not in values:
item['path'] = item.destination()
item.store()
return item
def add_item_fixture(self, **values):

View file

@ -31,6 +31,7 @@ from beets.dbcore import types
from beets.dbcore.query import (NoneQuery, ParsingError,
InvalidQueryArgumentTypeError)
from beets.library import Library, Item
from beets import util
class TestHelper(helper.TestHelper):
@ -372,7 +373,7 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin):
super(PathQueryTest, self).setUp()
# This is the item we'll try to match.
self.i.path = '/a/b/c.mp3'
self.i.path = util.normpath('/a/b/c.mp3')
self.i.title = u'path item'
self.i.album = u'path album'
self.i.store()
@ -380,7 +381,7 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin):
# A second item for testing exclusion.
i2 = _common.item()
i2.path = '/x/y/z.mp3'
i2.path = util.normpath('/x/y/z.mp3')
i2.title = 'another item'
i2.album = 'another album'
self.lib.add(i2)