From 1eb03a0de502de20c4a25beb4634fbf368d57151 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 31 May 2016 13:12:32 -0700 Subject: [PATCH] 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. --- test/helper.py | 9 +++++++++ test/test_query.py | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/helper.py b/test/helper.py index 0f708b640..c10d8fad2 100644 --- a/test/helper.py +++ b/test/helper.py @@ -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): diff --git a/test/test_query.py b/test/test_query.py index 7a076a0ee..b9c87ff87 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -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)