From 45870e6639acb333f9e90ebfded743b9d70f1633 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 5 Aug 2010 16:34:18 -0700 Subject: [PATCH] fix failure mode of order_items for length mismatch --- beets/autotag/__init__.py | 4 ++++ test/test_autotag.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index a7682dab1..2e72e05ca 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -203,6 +203,10 @@ def order_items(items, trackinfo): information. This always produces a result if the numbers of tracks match. """ + # Make sure lengths match. + if len(items) != len(trackinfo): + return None + # Construct the cost matrix. costs = [] for cur_item in items: diff --git a/test/test_autotag.py b/test/test_autotag.py index e7463c700..856f22b1b 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -111,6 +111,15 @@ class OrderingTest(unittest.TestCase): self.assertEqual(ordered[1].title, 'two') self.assertEqual(ordered[2].title, 'three') + def test_order_returns_none_for_length_mismatch(self): + items = [] + items.append(self.item('one', 1)) + items.append(self.item('two', 2)) + trackinfo = [] + trackinfo.append({'title': 'one', 'track': 1}) + ordered = autotag.order_items(items, trackinfo) + self.assertEqual(ordered, None) + class ApplyTest(unittest.TestCase): def setUp(self): self.items = []