fix range upper bound + tests added

This commit is contained in:
Fabrice Laporte 2014-05-03 23:46:31 +02:00
parent 581bf768ca
commit 31569baba7
2 changed files with 10 additions and 6 deletions

View file

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

View file

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