diff --git a/test/_common.py b/test/_common.py index cc211be8c..c424bbfee 100644 --- a/test/_common.py +++ b/test/_common.py @@ -2,6 +2,44 @@ import time import sys +# Mangle the search path to include the beets sources. +sys.path.insert(0, '..') +import beets.library + +# Dummy item creation. +def item(): return beets.library.Item({ + 'title': u'the title', + 'artist': u'the artist', + 'albumartist': u'the album artist', + 'album': u'the album', + 'genre': u'the genre', + 'composer': u'the composer', + 'grouping': u'the grouping', + 'year': 1, + 'month': 2, + 'day': 3, + 'track': 4, + 'tracktotal': 5, + 'disc': 6, + 'disctotal': 7, + 'lyrics': u'the lyrics', + 'comments': u'the comments', + 'bpm': 8, + 'comp': True, + 'path': 'somepath', + 'length': 60.0, + 'bitrate': 128000, + 'format': 'FLAC', + 'mb_trackid': 'someID-1', + 'mb_albumid': 'someID-2', + 'mb_artistid': 'someID-3', + 'mb_albumartistid': 'someID-4', + 'album_id': None, +}) + + +# Mock timing. + class Timecop(object): """Mocks the timing system (namely time() and sleep()) for testing. Inspired by the Ruby timecop library. @@ -27,6 +65,9 @@ class Timecop(object): time.time = self.orig['time'] time.sleep = self.orig['sleep'] + +# Mock I/O. + class InputException(Exception): def __init__(self, output=None): self.output = output diff --git a/test/test_art.py b/test/test_art.py index 369c5e839..f9c13fffd 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -15,9 +15,8 @@ """Tests for the album art fetchers.""" import unittest -import sys -sys.path.insert(0, '..') +import _common from beets.autotag import art class MockHeaders(object): diff --git a/test/test_autotag.py b/test/test_autotag.py index 81beb3260..ac17abfd8 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -20,7 +20,8 @@ import sys import os import shutil import re -sys.path.insert(0, '..') + +import _common from beets import autotag from beets.library import Item diff --git a/test/test_db.py b/test/test_db.py index cb7643add..f9be61b24 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -16,46 +16,18 @@ """ import unittest -import sys import os import sqlite3 import ntpath import posixpath -sys.path.insert(0, '..') + +import _common +from _common import item import beets.library def lib(): return beets.library.Library('rsrc' + os.sep + 'test.blb') def boracay(l): return beets.library.Item(l.conn.execute('select * from items ' 'where id=3').fetchone()) -def item(): return beets.library.Item({ - 'title': u'the title', - 'artist': u'the artist', - 'albumartist': u'the album artist', - 'album': u'the album', - 'genre': u'the genre', - 'composer': u'the composer', - 'grouping': u'the grouping', - 'year': 1, - 'month': 2, - 'day': 3, - 'track': 4, - 'tracktotal': 5, - 'disc': 6, - 'disctotal': 7, - 'lyrics': u'the lyrics', - 'comments': u'the comments', - 'bpm': 8, - 'comp': True, - 'path': 'somepath', - 'length': 60.0, - 'bitrate': 128000, - 'format': 'FLAC', - 'mb_trackid': 'someID-1', - 'mb_albumid': 'someID-2', - 'mb_artistid': 'someID-3', - 'mb_albumartistid': 'someID-4', - 'album_id': None, -}) np = beets.library._normpath class LoadTest(unittest.TestCase): diff --git a/test/test_files.py b/test/test_files.py index 1742214e9..a58235f27 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -17,13 +17,13 @@ import unittest import shutil -import sys import os import stat from os.path import join -sys.path.insert(0, '..') + +import _common +from _common import item import beets.library -from test_db import item def touch(path): open(path, 'a').close() diff --git a/test/test_mb.py b/test/test_mb.py index 20745b3cb..a1684f368 100644 --- a/test/test_mb.py +++ b/test/test_mb.py @@ -16,12 +16,11 @@ """ import unittest -import sys import time import musicbrainz2.model import musicbrainz2.webservice as mbws + import _common -sys.path.insert(0, '..') from beets.autotag import mb def nullfun(): pass diff --git a/test/test_mediafile.py b/test/test_mediafile.py index a905ab989..c6bfa3006 100644 --- a/test/test_mediafile.py +++ b/test/test_mediafile.py @@ -15,8 +15,10 @@ """Specific, edge-case tests for the MediaFile metadata layer. """ -import unittest, sys, os, shutil, datetime -sys.path.insert(0, '..') +import unittest +import os + +import _common import beets.mediafile class EdgeTest(unittest.TestCase): diff --git a/test/test_mediafile_basic.py b/test/test_mediafile_basic.py index 24948f1a2..a217f13d1 100644 --- a/test/test_mediafile_basic.py +++ b/test/test_mediafile_basic.py @@ -16,8 +16,12 @@ layer. """ -import unittest, sys, os, shutil, datetime -sys.path.insert(0, '..') +import unittest +import os +import shutil +import datetime + +import _common import beets.mediafile diff --git a/test/test_player.py b/test/test_player.py index 4586aa804..b7fda4383 100644 --- a/test/test_player.py +++ b/test/test_player.py @@ -16,8 +16,8 @@ """ import unittest -import sys -sys.path.insert(0, '..') + +import _common from beetsplug import bpd class FauxPathTest(unittest.TestCase): diff --git a/test/test_query.py b/test/test_query.py index 4fa5b4eee..46f8a440b 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -15,14 +15,15 @@ """Various tests for querying the library database. """ -import unittest, sys, os -sys.path.insert(0, '..') +import unittest +import os + +import _common import beets.library -import test_db parse_query = beets.library.CollectionQuery._parse_query -some_item = test_db.item() +some_item = _common.item() class QueryParseTest(unittest.TestCase): def test_one_basic_term(self): diff --git a/test/test_ui.py b/test/test_ui.py index 7af95d758..1af54f8e9 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -16,20 +16,18 @@ """ import unittest -import sys import os import shutil import textwrap from StringIO import StringIO import logging + import _common -sys.path.insert(0, '..') from beets import library from beets import ui from beets.ui import commands from beets import autotag from beets import mediafile -import test_db TEST_TITLES = ('The Opener','The Second Track','The Last Track') class ImportTest(unittest.TestCase): @@ -126,7 +124,7 @@ class ListTest(unittest.TestCase): self.io.install() self.lib = library.Library(':memory:') - i = test_db.item() + i = _common.item() self.lib.add(i) self.lib.add_album([i]) @@ -210,7 +208,7 @@ class AutotagTest(unittest.TestCase): def _no_candidates_test(self, result): res = commands.choose_match( 'path', - [test_db.item()], # items + [_common.item()], # items 'artist', 'album', [], # candidates