mirror of
https://github.com/beetbox/beets.git
synced 2026-01-05 07:23:33 +01:00
Flake8 fixes
This commit is contained in:
parent
ea04344560
commit
a6aed22ddd
4 changed files with 136 additions and 92 deletions
|
|
@ -9,4 +9,4 @@ ignore=E241,E221
|
|||
|
||||
# List of files that have not been cleand up yet. We will try to reduce
|
||||
# this with each commit
|
||||
exclude=test/test_config_command.py,test/test_files.py,test/test_art.py,test/test_dbcore.py,test/test_web.py,test/test_zero.py,test/rsrc/beetsplug/test.py,test/test_template.py,test/test_importfeeds.py,test/test_echonest.py,test/test_datequery.py,test/test_mb.py,test/test_convert.py,test/testall.py,test/test_player.py,test/test_query.py,test/test_mediafile.py,test/test_keyfinder.py,test/test_the.py,test/test_library.py,test/test_lyrics.py,test/test_ihate.py,test/test_vfs.py,test/test_replaygain.py,test/__init__.py,test/_common.py,test/test_mediafile_edge.py,test/test_ui.py,test/helper.py,test/test_autotag.py,test/test_pipeline.py
|
||||
exclude=test/test_config_command.py,test/test_files.py,test/test_art.py,test/test_dbcore.py,test/test_web.py,test/test_zero.py,test/rsrc/beetsplug/test.py,test/test_template.py,test/test_importfeeds.py,test/test_echonest.py,test/test_datequery.py,test/test_mb.py,test/test_convert.py,test/testall.py,test/test_player.py,test/test_query.py,test/test_mediafile.py,test/test_keyfinder.py,test/test_the.py,test/test_library.py,test/test_lyrics.py,test/test_ihate.py,test/test_vfs.py,test/test_replaygain.py,test/__init__.py,test/_common.py,test/test_mediafile_edge.py,test/test_ui.py
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ import os.path
|
|||
import shutil
|
||||
import subprocess
|
||||
from tempfile import mkdtemp, mkstemp
|
||||
from glob import glob
|
||||
from contextlib import contextmanager
|
||||
from StringIO import StringIO
|
||||
|
||||
|
|
@ -311,7 +310,7 @@ class TestImportSession(importer.ImportSession):
|
|||
if choice == importer.action.APPLY:
|
||||
return task.candidates[0]
|
||||
elif isinstance(choice, int):
|
||||
return task.candidates[choice-1]
|
||||
return task.candidates[choice - 1]
|
||||
else:
|
||||
return choice
|
||||
|
||||
|
|
@ -341,7 +340,7 @@ def generate_album_info(album_id, track_ids):
|
|||
return album
|
||||
|
||||
ALBUM_INFO_FIELDS = ['album', 'album_id', 'artist', 'artist_id',
|
||||
'asin', 'albumtype', 'va','label',
|
||||
'asin', 'albumtype', 'va', 'label',
|
||||
'artist_sort', 'releasegroup_id', 'catalognum',
|
||||
'language', 'country', 'albumstatus', 'media',
|
||||
'albumdisambig', 'artist_credit',
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ from beets.util import plurality
|
|||
from beets.autotag import AlbumInfo, TrackInfo
|
||||
from beets import config
|
||||
|
||||
|
||||
class PluralityTest(_common.TestCase):
|
||||
def test_plurality_consensus(self):
|
||||
objs = [1, 1, 1, 1]
|
||||
|
|
@ -91,12 +92,14 @@ class PluralityTest(_common.TestCase):
|
|||
for f in fields:
|
||||
self.assertEqual(likelies[f], '%s_1' % f)
|
||||
|
||||
|
||||
def _make_item(title, track, artist=u'some artist'):
|
||||
return Item(title=title, track=track,
|
||||
artist=artist, album=u'some album',
|
||||
length=1,
|
||||
mb_trackid='', mb_albumid='', mb_artistid='')
|
||||
|
||||
|
||||
def _make_trackinfo():
|
||||
return [
|
||||
TrackInfo(u'one', None, u'some artist', length=1, index=1),
|
||||
|
|
@ -104,12 +107,14 @@ def _make_trackinfo():
|
|||
TrackInfo(u'three', None, u'some artist', length=1, index=3),
|
||||
]
|
||||
|
||||
|
||||
def _clear_weights():
|
||||
"""Hack around the lazy descriptor used to cache weights for
|
||||
Distance calculations.
|
||||
"""
|
||||
Distance.__dict__['_weights'].computed = False
|
||||
|
||||
|
||||
class DistanceTest(_common.TestCase):
|
||||
def test_add(self):
|
||||
dist = Distance()
|
||||
|
|
@ -150,7 +155,7 @@ class DistanceTest(_common.TestCase):
|
|||
|
||||
dist.add_number('number', -1, 2)
|
||||
self.assertEqual(dist._penalties['number'], [0.0, 1.0, 1.0, 1.0,
|
||||
1.0, 1.0])
|
||||
1.0, 1.0])
|
||||
|
||||
def test_add_priority(self):
|
||||
dist = Distance()
|
||||
|
|
@ -161,12 +166,12 @@ class DistanceTest(_common.TestCase):
|
|||
self.assertEqual(dist._penalties['priority'], [0.0, 0.5])
|
||||
|
||||
dist.add_priority('priority', 'gh', ['ab', 'cd', 'ef',
|
||||
re.compile('GH', re.I)])
|
||||
re.compile('GH', re.I)])
|
||||
self.assertEqual(dist._penalties['priority'], [0.0, 0.5, 0.75])
|
||||
|
||||
dist.add_priority('priority', 'xyz', ['abc', 'def'])
|
||||
self.assertEqual(dist._penalties['priority'], [0.0, 0.5, 0.75,
|
||||
1.0])
|
||||
1.0])
|
||||
|
||||
def test_add_ratio(self):
|
||||
dist = Distance()
|
||||
|
|
@ -285,7 +290,8 @@ class DistanceTest(_common.TestCase):
|
|||
dist1.update(dist2)
|
||||
|
||||
self.assertEqual(dist1._penalties, {'album': [0.5, 0.75, 0.25],
|
||||
'media': [1.0, 0.05]})
|
||||
'media': [1.0, 0.05]})
|
||||
|
||||
|
||||
class TrackDistanceTest(_common.TestCase):
|
||||
def test_identical_tracks(self):
|
||||
|
|
@ -314,6 +320,7 @@ class TrackDistanceTest(_common.TestCase):
|
|||
dist = match.track_distance(item, info, incl_artist=True)
|
||||
self.assertEqual(dist, 0.0)
|
||||
|
||||
|
||||
class AlbumDistanceTest(_common.TestCase):
|
||||
def _mapping(self, items, info):
|
||||
out = {}
|
||||
|
|
@ -330,11 +337,12 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
items.append(_make_item(u'two', 2))
|
||||
items.append(_make_item(u'three', 3))
|
||||
info = AlbumInfo(
|
||||
artist = u'some artist',
|
||||
album = u'some album',
|
||||
tracks = _make_trackinfo(),
|
||||
va = False,
|
||||
album_id = None, artist_id = None,
|
||||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
)
|
||||
self.assertEqual(self._dist(items, info), 0)
|
||||
|
||||
|
|
@ -343,11 +351,12 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
items.append(_make_item(u'one', 1))
|
||||
items.append(_make_item(u'three', 3))
|
||||
info = AlbumInfo(
|
||||
artist = u'some artist',
|
||||
album = u'some album',
|
||||
tracks = _make_trackinfo(),
|
||||
va = False,
|
||||
album_id = None, artist_id = None,
|
||||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
)
|
||||
dist = self._dist(items, info)
|
||||
self.assertNotEqual(dist, 0)
|
||||
|
|
@ -360,11 +369,12 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
items.append(_make_item(u'two', 2))
|
||||
items.append(_make_item(u'three', 3))
|
||||
info = AlbumInfo(
|
||||
artist = u'someone else',
|
||||
album = u'some album',
|
||||
tracks = _make_trackinfo(),
|
||||
va = False,
|
||||
album_id = None, artist_id = None,
|
||||
artist=u'someone else',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
)
|
||||
self.assertNotEqual(self._dist(items, info), 0)
|
||||
|
||||
|
|
@ -374,11 +384,12 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
items.append(_make_item(u'two', 2))
|
||||
items.append(_make_item(u'three', 3))
|
||||
info = AlbumInfo(
|
||||
artist = u'should be ignored',
|
||||
album = u'some album',
|
||||
tracks = _make_trackinfo(),
|
||||
va = True,
|
||||
album_id = None, artist_id = None,
|
||||
artist=u'should be ignored',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=True,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
)
|
||||
self.assertEqual(self._dist(items, info), 0)
|
||||
|
||||
|
|
@ -389,11 +400,12 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
items.append(_make_item(u'two', 2))
|
||||
items.append(_make_item(u'three', 3))
|
||||
info = AlbumInfo(
|
||||
artist = u'should be ignored',
|
||||
album = u'some album',
|
||||
tracks = _make_trackinfo(),
|
||||
va = True,
|
||||
album_id = None, artist_id = None,
|
||||
artist=u'should be ignored',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=True,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
)
|
||||
info.tracks[0].artist = None
|
||||
info.tracks[1].artist = None
|
||||
|
|
@ -406,11 +418,12 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
items.append(_make_item(u'two', 2, u'someone else'))
|
||||
items.append(_make_item(u'three', 3))
|
||||
info = AlbumInfo(
|
||||
artist = u'some artist',
|
||||
album = u'some album',
|
||||
tracks = _make_trackinfo(),
|
||||
va = True,
|
||||
album_id = None, artist_id = None,
|
||||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=True,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
)
|
||||
self.assertNotEqual(self._dist(items, info), 0)
|
||||
|
||||
|
|
@ -420,11 +433,12 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
items.append(_make_item(u'three', 2))
|
||||
items.append(_make_item(u'two', 3))
|
||||
info = AlbumInfo(
|
||||
artist = u'some artist',
|
||||
album = u'some album',
|
||||
tracks = _make_trackinfo(),
|
||||
va = False,
|
||||
album_id = None, artist_id = None,
|
||||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
)
|
||||
dist = self._dist(items, info)
|
||||
self.assertTrue(0 < dist < 0.2)
|
||||
|
|
@ -435,11 +449,12 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
items.append(_make_item(u'two', 2))
|
||||
items.append(_make_item(u'three', 3))
|
||||
info = AlbumInfo(
|
||||
artist = u'some artist',
|
||||
album = u'some album',
|
||||
tracks = _make_trackinfo(),
|
||||
va = False,
|
||||
album_id = None, artist_id = None,
|
||||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
)
|
||||
info.tracks[0].medium_index = 1
|
||||
info.tracks[1].medium_index = 2
|
||||
|
|
@ -453,11 +468,12 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
items.append(_make_item(u'two', 2))
|
||||
items.append(_make_item(u'three', 1))
|
||||
info = AlbumInfo(
|
||||
artist = u'some artist',
|
||||
album = u'some album',
|
||||
tracks = _make_trackinfo(),
|
||||
va = False,
|
||||
album_id = None, artist_id = None,
|
||||
artist=u'some artist',
|
||||
album=u'some album',
|
||||
tracks=_make_trackinfo(),
|
||||
va=False,
|
||||
album_id=None,
|
||||
artist_id=None,
|
||||
)
|
||||
info.tracks[0].medium_index = 1
|
||||
info.tracks[1].medium_index = 2
|
||||
|
|
@ -465,8 +481,11 @@ class AlbumDistanceTest(_common.TestCase):
|
|||
dist = self._dist(items, info)
|
||||
self.assertEqual(dist, 0)
|
||||
|
||||
|
||||
def _mkmp3(path):
|
||||
shutil.copyfile(os.path.join(_common.RSRC, 'min.mp3'), path)
|
||||
|
||||
|
||||
class AlbumsInDirTest(_common.TestCase):
|
||||
def setUp(self):
|
||||
super(AlbumsInDirTest, self).setUp()
|
||||
|
|
@ -508,6 +527,7 @@ class AlbumsInDirTest(_common.TestCase):
|
|||
else:
|
||||
self.assertEqual(len(album), 1)
|
||||
|
||||
|
||||
class MultiDiscAlbumsInDirTest(_common.TestCase):
|
||||
def setUp(self):
|
||||
super(MultiDiscAlbumsInDirTest, self).setUp()
|
||||
|
|
@ -583,6 +603,7 @@ class MultiDiscAlbumsInDirTest(_common.TestCase):
|
|||
albums = list(autotag.albums_in_dir(self.base))
|
||||
self.assertEquals(len(albums), 0)
|
||||
|
||||
|
||||
class AssignmentTest(unittest.TestCase):
|
||||
def item(self, title, track):
|
||||
return Item(
|
||||
|
|
@ -698,7 +719,7 @@ class AssignmentTest(unittest.TestCase):
|
|||
trackinfo.append(info(6, u'Suzie Blue', 269.30599999999998))
|
||||
trackinfo.append(info(7, u'Steal My Kisses', 245.36000000000001))
|
||||
trackinfo.append(info(8, u'Burn to Shine', 214.90600000000001))
|
||||
trackinfo.append(info(9, u'Show Me a Little Shame', 224.09299999999999))
|
||||
trackinfo.append(info(9, u'Show Me a Little Shame', 224.0929999999999))
|
||||
trackinfo.append(info(10, u'Forgiven', 317.19999999999999))
|
||||
trackinfo.append(info(11, u'Beloved One', 243.733))
|
||||
trackinfo.append(info(12, u'In the Lord\'s Arms', 186.13300000000001))
|
||||
|
|
@ -710,6 +731,7 @@ class AssignmentTest(unittest.TestCase):
|
|||
for item, info in mapping.iteritems():
|
||||
self.assertEqual(items.index(item), trackinfo.index(info))
|
||||
|
||||
|
||||
class ApplyTestUtil(object):
|
||||
def _apply(self, info=None, per_disc_numbering=False):
|
||||
info = info or self.info
|
||||
|
|
@ -719,6 +741,7 @@ class ApplyTestUtil(object):
|
|||
config['per_disc_numbering'] = per_disc_numbering
|
||||
autotag.apply_metadata(info, mapping)
|
||||
|
||||
|
||||
class ApplyTest(_common.TestCase, ApplyTestUtil):
|
||||
def setUp(self):
|
||||
super(ApplyTest, self).setUp()
|
||||
|
|
@ -746,16 +769,16 @@ class ApplyTest(_common.TestCase, ApplyTestUtil):
|
|||
medium_total=1,
|
||||
))
|
||||
self.info = AlbumInfo(
|
||||
tracks = trackinfo,
|
||||
artist = u'artistNew',
|
||||
album = u'albumNew',
|
||||
album_id = '7edb51cb-77d6-4416-a23c-3a8c2994a2c7',
|
||||
artist_id = 'a6623d39-2d8e-4f70-8242-0a9553b91e50',
|
||||
artist_credit = u'albumArtistCredit',
|
||||
artist_sort = u'albumArtistSort',
|
||||
albumtype = u'album',
|
||||
va = False,
|
||||
mediums = 2,
|
||||
tracks=trackinfo,
|
||||
artist=u'artistNew',
|
||||
album=u'albumNew',
|
||||
album_id='7edb51cb-77d6-4416-a23c-3a8c2994a2c7',
|
||||
artist_id='a6623d39-2d8e-4f70-8242-0a9553b91e50',
|
||||
artist_credit=u'albumArtistCredit',
|
||||
artist_sort=u'albumArtistSort',
|
||||
albumtype=u'album',
|
||||
va=False,
|
||||
mediums=2,
|
||||
)
|
||||
|
||||
def test_titles_applied(self):
|
||||
|
|
@ -803,7 +826,7 @@ class ApplyTest(_common.TestCase, ApplyTestUtil):
|
|||
def test_mb_trackid_applied(self):
|
||||
self._apply()
|
||||
self.assertEqual(self.items[0].mb_trackid,
|
||||
'dfa939ec-118c-4d0f-84a0-60f3d1e6522c')
|
||||
'dfa939ec-118c-4d0f-84a0-60f3d1e6522c')
|
||||
self.assertEqual(self.items[1].mb_trackid,
|
||||
'40130ed1-a27c-42fd-a328-1ebefb6caef4')
|
||||
|
||||
|
|
@ -883,6 +906,7 @@ class ApplyTest(_common.TestCase, ApplyTestUtil):
|
|||
self.assertEqual(self.items[0].month, 2)
|
||||
self.assertEqual(self.items[0].day, 3)
|
||||
|
||||
|
||||
class ApplyCompilationTest(_common.TestCase, ApplyTestUtil):
|
||||
def setUp(self):
|
||||
super(ApplyCompilationTest, self).setUp()
|
||||
|
|
@ -906,13 +930,12 @@ class ApplyCompilationTest(_common.TestCase, ApplyTestUtil):
|
|||
index=2,
|
||||
))
|
||||
self.info = AlbumInfo(
|
||||
tracks = trackinfo,
|
||||
artist = u'variousNew',
|
||||
album = u'albumNew',
|
||||
album_id = '3b69ea40-39b8-487f-8818-04b6eff8c21a',
|
||||
artist_id = '89ad4ac3-39f7-470e-963a-56509c546377',
|
||||
albumtype = u'compilation',
|
||||
va = False,
|
||||
tracks=trackinfo,
|
||||
artist=u'variousNew',
|
||||
album=u'albumNew',
|
||||
album_id='3b69ea40-39b8-487f-8818-04b6eff8c21a',
|
||||
artist_id='89ad4ac3-39f7-470e-963a-56509c546377',
|
||||
albumtype=u'compilation',
|
||||
)
|
||||
|
||||
def test_album_and_track_artists_separate(self):
|
||||
|
|
@ -945,6 +968,7 @@ class ApplyCompilationTest(_common.TestCase, ApplyTestUtil):
|
|||
self.assertTrue(self.items[0].comp)
|
||||
self.assertTrue(self.items[1].comp)
|
||||
|
||||
|
||||
class StringDistanceTest(unittest.TestCase):
|
||||
def test_equal_strings(self):
|
||||
dist = string_dist(u'Some String', u'Some String')
|
||||
|
|
|
|||
|
|
@ -17,22 +17,31 @@
|
|||
from _common import unittest
|
||||
from beets.util import pipeline
|
||||
|
||||
|
||||
# Some simple pipeline stages for testing.
|
||||
def _produce(num=5):
|
||||
for i in range(num):
|
||||
yield i
|
||||
|
||||
|
||||
def _work():
|
||||
i = None
|
||||
while True:
|
||||
i = yield i
|
||||
i *= 2
|
||||
|
||||
|
||||
def _consume(l):
|
||||
while True:
|
||||
i = yield
|
||||
l.append(i)
|
||||
|
||||
|
||||
# A worker that raises an exception.
|
||||
class TestException(Exception): pass
|
||||
class TestException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def _exc_work(num=3):
|
||||
i = None
|
||||
while True:
|
||||
|
|
@ -41,6 +50,7 @@ def _exc_work(num=3):
|
|||
raise TestException()
|
||||
i *= 2
|
||||
|
||||
|
||||
# A worker that yields a bubble.
|
||||
def _bub_work(num=3):
|
||||
i = None
|
||||
|
|
@ -51,6 +61,7 @@ def _bub_work(num=3):
|
|||
else:
|
||||
i *= 2
|
||||
|
||||
|
||||
# Yet another worker that yields multiple messages.
|
||||
def _multi_work():
|
||||
i = None
|
||||
|
|
@ -58,6 +69,7 @@ def _multi_work():
|
|||
i = yield i
|
||||
i = pipeline.multiple([i, -i])
|
||||
|
||||
|
||||
class SimplePipelineTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.l = []
|
||||
|
|
@ -65,20 +77,21 @@ class SimplePipelineTest(unittest.TestCase):
|
|||
|
||||
def test_run_sequential(self):
|
||||
self.pl.run_sequential()
|
||||
self.assertEqual(self.l, [0,2,4,6,8])
|
||||
self.assertEqual(self.l, [0, 2, 4, 6, 8])
|
||||
|
||||
def test_run_parallel(self):
|
||||
self.pl.run_parallel()
|
||||
self.assertEqual(self.l, [0,2,4,6,8])
|
||||
self.assertEqual(self.l, [0, 2, 4, 6, 8])
|
||||
|
||||
def test_pull(self):
|
||||
pl = pipeline.Pipeline((_produce(), _work()))
|
||||
self.assertEqual(list(pl.pull()), [0,2,4,6,8])
|
||||
self.assertEqual(list(pl.pull()), [0, 2, 4, 6, 8])
|
||||
|
||||
def test_pull_chain(self):
|
||||
pl = pipeline.Pipeline((_produce(), _work()))
|
||||
pl2 = pipeline.Pipeline((pl.pull(), _work()))
|
||||
self.assertEqual(list(pl2.pull()), [0,4,8,12,16])
|
||||
self.assertEqual(list(pl2.pull()), [0, 4, 8, 12, 16])
|
||||
|
||||
|
||||
class ParallelStageTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
|
@ -89,21 +102,23 @@ class ParallelStageTest(unittest.TestCase):
|
|||
|
||||
def test_run_sequential(self):
|
||||
self.pl.run_sequential()
|
||||
self.assertEqual(self.l, [0,2,4,6,8])
|
||||
self.assertEqual(self.l, [0, 2, 4, 6, 8])
|
||||
|
||||
def test_run_parallel(self):
|
||||
self.pl.run_parallel()
|
||||
# Order possibly not preserved; use set equality.
|
||||
self.assertEqual(set(self.l), set([0,2,4,6,8]))
|
||||
self.assertEqual(set(self.l), set([0, 2, 4, 6, 8]))
|
||||
|
||||
def test_pull(self):
|
||||
pl = pipeline.Pipeline((_produce(), (_work(),_work())))
|
||||
self.assertEqual(list(pl.pull()), [0,2,4,6,8])
|
||||
pl = pipeline.Pipeline((_produce(), (_work(), _work())))
|
||||
self.assertEqual(list(pl.pull()), [0, 2, 4, 6, 8])
|
||||
|
||||
|
||||
class ExceptionTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.l = []
|
||||
self.pl = pipeline.Pipeline((_produce(), _exc_work(), _consume(self.l)))
|
||||
self.pl = pipeline.Pipeline((_produce(), _exc_work(),
|
||||
_consume(self.l)))
|
||||
|
||||
def test_run_sequential(self):
|
||||
self.assertRaises(TestException, self.pl.run_sequential)
|
||||
|
|
@ -114,9 +129,11 @@ class ExceptionTest(unittest.TestCase):
|
|||
def test_pull(self):
|
||||
pl = pipeline.Pipeline((_produce(), _exc_work()))
|
||||
pull = pl.pull()
|
||||
for i in range(3): pull.next()
|
||||
for i in range(3):
|
||||
pull.next()
|
||||
self.assertRaises(TestException, pull.next)
|
||||
|
||||
|
||||
class ParallelExceptionTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.l = []
|
||||
|
|
@ -127,6 +144,7 @@ class ParallelExceptionTest(unittest.TestCase):
|
|||
def test_run_parallel(self):
|
||||
self.assertRaises(TestException, self.pl.run_parallel)
|
||||
|
||||
|
||||
class ConstrainedThreadedPipelineTest(unittest.TestCase):
|
||||
def test_constrained(self):
|
||||
l = []
|
||||
|
|
@ -134,7 +152,7 @@ class ConstrainedThreadedPipelineTest(unittest.TestCase):
|
|||
pl = pipeline.Pipeline((_produce(1000), _work(), _consume(l)))
|
||||
# ... with only a single queue slot.
|
||||
pl.run_parallel(1)
|
||||
self.assertEqual(l, [i*2 for i in range(1000)])
|
||||
self.assertEqual(l, [i * 2 for i in range(1000)])
|
||||
|
||||
def test_constrained_exception(self):
|
||||
# Raise an exception in a constrained pipeline.
|
||||
|
|
@ -148,24 +166,27 @@ class ConstrainedThreadedPipelineTest(unittest.TestCase):
|
|||
_produce(1000), (_work(), _work()), _consume(l)
|
||||
))
|
||||
pl.run_parallel(1)
|
||||
self.assertEqual(set(l), set(i*2 for i in range(1000)))
|
||||
self.assertEqual(set(l), set(i * 2 for i in range(1000)))
|
||||
|
||||
|
||||
class BubbleTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.l = []
|
||||
self.pl = pipeline.Pipeline((_produce(), _bub_work(), _consume(self.l)))
|
||||
self.pl = pipeline.Pipeline((_produce(), _bub_work(),
|
||||
_consume(self.l)))
|
||||
|
||||
def test_run_sequential(self):
|
||||
self.pl.run_sequential()
|
||||
self.assertEqual(self.l, [0,2,4,8])
|
||||
self.assertEqual(self.l, [0, 2, 4, 8])
|
||||
|
||||
def test_run_parallel(self):
|
||||
self.pl.run_parallel()
|
||||
self.assertEqual(self.l, [0,2,4,8])
|
||||
self.assertEqual(self.l, [0, 2, 4, 8])
|
||||
|
||||
def test_pull(self):
|
||||
pl = pipeline.Pipeline((_produce(), _bub_work()))
|
||||
self.assertEqual(list(pl.pull()), [0,2,4,8])
|
||||
self.assertEqual(list(pl.pull()), [0, 2, 4, 8])
|
||||
|
||||
|
||||
class MultiMessageTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
|
@ -176,15 +197,15 @@ class MultiMessageTest(unittest.TestCase):
|
|||
|
||||
def test_run_sequential(self):
|
||||
self.pl.run_sequential()
|
||||
self.assertEqual(self.l, [0,0,1,-1,2,-2,3,-3,4,-4])
|
||||
self.assertEqual(self.l, [0, 0, 1, -1, 2, -2, 3, -3, 4, -4])
|
||||
|
||||
def test_run_parallel(self):
|
||||
self.pl.run_parallel()
|
||||
self.assertEqual(self.l, [0,0,1,-1,2,-2,3,-3,4,-4])
|
||||
self.assertEqual(self.l, [0, 0, 1, -1, 2, -2, 3, -3, 4, -4])
|
||||
|
||||
def test_pull(self):
|
||||
pl = pipeline.Pipeline((_produce(), _multi_work()))
|
||||
self.assertEqual(list(pl.pull()), [0,0,1,-1,2,-2,3,-3,4,-4])
|
||||
self.assertEqual(list(pl.pull()), [0, 0, 1, -1, 2, -2, 3, -3, 4, -4])
|
||||
|
||||
|
||||
def suite():
|
||||
|
|
|
|||
Loading…
Reference in a new issue