Example #1
0
    def test_order_works_when_track_names_are_entirely_wrong(self):
        # A real-world test case contributed by a user.
        def item(i, length):
            return Item({
                'artist': u'ben harper',
                'album': u'burn to shine',
                'title': u'ben harper - Burn to Shine ' + str(i),
                'track': i,
                'length': length,
                'mb_trackid': '',
                'mb_albumid': '',
                'mb_artistid': '',
            })

        items = []
        items.append(item(1, 241.37243007106997))
        items.append(item(2, 342.27781704375036))
        items.append(item(3, 245.95070222338137))
        items.append(item(4, 472.87662515485437))
        items.append(item(5, 279.1759535763187))
        items.append(item(6, 270.33333768012))
        items.append(item(7, 247.83435613222923))
        items.append(item(8, 216.54504531525072))
        items.append(item(9, 225.72775379800484))
        items.append(item(10, 317.7643606963552))
        items.append(item(11, 243.57001238834192))
        items.append(item(12, 186.45916150485752))

        def info(index, title, length):
            return TrackInfo(title, None, length=length, index=index)

        trackinfo = []
        trackinfo.append(info(1, u'Alone', 238.893))
        trackinfo.append(info(2, u'The Woman in You', 341.44))
        trackinfo.append(info(3, u'Less', 245.59999999999999))
        trackinfo.append(info(4, u'Two Hands of a Prayer', 470.49299999999999))
        trackinfo.append(info(5, u'Please Bleed', 277.86599999999999))
        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(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))

        mapping, extra_items, extra_tracks = \
            match.assign_items(items, trackinfo)
        self.assertEqual(extra_items, set())
        self.assertEqual(extra_tracks, set())
        for item, info in mapping.iteritems():
            self.assertEqual(items.index(item), trackinfo.index(info))
Example #2
0
 def test_order_works_with_extra_tracks(self):
     items = []
     items.append(self.item(u'one', 1))
     items.append(self.item(u'two', 2))
     items.append(self.item(u'three', 3))
     trackinfo = []
     trackinfo.append(TrackInfo(u'one', None))
     trackinfo.append(TrackInfo(u'three', None))
     mapping, extra_items, extra_tracks = \
         match.assign_items(items, trackinfo)
     self.assertEqual(extra_items, [items[1]])
     self.assertEqual(extra_tracks, [])
     self.assertEqual(mapping, {
         items[0]: trackinfo[0],
         items[2]: trackinfo[1],
     })
Example #3
0
 def test_order_works_with_missing_tracks(self):
     items = []
     items.append(self.item('one', 1))
     items.append(self.item('three', 3))
     trackinfo = []
     trackinfo.append(TrackInfo(title='one'))
     trackinfo.append(TrackInfo(title='two'))
     trackinfo.append(TrackInfo(title='three'))
     mapping, extra_items, extra_tracks = \
         match.assign_items(items, trackinfo)
     self.assertEqual(extra_items, [])
     self.assertEqual(extra_tracks, [trackinfo[1]])
     self.assertEqual(mapping, {
         items[0]: trackinfo[0],
         items[1]: trackinfo[2],
     })
Example #4
0
    def test_order_works_when_track_names_are_entirely_wrong(self):
        # A real-world test case contributed by a user.
        def item(i, length):
            return Item(
                artist=u'ben harper',
                album=u'burn to shine',
                title=u'ben harper - Burn to Shine {0}'.format(i),
                track=i,
                length=length,
                mb_trackid='', mb_albumid='', mb_artistid='',
            )
        items = []
        items.append(item(1, 241.37243007106997))
        items.append(item(2, 342.27781704375036))
        items.append(item(3, 245.95070222338137))
        items.append(item(4, 472.87662515485437))
        items.append(item(5, 279.1759535763187))
        items.append(item(6, 270.33333768012))
        items.append(item(7, 247.83435613222923))
        items.append(item(8, 216.54504531525072))
        items.append(item(9, 225.72775379800484))
        items.append(item(10, 317.7643606963552))
        items.append(item(11, 243.57001238834192))
        items.append(item(12, 186.45916150485752))

        def info(index, title, length):
            return TrackInfo(title, None, length=length, index=index)
        trackinfo = []
        trackinfo.append(info(1, u'Alone', 238.893))
        trackinfo.append(info(2, u'The Woman in You', 341.44))
        trackinfo.append(info(3, u'Less', 245.59999999999999))
        trackinfo.append(info(4, u'Two Hands of a Prayer', 470.49299999999999))
        trackinfo.append(info(5, u'Please Bleed', 277.86599999999999))
        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.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))

        mapping, extra_items, extra_tracks = \
            match.assign_items(items, trackinfo)
        self.assertEqual(extra_items, [])
        self.assertEqual(extra_tracks, [])
        for item, info in mapping.items():
            self.assertEqual(items.index(item), trackinfo.index(info))
Example #5
0
 def test_reorder_when_track_numbers_incorrect(self):
     items = []
     items.append(self.item(u'one', 1))
     items.append(self.item(u'three', 2))
     items.append(self.item(u'two', 3))
     trackinfo = []
     trackinfo.append(TrackInfo(u'one', None))
     trackinfo.append(TrackInfo(u'two', None))
     trackinfo.append(TrackInfo(u'three', None))
     mapping, extra_items, extra_tracks = \
         match.assign_items(items, trackinfo)
     self.assertEqual(extra_items, [])
     self.assertEqual(extra_tracks, [])
     self.assertEqual(mapping, {
         items[0]: trackinfo[0],
         items[1]: trackinfo[2],
         items[2]: trackinfo[1],
     })
Example #6
0
 def test_order_works_with_invalid_track_numbers(self):
     items = []
     items.append(self.item(u'one', 1))
     items.append(self.item(u'three', 1))
     items.append(self.item(u'two', 1))
     trackinfo = []
     trackinfo.append(TrackInfo(title=u'one'))
     trackinfo.append(TrackInfo(title=u'two'))
     trackinfo.append(TrackInfo(title=u'three'))
     mapping, extra_items, extra_tracks = \
         match.assign_items(items, trackinfo)
     self.assertEqual(extra_items, [])
     self.assertEqual(extra_tracks, [])
     self.assertEqual(
         mapping, {
             items[0]: trackinfo[0],
             items[1]: trackinfo[2],
             items[2]: trackinfo[1],
         })