move some reused testing stuff to _common module

This commit is contained in:
Adrian Sampson 2011-03-23 16:15:18 -07:00
parent b5c38970cc
commit 43a5e913a7
11 changed files with 71 additions and 54 deletions

View file

@ -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

View file

@ -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):

View file

@ -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

View file

@ -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):

View file

@ -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()

View file

@ -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

View file

@ -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):

View file

@ -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

View file

@ -16,8 +16,8 @@
"""
import unittest
import sys
sys.path.insert(0, '..')
import _common
from beetsplug import bpd
class FauxPathTest(unittest.TestCase):

View file

@ -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):

View file

@ -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