From 31569baba79fece6cc0e67f3b0f65c744198fb9c Mon Sep 17 00:00:00 2001 From: Fabrice Laporte Date: Sat, 3 May 2014 23:46:31 +0200 Subject: [PATCH] fix range upper bound + tests added --- beetsplug/bucket.py | 6 ++---- test/test_bucket.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/beetsplug/bucket.py b/beetsplug/bucket.py index 1b8eec4d7..a814f86c2 100644 --- a/beetsplug/bucket.py +++ b/beetsplug/bucket.py @@ -64,7 +64,6 @@ class BucketPlugin(plugins.BeetsPlugin): self.yearranges = [self.make_year_range(b) for b in yearranges] self.alpharanges = [self.make_alpha_range(b) for b in self.config['bucket_alpha'].get()] - log.debug(self.alpharanges) def make_year_range(self, ys): """Express year-span as a list of years [from...to]. @@ -76,8 +75,8 @@ class BucketPlugin(plugins.BeetsPlugin): try: ys.append(self.yearbounds[lb_idx + 1]) except: - ys.append(datetime.now().year + 1) - return range(ys[0], ys[1]) + ys.append(datetime.now().year) + return range(ys[0], ys[-1] + 1) def make_alpha_range(self, s): """Express chars range as a list of chars [from...to] @@ -111,5 +110,4 @@ class BucketPlugin(plugins.BeetsPlugin): func = self.find_bucket_timerange else: func = self.find_bucket_alpha - return func(text) diff --git a/test/test_bucket.py b/test/test_bucket.py index 1a45bc2c2..3b16420f4 100644 --- a/test/test_bucket.py +++ b/test/test_bucket.py @@ -45,11 +45,17 @@ class BucketPluginTest(unittest.TestCase, TestHelper): def test_year_single_year_last_folder(self): """Last folder of a range extends from its year to current year.""" self._setup_config(bucket_year=['50', '70']) - self.assertEqual(self.plugin._tmpl_bucket('1999'), '70') + self.assertEqual(self.plugin._tmpl_bucket('2014'), '70') + self.assertEqual(self.plugin._tmpl_bucket('2015'), '2015') def test_year_two_years(self): self._setup_config(bucket_year=['50-59', '1960-69']) - self.assertEqual(self.plugin._tmpl_bucket('1954'), '50-59') + self.assertEqual(self.plugin._tmpl_bucket('1959'), '50-59') + + def test_year_multiple_years(self): + self._setup_config(bucket_year=['1950,51,52,53']) + self.assertEqual(self.plugin._tmpl_bucket('1953'), '1950,51,52,53') + self.assertEqual(self.plugin._tmpl_bucket('1974'), '1974') def test_year_out_of_range(self): """If no range match, return the year"""